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- organizesCoursesand their content. PromotesCoursestoStudentsand runsCourse batches. Prepares assignments forStudents. Anybody can be aCourse authorityand 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. -
CourseManagerprogram derives and ownsCourseaccount. This account keepsCourse authoritypubkey 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. -
CourseBatchManagerprogram-
derives and owns
Course batchandCourse batch Mintaccounts for each batch created by theCourse Authority.Course batchaccount is the mint authority ofCourse batch Mintaccount. Both accounts have PDAs. OnlyCourseBatchManagercould sign for them. -
Studentscan enroll in the batch and get theirStudent course batch ATAwith zero balance ofCourse batch tokens. -
Course authoritycan createAssignmentCheckerStateaccounts for eachCourseassignment, provide ground truth solution hashes and configure number of tokens that will be minted and tranfered toStudent course batch ATAwhen correct solution is provided by aStudent -
Studentscan start solving assignments and createCheckResultaccounts for them.CheckResultanswers 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
StudentinitiatesCheckAssignmentoperation. If it's succededStudentreceives the tokens awarded for the submission of the correct solution hash. Tokens are awarded for eachStudentonly once perCourseand assignment.
-
-
AssignmentCheckerprogram is an owner ofAssignmentCheckerStateandCheckResultaccounts. It checks whether provided solution hash with the givenexpected_hash_chain_lengthcorrectly 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.AssignmentCheckerstores the status of the check inCheckResultaccount.AssignmentCheckerStateandCheckResultaccounts are PDAs derived from parameterizedresult_processor_programand required to be transaction signers- only the
result_processor_programcan create these accounts and run assignment solution check CourseBatchManagerprogram creates these accounts forAssignmentCheckerand sets it be the accounts owner. It initializes them by doingCPIcalls toAssignmentChecker- the only program that can mutate them.CourseBatchManagerprogram plays the role ofresult_processor_programduringcheck_assignmentoperations. It doesCPIcall toAssignmentCheckerto do the actual check and analyzes the state ofCheckResultaccount- another program cannot pass
AssignmentCheckerStateandCheckResultaccounts derived fromCourseBatchManagerbecause it cannot sign for these PDAs.
- only the
AssignmentCheckerreturns custom program errors when a hash chain has run out of capacity orcheck_assignmentis 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_lengthvalue.
-
Install Rust + Cargo, Solana, Anchor and Trdelnik.
-
Build shared objects for on-chain programs, generate their Anchor IDL and Trdelink test
.program_clientmoduletrdelnik build -
Build and run test that will setup and test the entire
check_assignmentflow.trdelnik test -
Optionally during test execution you can monitor program logs from the local test validator
solana logs -u localhostWhen tokens are minted the following line is logged:
Program log: minted 100 tokens to Too1UPuAw5enEA4PkdZUDnPfye9TsqH5bsqAWmYCas7