Juvix - Anoma: Generate TX Candidate

Goal: Describe the user’s steps to submit a transaction candidate to Anoma using the Cairo backend.

(These are notes taken from Juvix ↔ Anoma session at HHH on 13-Sep-24 with @xuyang @camofu and led by @Lukasz ).

This process represents the first transition of the Anoma Node Transaction Code Lifecycle:

  1. Compile Juvix to Cairo bytecode.
  2. Generate the proofs for the resource logics using the Anoma API (e.g. CLI) in a local environment.
    • Inputs:
      • Resource logic Cairo bytecode (from step 1)
      • Resource logic inputs in a .json file
    • Outputs:
      • Program proof binary
  3. Generate compliance proof
    • Inputs:
      • compliance.json file, where the “logic” field points to the path to the proof binary field. The Juvix API computes the hash of the file under the hood. This reduces the cognitive burden from the user.
  4. Submit transaction to Anoma
    • Create partial transaction(s)
      • Inputs:
        • Some number of resource proof binaries (generated by step 2)
        • Some number of compliance proof binaries (generated by step 3)
    • Create final transaction
      • Inputs:
        • Partial transactions
        • Delta: List of “rcv” fields in the compliance_input.json files corresponding to the provided compliance proofs
    • Encode into Nock Transaction Candidate
1 Like

I wonder if step 3, Generate compliance proof, can be hidden from the user using the Anoma API.

The user would still need to provide the necessary inputs such as quantity, but I would not expose the user to the compliance proof.

1 Like

Yes, I think step 3 can be merged into step 4. The user would provide compliance_input.json files for each compliance proof, and then the system would create compliance proof binaries and extract the “rvc” fields without user intervention.

1 Like

Here are photos of the blackboard.


Question: do resource proof binaries in step 3 always correspond to the resource logics in the compliance_input.json files, and should always just be submitted in the order in which they occur in the json files?

For example, we have two compliance files:

compliance1.json:
{
"input": {
   "logic": <hash of logic1A_proof>
  ...
},
"output": {
   "logic": <hash of logic1B_proof>
  ...
}
}

compliance2.json:
{
"input": {
   "logic": <hash of logic2A_proof>
  ...
},
"output": {
   "logic": <hash of logic2B_proof>
  ...
}
}

Would the partial transaction then always be:

logic_proofs = [logic1A_proof, logic1B_proof, logic2A_proof, logic2B_proof]
compliance_proofs = [compliance1_proof, compliance2_proof]

In other words, is the partial transaction always uniquely determined from compliance1.json and compliance2.json in this way, or can the user, e.g., add some other unrelated proofs to logic_proofs, or the order may be different, etc?

From the Elixir code it seems that ComplianceInput always has two shielded resources with resource logics inside: input and output. Is this correct? Or can compliance inputs contain other shielded resources?

The compliance_input.json “logic” field always corresponds to the hash of the resource proof binary generated in step 2.

I would stick to an order, like the one you suggested. Maybe in the future the use may add some other data (e.g. there was some discussion on adding “hints”) but we can completely forget about that.

Yes

No

The compliance_input.json “logic” field always corresponds to the hash of the resource proof binary generated in step 2.

Sorry, I meant step 4 not 3, but I assume from the above that the answer is yes.

I think that then we can merge steps 2-4 into one step from the user perspective. Because if the partial transaction is uniquely determined from the compliance files, then we could take as input:

  • compliance_input.json files with paths to compiled Cairo bytecode in the “logic” fields,
  • json files storing inputs for the resource logics.

Then we can automatically do the following without user intervention:

  • generate proofs for resource logics (step 2 above)
  • generate the compliance proof using the compliance_input.json files provided, but with the “logic” fields substituted with hashes of the generated resource logic proofs (step 3)
  • create a partial transaction which is uniquely determined from the resource and compliance proofs that we’ve generated
  • create a final transaction
  • submit nock-encoded transaction candidate

So the user wouldn’t see any proofs – everything happens under the hood. They only need to provide compliance circuit input files with “logic” fields pointing to compiled cairo bytecode for the resource logics, and files storing inputs for each resource logic

1 Like

This assumes that the final transaction contains only one partial transaction, which if I remember correctly is the case for now. In the future, we might need to have a command to generate each partial transaction separately.

1 Like

Can someone (@xuyang ?) explain again how to hash a resource logic proof? Because I didn’t note this down. I forgot which hash function to use and now I’m getting some errors.

The API we have can generate the hash of resource logic. You can find it in this example.aarm-cairo/test/cairo_logic_test.exs at base · anoma/aarm-cairo · GitHub

All the APIs are available in Anoma. Let me know if you have any questions about generating the hash. @Lukasz

1 Like

The final transaction contains a bunch of partial transactions. The number depends on the applications or intents as long as we can balance the final transaction.

1 Like