This project is a result of practice to understand main Solana concepts like
owner
, authority
, Program Derived Addresses (PDA)
, signers
, PDA signers
, cross-program invocation (CPI)
, Associated token account (ATA)
. It contains a prototype of on-chain automated assignment checker system (AACS)
that mints preconfigured number of course batch tokens when a student successfuly solves some assignment and sends correct result.
Solana is chosen because it allows to build energy efficient and concurrent on-chain programs. Due to efficiency transaction cost and confirmation time is much lower than in other public blockchains. Both on-chain and client side of the programs can benefit from usage of Rust and its ecosystem.
The prototype uses Anchor framework to organize accounts and their validation. Trdelnik is used to generate a test client and write a command line test that spins up local validator, deploys programs, initializes test fixture with configured accounts, creates them using the program instructions and runs the logic that tests behaviour of the AACS
prototype.
-
Course authority
- organizesCourses
and their content. PromotesCourses
toStudents
and runsCourse batches
. Prepares assignments forStudents
. Anybody can be aCourse authority
and organize ownCourses
. -
Student
- enrolls intoCourse batch
, solves assignments and sends hashed solutions to getCourse batch tokens
. Fully implemented MVP of AACS could exchange these batch specific tokens into other assets (like certifications or hiring rating). This functionality is outside of the prototype scope. -
CourseManager
program derives and ownsCourse
account. This account keepsCourse authority
pubkey for validation purposes. The account address (which is PDA) is used as a namespace to derive addresses of other accounts likeCourse batch
,Course batch Mint
,Assignment checker
. -
CourseBatchManager
program-
derives and owns
Course batch
andCourse batch Mint
accounts for each batch created by theCourse Authority
.Course batch
account is the mint authority ofCourse batch Mint
account. Both accounts have PDAs. OnlyCourseBatchManager
could sign for them. -
Students
can enroll in the batch and get theirStudent course batch ATA
with zero balance ofCourse batch tokens
. -
Course authority
can createAssignmentCheckerState
accounts for eachCourse
assignment, provide ground truth solution hashes and configure number of tokens that will be minted and tranfered toStudent course batch ATA
when correct solution is provided by aStudent
-
Students
can start solving assignments and createCheckResult
accounts for them.CheckResult
answers on two questions:- whether the assignment check has ever passed
- whether the check has passed for the first time
On finding a potential assignment solution
Student
initiatesCheckAssignment
operation. If it's succededStudent
receives the tokens awarded for the submission of the correct solution hash. Tokens are awarded for eachStudent
only once perCourse
and assignment.
-
-
AssignmentChecker
program is an owner ofAssignmentCheckerState
andCheckResult
accounts. It checks whether provided solution hash with the givenexpected_hash_chain_length
correctly hashes into storedground_truth_hash_chain_tail
. On successful check it cuts the tail of the hash chain and removes an opportunity to try the same solution hash by another student acting like a sequence of one-time passwords.AssignmentChecker
stores the status of the check inCheckResult
account.AssignmentCheckerState
andCheckResult
accounts are PDAs derived from parameterizedresult_processor_program
and required to be transaction signers- only the
result_processor_program
can create these accounts and run assignment solution check CourseBatchManager
program creates these accounts forAssignmentChecker
and sets it be the accounts owner. It initializes them by doingCPI
calls toAssignmentChecker
- the only program that can mutate them.CourseBatchManager
program plays the role ofresult_processor_program
duringcheck_assignment
operations. It doesCPI
call toAssignmentChecker
to do the actual check and analyzes the state ofCheckResult
account- another program cannot pass
AssignmentCheckerState
andCheckResult
accounts derived fromCourseBatchManager
because it cannot sign for these PDAs.
- only the
AssignmentChecker
returns custom program errors when a hash chain has run out of capacity orcheck_assignment
is called with incorrectexpected_hash_chain_length
. The later error could happen during concurrent checks made by several students. Client is expected to retry the call with updatedexpected_hash_chain_length
value.
-
Install Rust + Cargo, Solana, Anchor and Trdelnik.
-
Build shared objects for on-chain programs, generate their Anchor IDL and Trdelink test
.program_client
moduletrdelnik build
-
Build and run test that will setup and test the entire
check_assignment
flow.trdelnik test
-
Optionally during test execution you can monitor program logs from the local test validator
solana logs -u localhost
When tokens are minted the following line is logged:
Program log: minted 100 tokens to Too1UPuAw5enEA4PkdZUDnPfye9TsqH5bsqAWmYCas7