Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Catalyst voting support #8

Merged
merged 10 commits into from
Apr 19, 2021
Merged

Conversation

refi93
Copy link

@refi93 refi93 commented Apr 16, 2021

Motivation: Add support for Catalyst voting registration as specified in CIP-0015: cardano-foundation/CIPs#79 - a custom metadata to be included with Cardano transactions in order for the user to bind their staking key to a randomly generated voting key which would have the proportional weight in the Catalyst voting sidechain.

Changes:

  • introduced __noinline_due_to_stack__ directive to prevent running out of stack space with inlined functions allocating non-trivial memory
  • renamed metadata to auxData in the code to reflect latest CDDL
  • introduce new hash builder for auxiliary data (former metadata in pre-Mary era) needed to compute the hash of the auxiliary data as such as well as the catalyst registration payload (needed to obtain its signature)
  • introduce new dedicated submachine for Catalyst voting registration which triggers from the Auxiliary data step within the main signTx flow
  • the catalyst registration submachine, once in its terminal state, returns the overall auxiliary data hash and registration signature in a single APDU
  • split the sign transaction instruction context into three "parts" - aux_data_ctx, body_ctx and witness_ctx, to be able to reuse memory while serializing those three separate parts of the transaction, avoiding three concurrent hash contexts in case of the catalyst voting registration, otherwise Ledger was running out of memory
  • APDU-wise, the auxiliary data APDU has been put right after the init APDU and extended with "auxiliary data type" enum, other than that there are no breaking changes (TBD if we want to renumber the handler codes https://github.com/vacuumlabs/ledger-app-cardano-shelley/pull/65/files#diff-5fb9b0dad635df88437117ed0aee787f834f3b8730b88ba5921f67b78f20fe52R1556)

Instruction state size:
We originally faced issues with a prohibitively big instruction state size (~1100 bytes) due to three independent hash contexts, each taking up 256 bytes. By putting processing of metadata before the rest of the transaction we were able to save space by sharing memory with the tx body hash builder, saving ~256 bytes.

Testing:

@TamtamHero TamtamHero merged commit 9cda098 into LedgerHQ:master Apr 19, 2021
@janmazak janmazak deleted the catalyst-voting branch June 29, 2021 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants