diff --git a/.gitignore b/.gitignore index eef45f38..828dc9c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ ledger bin +build debug dep obj diff --git a/CHANGELOG.md b/CHANGELOG.md index f535d676..7c5a28b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [6.0.2](TBD) - [TBD] +## [6.0.3](TBD) - [TBD] Support for CIP-36 voting diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index ca21e882..00000000 --- a/Dockerfile +++ /dev/null @@ -1,81 +0,0 @@ -FROM ubuntu:20.04 -ENV LANG C.UTF-8 - -ARG DEBIAN_FRONTEND=noninteractive - -ARG LLVM_VERSION=12 - -RUN apt-get update && apt-get upgrade -qy && \ - apt-get install -qy \ - astyle\ - clang-$LLVM_VERSION \ - clang-tools-$LLVM_VERSION \ - clang-format-$LLVM_VERSION \ - cmake \ - curl \ - doxygen \ - git \ - lcov \ - libbsd-dev \ - libcmocka0 \ - libcmocka-dev \ - lld-$LLVM_VERSION \ - make \ - protobuf-compiler \ - python-is-python3 \ - python3 \ - python3-pip && \ - apt-get autoclean -y && \ - apt-get autoremove -y && \ - apt-get clean - -# Create generic clang & lld symbolic links to their installed version -RUN cd /usr/bin && \ - find . -name "*-"$LLVM_VERSION | sed "s/^\(.*\)\(-"$LLVM_VERSION"\)$/ln -s \1\2 \1/" | sh - -# ARM Embedded Toolchain -# Integrity is checked using the MD5 checksum provided by ARM at https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads -RUN curl -sSfL -o arm-toolchain.tar.bz2 "https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2" && \ - echo 2383e4eb4ea23f248d33adc70dc3227e arm-toolchain.tar.bz2 > /tmp/arm-toolchain.md5 && \ - md5sum --check /tmp/arm-toolchain.md5 && rm /tmp/arm-toolchain.md5 && \ - tar xf arm-toolchain.tar.bz2 -C /opt && \ - rm arm-toolchain.tar.bz2 - -# Adding GCC to PATH and defining rustup/cargo home directories -ENV PATH=/opt/gcc-arm-none-eabi-10.3-2021.10/bin:$PATH \ - RUSTUP_HOME=/opt/rustup \ - CARGO_HOME=/opt/.cargo - -# Install rustup to manage rust toolchains -RUN curl https://sh.rustup.rs -sSf | \ - sh -s -- --default-toolchain stable -y - -# Adding cargo binaries to PATH -ENV PATH=${CARGO_HOME}/bin:${PATH} - -# Adding ARMV6M target to the default toolchain -RUN rustup target add thumbv6m-none-eabi - -# Python packages commonly used by apps -RUN pip3 install ledgerblue pytest - -ARG GIT_SERVER=/~https://github.com/LedgerHQ - -# Latest Nano S SDK -ENV NANOS_SDK=/opt/nanos-secure-sdk -RUN git clone --branch 2.1.0 --depth 1 "$GIT_SERVER/nanos-secure-sdk.git" "$NANOS_SDK" - -# Latest Nano X SDK -ENV NANOX_SDK=/opt/nanox-secure-sdk -RUN git clone --branch 2.0.2-2 --depth 1 "$GIT_SERVER/nanox-secure-sdk.git" "$NANOX_SDK" - -# Latest Nano S+ SDK -ENV NANOSP_SDK=/opt/nanosplus-secure-sdk -RUN git clone --branch 1.0.4 --depth 1 "$GIT_SERVER/nanosplus-secure-sdk.git" "$NANOSP_SDK" - -# Default SDK -ENV BOLOS_SDK=${NANOS_SDK} - -WORKDIR /app - -CMD ["/usr/bin/env", "bash"] diff --git a/Makefile b/Makefile index db2fd81b..d5ee3f7e 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ APPNAME = "Cardano ADA" APPVERSION_M = 6 APPVERSION_N = 0 -APPVERSION_P = 2 +APPVERSION_P = 3 APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)" ifeq ($(BOLOS_SDK),) @@ -176,7 +176,7 @@ seed: ############## format: - astyle --options=.astylerc "src/*.h" "src/*.c" --exclude=src/glyphs.h --exclude=src/glyphs.c + astyle --options=.astylerc "src/*.h" "src/*.c" --exclude=src/glyphs.h --exclude=src/glyphs.c --ignore-exclude-errors ############## diff --git a/doc/build.md b/doc/build.md index 59fe04e3..14a11485 100644 --- a/doc/build.md +++ b/doc/build.md @@ -3,11 +3,9 @@ ## Dependencies - Install Docker -- Update [Dockerfile](../Dockerfile) if needed: check /~https://github.com/LedgerHQ/ledger-app-builder/blob/master/Dockerfile. -- Create Docker image - - `docker build -t ledger-app-builder-cardano:latest .` +- Pull the required containers as discussed in /~https://github.com/LedgerHQ/ledger-app-builder/ (lite container is sufficient for a C build): + `sudo docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest` ## Compiling the app @@ -19,7 +17,7 @@ Based on https://developers.ledger.com/docs/nano-app/build/. - Create container with the image - `docker run --rm -ti -v "$(realpath .):/app" ledger-app-builder-cardano:latest` + `docker run --rm -ti -v "$(realpath .):/app" --user $(id -u $USER):$(id -g $USER) ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest` - Run make commands diff --git a/doc/ins_sign_cip36_registration.md b/doc/ins_sign_cip36_registration.md index 9940ce0c..9fe21c43 100644 --- a/doc/ins_sign_cip36_registration.md +++ b/doc/ins_sign_cip36_registration.md @@ -1,4 +1,4 @@ -# CIP36 Voting Key Registration +# CIP36 Vote Key Registration ## Description @@ -34,7 +34,7 @@ P2 = `0x36` --- -**Voting key** +**Vote key** A single APDU with voting key is sent if the number of delegations specified in the init APDU is 0 (otherwise no such APDU is allowed). @@ -45,7 +45,7 @@ P2 = `0x30` |Field| Length | Comments| |-----|--------|---------| |Key type | 1 | 0x01 or 0x02 if a 32-byte key or its derivation path follows | -|Voting public key: bytestring or BIP44 derivation path | | (depends on previous line) | +|Vote public key: bytestring or BIP44 derivation path | | (depends on previous line) | **Delegation** @@ -59,7 +59,7 @@ P2 = `0x37` |Field| Length | Comments| |-----|--------|---------| |Key type | 1 | 0x01 or 0x02 if a 32-byte key or its derivation path follows | -|Voting public key: bytestring or BIP44 derivation path | | (depends on previous line) | +|Vote public key: bytestring or BIP44 derivation path | | (depends on previous line) | |Weight | 4 | big endian | --- @@ -76,7 +76,7 @@ P2 = `0x31` --- -**Voting rewards address** +**Voting rewards payment address** P2 = `0x32` diff --git a/doc/ins_sign_tx.md b/doc/ins_sign_tx.md index dd5f1ca3..bbaafa4b 100644 --- a/doc/ins_sign_tx.md +++ b/doc/ins_sign_tx.md @@ -98,11 +98,11 @@ So only the hash is transferred and displayed and the user has to use other mean | Auxiliary data type | 1 | `AUX_DATA_TYPE_ARBITRARY_HASH=0x00` | | Auxiliary data hash | 32 | | -**Data for AUX_DATA_TYPE_CIP36_REGISTRATION** +**Data for AUX_DATA_TYPE_CVOTE_REGISTRATION** |Field| Length | Comments| |-----|--------|---------| -| Auxiliary data type | 1 | `AUX_DATA_TYPE_CIP36_REGISTRATION=0x01` | +| Auxiliary data type | 1 | `AUX_DATA_TYPE_CVOTE_REGISTRATION=0x01` | This only describes the initial message. All the data for this type of auxiliary data are obtained via a series of additional APDU messages; see [CIP-36 Voting Registration](ins_sign_cip36_registration.md) for the details. diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt index cbe1e9a8..e57620c5 100644 --- a/fuzz/CMakeLists.txt +++ b/fuzz/CMakeLists.txt @@ -96,7 +96,7 @@ set(SOURCES ../src/signTxOutput.c ../src/state.c ../src/signTxPoolRegistration.c - ../src/signTxGovernanceVotingRegistration.c + ../src/signTxCVoteRegistration.c ../src/signTxUtils.c ../src/textUtils.c ../src/txHashBuilder.c diff --git a/src/addressUtilsByron.c b/src/addressUtilsByron.c index bf043a15..c621535c 100644 --- a/src/addressUtilsByron.c +++ b/src/addressUtilsByron.c @@ -86,7 +86,7 @@ size_t cborEncodePubkeyAddressInner( if (protocolMagic == MAINNET_PROTOCOL_MAGIC) { view_appendToken(&out, CBOR_TYPE_MAP, 0 /* addrAttributes is empty */); } else { - /* addrAddtributes contains protocol magic for non-mainnet Byron addresses */ + /* addrAttributes contains protocol magic for non-mainnet Byron addresses */ view_appendToken(&out, CBOR_TYPE_MAP, 1); { view_appendToken(&out, CBOR_TYPE_UNSIGNED, PROTOCOL_MAGIC_ADDRESS_ATTRIBUTE_KEY); /* map key for protocol magic */ diff --git a/src/addressUtilsShelley_test.c b/src/addressUtilsShelley_test.c index 434365a7..9b2b91ba 100644 --- a/src/addressUtilsShelley_test.c +++ b/src/addressUtilsShelley_test.c @@ -126,35 +126,41 @@ static void testAddressDerivation() BASE_PAYMENT_KEY_STAKE_KEY, 0x03, (HD + 1852, HD + 1815, HD + 0, 0, 1), STAKING_KEY_PATH, (HD + 1852, HD + 1815, HD + 0, 2, 0), NO_STAKING_KEY_HASH, "035a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b31d227aefa4b773149170885aadba30aab3127cc611ddbc4999def61c" + /* cspell:disable-next-line */ // bech32: addr1qdd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vcayfawlf9hwv2fzuygt2km5v92kvf8e3s3mk7ynxw77cwqdquehe ); TESTCASE( BASE_PAYMENT_KEY_STAKE_KEY, 0x00, (HD + 1852, HD + 1815, HD + 0, 0, 1), STAKING_KEY_PATH, (HD + 1852, HD + 1815, HD + 0, 2, 0), NO_STAKING_KEY_HASH, "005a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b31d227aefa4b773149170885aadba30aab3127cc611ddbc4999def61c" + /* cspell:disable-next-line */ // bech32: addr1qpd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vcayfawlf9hwv2fzuygt2km5v92kvf8e3s3mk7ynxw77cwqhn8sgh ); TESTCASE( BASE_PAYMENT_KEY_STAKE_KEY, 0x00, (HD + 1852, HD + 1815, HD + 0, 0, 1), STAKING_KEY_HASH, NO_STAKING_KEY_PATH, "1d227aefa4b773149170885aadba30aab3127cc611ddbc4999def61c", "005a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b31d227aefa4b773149170885aadba30aab3127cc611ddbc4999def61c" + /* cspell:disable-next-line */ // bech32: addr1qpd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vcayfawlf9hwv2fzuygt2km5v92kvf8e3s3mk7ynxw77cwqhn8sgh ); TESTCASE( BASE_PAYMENT_KEY_STAKE_KEY, 0x03, (HD + 1852, HD + 1815, HD + 0, 0, 1), STAKING_KEY_HASH, NO_STAKING_KEY_PATH, "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277", "035a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b3122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277" + /* cspell:disable-next-line */ // bech32: addr1qdd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vcj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmswz93l5 ); TESTCASE( ENTERPRISE_KEY, 0x00, (HD + 1852, HD + 1815, HD + 0, 0, 1), NO_STAKING, NO_STAKING_KEY_PATH, NO_STAKING_KEY_HASH, "605a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b3" + /* cspell:disable-next-line */ // bech32: addr1vpd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vc93wyej ); TESTCASE( ENTERPRISE_KEY, 0x03, (HD + 1852, HD + 1815, HD + 0, 0, 1), NO_STAKING, NO_STAKING_KEY_PATH, NO_STAKING_KEY_HASH, "635a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b3" + /* cspell:disable-next-line */ // bech32: addr1vdd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vc9wh7em ); @@ -172,16 +178,19 @@ static void testAddressDerivation() TESTCASE_POINTER( POINTER_KEY, 0x00, (HD + 1852, HD + 1815, HD + 0, 0, 1), (1, 2, 3), "405a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b3010203" + /* cspell:disable-next-line */ // bech32: addr1gpd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vcpqgpsh506pr ); TESTCASE_POINTER( POINTER_KEY, 0x03, (HD + 1852, HD + 1815, HD + 0, 0, 1), (24157, 177, 42), "435a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b381bc5d81312a" + /* cspell:disable-next-line */ // bech32: addr1gdd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vuph3wczvf288aeyu ); TESTCASE_POINTER( POINTER_KEY, 0x03, (HD + 1852, HD + 1815, HD + 0, 0, 1), (0, 0, 0), "435a53103829a7382c2ab76111fb69f13e69d616824c62058e44f1a8b3000000" + /* cspell:disable-next-line */ // bech32: addr1gdd9xypc9xnnstp2kas3r7mf7ylxn4sksfxxypvwgnc63vcqqqqqnnd32q ); diff --git a/src/auxDataHashBuilder.c b/src/auxDataHashBuilder.c index f69220c7..771ca29a 100644 --- a/src/auxDataHashBuilder.c +++ b/src/auxDataHashBuilder.c @@ -18,7 +18,7 @@ enum { HC_AUX_DATA = (1u << 0), // aux data hash context - HC_GOVERNANCE_VOTING_PAYLOAD = (1u << 1) // governance voting registration payload hash context + HC_CVOTE_REGISTRATION_PAYLOAD = (1u << 1) // cip36 registration payload hash context }; /* @@ -31,16 +31,16 @@ The following macros and functions have dual purpose: if (hashContexts & HC_AUX_DATA) { \ blake2b_256_append_cbor_aux_data(&builder->auxDataHash, type, value, true); \ } \ - if (hashContexts & HC_GOVERNANCE_VOTING_PAYLOAD) { \ - blake2b_256_append_cbor_aux_data(&builder->governanceVotingRegistrationData.payloadHash, type, value, false); \ + if (hashContexts & HC_CVOTE_REGISTRATION_PAYLOAD) { \ + blake2b_256_append_cbor_aux_data(&builder->cVoteRegistrationData.payloadHash, type, value, false); \ } #define APPEND_DATA(hashContexts, buffer, bufferSize) \ if (hashContexts & HC_AUX_DATA) { \ blake2b_256_append_buffer_aux_data(&builder->auxDataHash, buffer, bufferSize, true); \ } \ - if (hashContexts & HC_GOVERNANCE_VOTING_PAYLOAD) { \ - blake2b_256_append_buffer_aux_data(&builder->governanceVotingRegistrationData.payloadHash, buffer, bufferSize, false); \ + if (hashContexts & HC_CVOTE_REGISTRATION_PAYLOAD) { \ + blake2b_256_append_buffer_aux_data(&builder->cVoteRegistrationData.payloadHash, buffer, bufferSize, false); \ } @@ -83,7 +83,7 @@ void auxDataHashBuilder_init( { TRACE("Serializing tx auxiliary data"); blake2b_256_init(&builder->auxDataHash); - blake2b_256_init(&builder->governanceVotingRegistrationData.payloadHash); + blake2b_256_init(&builder->cVoteRegistrationData.payloadHash); { APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_ARRAY, 2); @@ -91,109 +91,109 @@ void auxDataHashBuilder_init( builder->state = AUX_DATA_HASH_BUILDER_INIT; } -void auxDataHashBuilder_governanceVotingRegistration_enter( +void auxDataHashBuilder_cVoteRegistration_enter( aux_data_hash_builder_t* builder, - governance_voting_registration_format_t format + cvote_registration_format_t format ) { _TRACE("state = %d", builder->state); ASSERT(format == CIP15 || format == CIP36); - builder->governanceVotingRegistrationData.format = format; + builder->cVoteRegistrationData.format = format; ASSERT(builder->state == AUX_DATA_HASH_BUILDER_INIT); { - // for governance voting, in the completed auxiliary data + // for cip36 registration, in the completed auxiliary data // there is a map with two entries 61284 and 61285 APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_MAP, 2); // however, the data being signed is a map with a single entry 61284 - APPEND_CBOR(HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_MAP, 1); + APPEND_CBOR(HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_MAP, 1); // the remainder of the payload serialization shares the cbor tokens // with the overall auxiliary data CBOR } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_REGISTRATION_INIT; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_INIT; } -void auxDataHashBuilder_governanceVotingRegistration_enterPayload(aux_data_hash_builder_t* builder) +void auxDataHashBuilder_cVoteRegistration_enterPayload(aux_data_hash_builder_t* builder) { _TRACE("state = %d", builder->state); - ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_REGISTRATION_INIT); + ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_INIT); { - // Enter the governance voting key registration payload inner map - size_t mapSize = (builder->governanceVotingRegistrationData.format == CIP36) ? 5 : 4; - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, METADATA_KEY_GOVERNANCE_VOTING_REGISTRATION_PAYLOAD); - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_MAP, mapSize); + // Enter the cip36 registration payload inner map + size_t mapSize = (builder->cVoteRegistrationData.format == CIP36) ? 5 : 4; + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, METADATA_KEY_CVOTE_REGISTRATION_PAYLOAD); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_MAP, mapSize); } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_INIT; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_INIT; } -void auxDataHashBuilder_governanceVotingRegistration_addVotingKey( +void auxDataHashBuilder_cVoteRegistration_addVoteKey( aux_data_hash_builder_t* builder, - const uint8_t* votingPubKeyBuffer, size_t votingPubKeySize + const uint8_t* votePubKeyBuffer, size_t votePubKeySize ) { _TRACE("state = %d", builder->state); - ASSERT(votingPubKeySize < BUFFER_SIZE_PARANOIA); + ASSERT(votePubKeySize < BUFFER_SIZE_PARANOIA); - ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_INIT); + ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_INIT); { - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_VOTING_KEY); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, CVOTE_REGISTRATION_PAYLOAD_KEY_VOTE_KEY); { - ASSERT(votingPubKeySize == PUBLIC_KEY_SIZE); - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_BYTES, votingPubKeySize); - APPEND_DATA(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, votingPubKeyBuffer, votingPubKeySize); + ASSERT(votePubKeySize == PUBLIC_KEY_SIZE); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_BYTES, votePubKeySize); + APPEND_DATA(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, votePubKeyBuffer, votePubKeySize); } } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_KEY; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_VOTE_KEY; } -void auxDataHashBuilder_governanceVotingRegistration_enterDelegations( +void auxDataHashBuilder_cVoteRegistration_enterDelegations( aux_data_hash_builder_t* builder, size_t numDelegations ) { _TRACE("state = %d", builder->state); - builder->governanceVotingRegistrationData.remainingDelegations = numDelegations; + builder->cVoteRegistrationData.remainingDelegations = numDelegations; - ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_INIT); + ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_INIT); { - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_VOTING_KEY); - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_ARRAY, numDelegations); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, CVOTE_REGISTRATION_PAYLOAD_KEY_VOTE_KEY); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_ARRAY, numDelegations); } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_DELEGATIONS; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_DELEGATIONS; } -void auxDataHashBuilder_governanceVotingRegistration_addDelegation( +void auxDataHashBuilder_cVoteRegistration_addDelegation( aux_data_hash_builder_t* builder, - const uint8_t* votingPubKeyBuffer, size_t votingPubKeySize, + const uint8_t* votePubKeyBuffer, size_t votePubKeySize, uint32_t weight ) { _TRACE("state = %d", builder->state); - ASSERT(votingPubKeySize < BUFFER_SIZE_PARANOIA); + ASSERT(votePubKeySize < BUFFER_SIZE_PARANOIA); - ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_DELEGATIONS); - ASSERT(builder->governanceVotingRegistrationData.remainingDelegations > 0); + ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_DELEGATIONS); + ASSERT(builder->cVoteRegistrationData.remainingDelegations > 0); - builder->governanceVotingRegistrationData.remainingDelegations--; + builder->cVoteRegistrationData.remainingDelegations--; { - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_ARRAY, 2); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_ARRAY, 2); { - ASSERT(votingPubKeySize == PUBLIC_KEY_SIZE); - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_BYTES, votingPubKeySize); - APPEND_DATA(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, votingPubKeyBuffer, votingPubKeySize); + ASSERT(votePubKeySize == PUBLIC_KEY_SIZE); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_BYTES, votePubKeySize); + APPEND_DATA(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, votePubKeyBuffer, votePubKeySize); } - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, weight); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, weight); } } -void auxDataHashBuilder_governanceVotingRegistration_addStakingKey( +void auxDataHashBuilder_cVoteRegistration_addStakingKey( aux_data_hash_builder_t* builder, const uint8_t* stakingPubKeyBuffer, size_t stakingPubKeySize ) @@ -204,12 +204,12 @@ void auxDataHashBuilder_governanceVotingRegistration_addStakingKey( switch(builder->state) { - case AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_KEY: + case AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_VOTE_KEY: // ok break; - case AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_DELEGATIONS: - ASSERT(builder->governanceVotingRegistrationData.remainingDelegations == 0); + case AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_DELEGATIONS: + ASSERT(builder->cVoteRegistrationData.remainingDelegations == 0); break; default: @@ -218,17 +218,17 @@ void auxDataHashBuilder_governanceVotingRegistration_addStakingKey( } { - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_STAKING_KEY); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, CVOTE_REGISTRATION_PAYLOAD_KEY_STAKING_KEY); { ASSERT(stakingPubKeySize == PUBLIC_KEY_SIZE); - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_BYTES, stakingPubKeySize); - APPEND_DATA(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, stakingPubKeyBuffer, stakingPubKeySize); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_BYTES, stakingPubKeySize); + APPEND_DATA(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, stakingPubKeyBuffer, stakingPubKeySize); } } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_STAKING_KEY; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_STAKING_KEY; } -void auxDataHashBuilder_governanceVotingRegistration_addVotingRewardsAddress( +void auxDataHashBuilder_cVoteRegistration_addPaymentAddress( aux_data_hash_builder_t* builder, const uint8_t* addressBuffer, size_t addressSize ) @@ -238,65 +238,65 @@ void auxDataHashBuilder_governanceVotingRegistration_addVotingRewardsAddress( ASSERT(addressSize > 0); ASSERT(addressSize < BUFFER_SIZE_PARANOIA); - ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_STAKING_KEY); + ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_STAKING_KEY); { - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_VOTING_REWARDS_ADDRESS); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, CVOTE_REGISTRATION_PAYLOAD_PAYMENT_ADDRESS); { - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_BYTES, addressSize); - APPEND_DATA(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, addressBuffer, addressSize); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_BYTES, addressSize); + APPEND_DATA(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, addressBuffer, addressSize); } } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_REWARDS_ADDRESS; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_PAYMENT_ADDRESS; } -void auxDataHashBuilder_governanceVotingRegistration_addNonce( +void auxDataHashBuilder_cVoteRegistration_addNonce( aux_data_hash_builder_t* builder, uint64_t nonce ) { _TRACE("state = %d", builder->state); - ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_REWARDS_ADDRESS); + ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_PAYMENT_ADDRESS); { - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_NONCE); - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, nonce); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, CVOTE_REGISTRATION_PAYLOAD_KEY_NONCE); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, nonce); } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_NONCE; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_NONCE; } -void auxDataHashBuilder_governanceVotingRegistration_addVotingPurpose( +void auxDataHashBuilder_cVoteRegistration_addVotingPurpose( aux_data_hash_builder_t* builder, uint64_t votingPurpose ) { _TRACE("state = %d", builder->state); - ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_NONCE); + ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_NONCE); { - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_VOTING_PURPOSE); - APPEND_CBOR(HC_AUX_DATA | HC_GOVERNANCE_VOTING_PAYLOAD, CBOR_TYPE_UNSIGNED, votingPurpose); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, CVOTE_REGISTRATION_PAYLOAD_VOTING_PURPOSE); + APPEND_CBOR(HC_AUX_DATA | HC_CVOTE_REGISTRATION_PAYLOAD, CBOR_TYPE_UNSIGNED, votingPurpose); } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_PURPOSE; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_VOTING_PURPOSE; } -void auxDataHashBuilder_governanceVotingRegistration_finalizePayload(aux_data_hash_builder_t* builder, uint8_t* outBuffer, size_t outSize) +void auxDataHashBuilder_cVoteRegistration_finalizePayload(aux_data_hash_builder_t* builder, uint8_t* outBuffer, size_t outSize) { _TRACE("state = %d", builder->state); ASSERT(outSize < BUFFER_SIZE_PARANOIA); ASSERT( - builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_NONCE || - builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_PURPOSE + builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_NONCE || + builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_VOTING_PURPOSE ); - ASSERT(outSize == GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_HASH_LENGTH); + ASSERT(outSize == CVOTE_REGISTRATION_PAYLOAD_HASH_LENGTH); { - blake2b_256_finalize(&builder->governanceVotingRegistrationData.payloadHash, outBuffer, outSize); + blake2b_256_finalize(&builder->cVoteRegistrationData.payloadHash, outBuffer, outSize); } } -void auxDataHashBuilder_governanceVotingRegistration_addSignature( +void auxDataHashBuilder_cVoteRegistration_addSignature( aux_data_hash_builder_t* builder, const uint8_t* signatureBuffer, size_t signatureSize ) @@ -306,29 +306,29 @@ void auxDataHashBuilder_governanceVotingRegistration_addSignature( ASSERT(signatureSize < BUFFER_SIZE_PARANOIA); ASSERT( - builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_NONCE || - builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_PURPOSE + builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_NONCE || + builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_VOTING_PURPOSE ); { - APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_UNSIGNED, METADATA_KEY_GOVERNANCE_VOTING_SIGNATURE); + APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_UNSIGNED, METADATA_KEY_CVOTE_REGISTRATION_SIGNATURE); { ASSERT(signatureSize == ED25519_SIGNATURE_LENGTH); APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_MAP, 1); - APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_UNSIGNED, GOVERNANCE_VOTING_REGISTRATION_SIGNATURE_KEY); + APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_UNSIGNED, CVOTE_REGISTRATION_SIGNATURE_KEY); APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_BYTES, signatureSize); APPEND_DATA(HC_AUX_DATA, signatureBuffer, signatureSize); } } - builder->state = AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_SIGNATURE; + builder->state = AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_SIGNATURE; } -void auxDataHashBuilder_governanceVotingRegistration_addAuxiliaryScripts( +void auxDataHashBuilder_cVoteRegistration_addAuxiliaryScripts( aux_data_hash_builder_t* builder ) { _TRACE("state = %d", builder->state); - ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_SIGNATURE); + ASSERT(builder->state == AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_SIGNATURE); { // auxiliary scripts currently hard-coded to an empty list APPEND_CBOR(HC_AUX_DATA, CBOR_TYPE_ARRAY, 0); diff --git a/src/auxDataHashBuilder.h b/src/auxDataHashBuilder.h index c2488384..0dd78ffc 100644 --- a/src/auxDataHashBuilder.h +++ b/src/auxDataHashBuilder.h @@ -6,33 +6,33 @@ #include "keyDerivation.h" enum { - METADATA_KEY_GOVERNANCE_VOTING_REGISTRATION_PAYLOAD = 61284, - METADATA_KEY_GOVERNANCE_VOTING_SIGNATURE = 61285, + METADATA_KEY_CVOTE_REGISTRATION_PAYLOAD = 61284, + METADATA_KEY_CVOTE_REGISTRATION_SIGNATURE = 61285, }; enum { - GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_VOTING_KEY = 1, - GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_STAKING_KEY = 2, - GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_VOTING_REWARDS_ADDRESS = 3, - GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_NONCE = 4, - GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_KEY_VOTING_PURPOSE = 5, + CVOTE_REGISTRATION_PAYLOAD_KEY_VOTE_KEY = 1, + CVOTE_REGISTRATION_PAYLOAD_KEY_STAKING_KEY = 2, + CVOTE_REGISTRATION_PAYLOAD_PAYMENT_ADDRESS = 3, + CVOTE_REGISTRATION_PAYLOAD_KEY_NONCE = 4, + CVOTE_REGISTRATION_PAYLOAD_VOTING_PURPOSE = 5, }; enum { - GOVERNANCE_VOTING_REGISTRATION_SIGNATURE_KEY = 1, + CVOTE_REGISTRATION_SIGNATURE_KEY = 1, }; typedef enum { AUX_DATA_HASH_BUILDER_INIT = 100, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_REGISTRATION_INIT = 200, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_INIT = 210, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_KEY = 211, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_DELEGATIONS = 212, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_STAKING_KEY = 213, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_REWARDS_ADDRESS = 214, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_NONCE = 215, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_PAYLOAD_VOTING_PURPOSE = 216, - AUX_DATA_HASH_BUILDER_IN_GOVERNANCE_VOTING_SIGNATURE = 220, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_INIT = 200, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_INIT = 210, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_VOTE_KEY = 211, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_DELEGATIONS = 212, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_STAKING_KEY = 213, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_PAYMENT_ADDRESS = 214, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_NONCE = 215, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_PAYLOAD_VOTING_PURPOSE = 216, + AUX_DATA_HASH_BUILDER_IN_CVOTE_REGISTRATION_SIGNATURE = 220, AUX_DATA_HASH_BUILDER_IN_AUXILIARY_SCRIPTS = 300, AUX_DATA_HASH_BUILDER_FINISHED = 400, } aux_data_hash_builder_state_t; @@ -40,14 +40,14 @@ typedef enum { typedef enum { CIP15 = 1, CIP36 = 2 -} governance_voting_registration_format_t; +} cvote_registration_format_t; typedef struct { struct { blake2b_256_context_t payloadHash; - governance_voting_registration_format_t format; + cvote_registration_format_t format; uint16_t remainingDelegations; - } governanceVotingRegistrationData; + } cVoteRegistrationData; aux_data_hash_builder_state_t state; blake2b_256_context_t auxDataHash; @@ -58,48 +58,48 @@ void auxDataHashBuilder_init( aux_data_hash_builder_t* builder ); -void auxDataHashBuilder_governanceVotingRegistration_enter( +void auxDataHashBuilder_cVoteRegistration_enter( aux_data_hash_builder_t* builder, - governance_voting_registration_format_t format + cvote_registration_format_t format ); -void auxDataHashBuilder_governanceVotingRegistration_enterPayload(aux_data_hash_builder_t* builder); -void auxDataHashBuilder_governanceVotingRegistration_addVotingKey( +void auxDataHashBuilder_cVoteRegistration_enterPayload(aux_data_hash_builder_t* builder); +void auxDataHashBuilder_cVoteRegistration_addVoteKey( aux_data_hash_builder_t* builder, - const uint8_t* votingPubKeyBuffer, size_t votingPubKeySize + const uint8_t* votePubKeyBuffer, size_t votePubKeySize ); -void auxDataHashBuilder_governanceVotingRegistration_enterDelegations( +void auxDataHashBuilder_cVoteRegistration_enterDelegations( aux_data_hash_builder_t* builder, size_t numDelegations ); -void auxDataHashBuilder_governanceVotingRegistration_addDelegation( +void auxDataHashBuilder_cVoteRegistration_addDelegation( aux_data_hash_builder_t* builder, - const uint8_t* votingPubKeyBuffer, size_t votingPubKeySize, + const uint8_t* votePubKeyBuffer, size_t votePubKeySize, uint32_t weight ); -void auxDataHashBuilder_governanceVotingRegistration_addStakingKey( +void auxDataHashBuilder_cVoteRegistration_addStakingKey( aux_data_hash_builder_t* builder, const uint8_t* stakingPubKeyBuffer, size_t stakingPubKeySize ); -void auxDataHashBuilder_governanceVotingRegistration_addVotingRewardsAddress( +void auxDataHashBuilder_cVoteRegistration_addPaymentAddress( aux_data_hash_builder_t* builder, const uint8_t* addressBuffer, size_t addressSize ); -void auxDataHashBuilder_governanceVotingRegistration_addNonce(aux_data_hash_builder_t* builder, uint64_t nonce); -void auxDataHashBuilder_governanceVotingRegistration_addVotingPurpose( +void auxDataHashBuilder_cVoteRegistration_addNonce(aux_data_hash_builder_t* builder, uint64_t nonce); +void auxDataHashBuilder_cVoteRegistration_addVotingPurpose( aux_data_hash_builder_t* builder, uint64_t votingPurpose ); -void auxDataHashBuilder_governanceVotingRegistration_finalizePayload( +void auxDataHashBuilder_cVoteRegistration_finalizePayload( aux_data_hash_builder_t* builder, uint8_t* outBuffer, size_t outSize ); -void auxDataHashBuilder_governanceVotingRegistration_addSignature( +void auxDataHashBuilder_cVoteRegistration_addSignature( aux_data_hash_builder_t* builder, const uint8_t* signatureBuffer, size_t signatureSize ); -void auxDataHashBuilder_governanceVotingRegistration_addAuxiliaryScripts(aux_data_hash_builder_t* builder); +void auxDataHashBuilder_cVoteRegistration_addAuxiliaryScripts(aux_data_hash_builder_t* builder); void auxDataHashBuilder_finalize( aux_data_hash_builder_t* builder, diff --git a/src/auxDataHashBuilder_test.c b/src/auxDataHashBuilder_test.c index 45e4b176..2513a64d 100644 --- a/src/auxDataHashBuilder_test.c +++ b/src/auxDataHashBuilder_test.c @@ -8,28 +8,28 @@ void test_CIP15() { - PRINTF("governance voting CIP15\n"); + PRINTF("CIP15 voting registration\n"); - static const char* votingKey = "3B40265111D8BB3C3C608D95B3A0BF83461ACE32D79336579A1939B3AAD1C0B7"; + static const char* voteKey = "3B40265111D8BB3C3C608D95B3A0BF83461ACE32D79336579A1939B3AAD1C0B7"; static const char* stakingKey = "BC65BE1B0B9D7531778A1317C2AA6DE936963C3F9AC7D5EE9E9EDA25E0C97C5E"; - static const char* votingRewardsAddress = "0180F9E2C88E6C817008F3A812ED889B4A4DA8E0BD103F86E7335422AA122A946B9AD3D2DDF029D3A828F0468AECE76895F15C9EFBD69B4277"; + static const char* paymentAddress = "0180F9E2C88E6C817008F3A812ED889B4A4DA8E0BD103F86E7335422AA122A946B9AD3D2DDF029D3A828F0468AECE76895F15C9EFBD69B4277"; static uint64_t nonce = 22634813; - static const char* governanceVotingRegistrationSignature = "0EA4A424522DD485F16466CD5A754F3C8DBD4D1976C912624E3465C540B1D0776C92633FC64BE057F947AAC561012FE55ACD3C54EF7BECE0DA0B90CF02DC760D"; + static const char* cVoteRegistrationSignature = "0EA4A424522DD485F16466CD5A754F3C8DBD4D1976C912624E3465C540B1D0776C92633FC64BE057F947AAC561012FE55ACD3C54EF7BECE0DA0B90CF02DC760D"; - static const char* expectedGovernanceVotingRegistrationPayloadHashHex = "2EEA6A5168066BDA411F80BE10B50646378616C3414C711A61D363C7879B5CBC"; + static const char* expectedCVoteRegistrationPayloadHashHex = "2EEA6A5168066BDA411F80BE10B50646378616C3414C711A61D363C7879B5CBC"; static const char* expectedAuxDataHashHex = "07cdec3a795626019739f275582433eabe32da80f82aeb74e4916b547c01a589"; aux_data_hash_builder_t builder; auxDataHashBuilder_init(&builder); - auxDataHashBuilder_governanceVotingRegistration_enter(&builder, CIP15); - auxDataHashBuilder_governanceVotingRegistration_enterPayload(&builder); + auxDataHashBuilder_cVoteRegistration_enter(&builder, CIP15); + auxDataHashBuilder_cVoteRegistration_enterPayload(&builder); { uint8_t tmp[32] = {0}; - size_t tmpSize = decode_hex(votingKey, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addVotingKey( + size_t tmpSize = decode_hex(voteKey, tmp, SIZEOF(tmp)); + auxDataHashBuilder_cVoteRegistration_addVoteKey( &builder, tmp, tmpSize ); @@ -38,7 +38,7 @@ void test_CIP15() { uint8_t tmp[32] = {0}; size_t tmpSize = decode_hex(stakingKey, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addStakingKey( + auxDataHashBuilder_cVoteRegistration_addStakingKey( &builder, tmp, tmpSize ); @@ -46,23 +46,23 @@ void test_CIP15() { uint8_t tmp[57] = {0}; - size_t tmpSize = decode_hex(votingRewardsAddress, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addVotingRewardsAddress( + size_t tmpSize = decode_hex(paymentAddress, tmp, SIZEOF(tmp)); + auxDataHashBuilder_cVoteRegistration_addPaymentAddress( &builder, tmp, tmpSize ); } - auxDataHashBuilder_governanceVotingRegistration_addNonce(&builder, nonce); + auxDataHashBuilder_cVoteRegistration_addNonce(&builder, nonce); { uint8_t result[AUX_DATA_HASH_LENGTH] = {0}; - auxDataHashBuilder_governanceVotingRegistration_finalizePayload(&builder, result, SIZEOF(result)); + auxDataHashBuilder_cVoteRegistration_finalizePayload(&builder, result, SIZEOF(result)); uint8_t expected[AUX_DATA_HASH_LENGTH] = {0}; - decode_hex(expectedGovernanceVotingRegistrationPayloadHashHex, expected, SIZEOF(expected)); + decode_hex(expectedCVoteRegistrationPayloadHashHex, expected, SIZEOF(expected)); - PRINTF("Governance voting registration payload hash hex\n"); + PRINTF("registration payload hash hex\n"); PRINTF("%.*h\n", 32, result); EXPECT_EQ_BYTES(result, expected, 32); @@ -70,14 +70,14 @@ void test_CIP15() { uint8_t tmp[64] = {0}; - size_t tmpSize = decode_hex(governanceVotingRegistrationSignature, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addSignature( + size_t tmpSize = decode_hex(cVoteRegistrationSignature, tmp, SIZEOF(tmp)); + auxDataHashBuilder_cVoteRegistration_addSignature( &builder, tmp, tmpSize ); } - auxDataHashBuilder_governanceVotingRegistration_addAuxiliaryScripts(&builder); + auxDataHashBuilder_cVoteRegistration_addAuxiliaryScripts(&builder); { uint8_t result[AUX_DATA_HASH_LENGTH] = {0}; @@ -95,7 +95,7 @@ void test_CIP15() void test_CIP36() { - PRINTF("governance voting CIP36\n"); + PRINTF("CIP36 voting registration\n"); // data from https://cips.cardano.org/cips/cip36/test-vector.md.html @@ -105,26 +105,26 @@ void test_CIP36() static const uint64_t delegationWeight2 = 3; static const char* stakingKey = "86870efc99c453a873a16492ce87738ec79a0ebd064379a62e2c9cf4e119219e"; - static const char* votingRewardsAddress = "e0ae3a0a7aeda4aea522e74e4fe36759fca80789a613a58a4364f6ecef"; + static const char* paymentAddress = "e0ae3a0a7aeda4aea522e74e4fe36759fca80789a613a58a4364f6ecef"; static const uint64_t nonce = 1234; static const uint64_t votingPurpose = 0; - static const char* governanceVotingRegistrationSignature = "0ea4a424522dd485f16466cd5a754f3c8dbd4d1976c912624e3465c540b1d0776c92633fc64be057f947aac561012fe55acd3c54ef7bece0da0b90cf02dc760d"; + static const char* cVoteRegistrationSignature = "0ea4a424522dd485f16466cd5a754f3c8dbd4d1976c912624e3465c540b1d0776c92633fc64be057f947aac561012fe55acd3c54ef7bece0da0b90cf02dc760d"; - static const char* expectedGovernanceVotingRegistrationPayloadHashHex = "5bc0681f173efd76e1989037a3694b8a7abea22053f5940cbb5cfcdf721007d7"; + static const char* expectedCVoteRegistrationPayloadHashHex = "5bc0681f173efd76e1989037a3694b8a7abea22053f5940cbb5cfcdf721007d7"; static const char* expectedAuxDataHashHex = "3786b3ad677129e43dbb3456e45e5af589e9aae81062ef7e26f15fde00df421d"; aux_data_hash_builder_t builder; auxDataHashBuilder_init(&builder); - auxDataHashBuilder_governanceVotingRegistration_enter(&builder, CIP36); - auxDataHashBuilder_governanceVotingRegistration_enterPayload(&builder); + auxDataHashBuilder_cVoteRegistration_enter(&builder, CIP36); + auxDataHashBuilder_cVoteRegistration_enterPayload(&builder); - auxDataHashBuilder_governanceVotingRegistration_enterDelegations(&builder, 2); + auxDataHashBuilder_cVoteRegistration_enterDelegations(&builder, 2); { uint8_t tmp[32] = {0}; size_t tmpSize = decode_hex(delegationKey1, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addDelegation( + auxDataHashBuilder_cVoteRegistration_addDelegation( &builder, tmp, tmpSize, delegationWeight1 @@ -133,7 +133,7 @@ void test_CIP36() { uint8_t tmp[32] = {0}; size_t tmpSize = decode_hex(delegationKey2, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addDelegation( + auxDataHashBuilder_cVoteRegistration_addDelegation( &builder, tmp, tmpSize, delegationWeight2 @@ -143,7 +143,7 @@ void test_CIP36() { uint8_t tmp[32] = {0}; size_t tmpSize = decode_hex(stakingKey, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addStakingKey( + auxDataHashBuilder_cVoteRegistration_addStakingKey( &builder, tmp, tmpSize ); @@ -151,24 +151,24 @@ void test_CIP36() { uint8_t tmp[57] = {0}; - size_t tmpSize = decode_hex(votingRewardsAddress, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addVotingRewardsAddress( + size_t tmpSize = decode_hex(paymentAddress, tmp, SIZEOF(tmp)); + auxDataHashBuilder_cVoteRegistration_addPaymentAddress( &builder, tmp, tmpSize ); } - auxDataHashBuilder_governanceVotingRegistration_addNonce(&builder, nonce); - auxDataHashBuilder_governanceVotingRegistration_addVotingPurpose(&builder, votingPurpose); + auxDataHashBuilder_cVoteRegistration_addNonce(&builder, nonce); + auxDataHashBuilder_cVoteRegistration_addVotingPurpose(&builder, votingPurpose); { uint8_t result[AUX_DATA_HASH_LENGTH] = {0}; - auxDataHashBuilder_governanceVotingRegistration_finalizePayload(&builder, result, SIZEOF(result)); + auxDataHashBuilder_cVoteRegistration_finalizePayload(&builder, result, SIZEOF(result)); uint8_t expected[AUX_DATA_HASH_LENGTH] = {0}; - decode_hex(expectedGovernanceVotingRegistrationPayloadHashHex, expected, SIZEOF(expected)); + decode_hex(expectedCVoteRegistrationPayloadHashHex, expected, SIZEOF(expected)); - PRINTF("Governance voting registration payload hash hex\n"); + PRINTF("registration payload hash hex\n"); PRINTF("%.*h\n", 32, result); EXPECT_EQ_BYTES(result, expected, 32); @@ -176,14 +176,14 @@ void test_CIP36() { uint8_t tmp[64] = {0}; - size_t tmpSize = decode_hex(governanceVotingRegistrationSignature, tmp, SIZEOF(tmp)); - auxDataHashBuilder_governanceVotingRegistration_addSignature( + size_t tmpSize = decode_hex(cVoteRegistrationSignature, tmp, SIZEOF(tmp)); + auxDataHashBuilder_cVoteRegistration_addSignature( &builder, tmp, tmpSize ); } - auxDataHashBuilder_governanceVotingRegistration_addAuxiliaryScripts(&builder); + auxDataHashBuilder_cVoteRegistration_addAuxiliaryScripts(&builder); { uint8_t result[AUX_DATA_HASH_LENGTH] = {0}; diff --git a/src/base58.c b/src/base58.c index cc478f6c..59853102 100644 --- a/src/base58.c +++ b/src/base58.c @@ -22,6 +22,7 @@ #define MAX_BUFFER_SIZE 124 +/* cspell:disable-next-line */ static const char BASE58ALPHABET[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; size_t base58_encode( diff --git a/src/base58_test.c b/src/base58_test.c index be5e39fd..522c85b1 100644 --- a/src/base58_test.c +++ b/src/base58_test.c @@ -36,6 +36,7 @@ void run_base58_test() { "82d818582183581ce63175c654dfd93a9290342a067158dc0f57a1108ddbd8cace3839bda0001a0a0e41ce", + /* cspell:disable-next-line */ "Ae2tdPwUPEZKmwoy3AU3cXb5Chnasj6mvVNxV1H11997q3VW5ihbSfQwGpm" }, diff --git a/src/bech32.c b/src/bech32.c index 5fe07aba..4ac6a7f3 100644 --- a/src/bech32.c +++ b/src/bech32.c @@ -32,6 +32,7 @@ uint32_t bech32_polymod_step(uint32_t pre) (-((b >> 3) & 1) & 0x3d4233ddUL) ^ (-((b >> 4) & 1) & 0x2a1462b3UL); } +/* cspell:disable-next-line */ static const char* charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; /** Encode a Bech32 string diff --git a/src/bech32_test.c b/src/bech32_test.c index 9c900a99..66dfaef6 100644 --- a/src/bech32_test.c +++ b/src/bech32_test.c @@ -36,12 +36,14 @@ void run_bech32_test() const char* inputBytesHex; const char* expectedHex; } testVectors[] = { + /* cspell:disable */ {"a", "", "a12uel5l"}, {"an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio", "", "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs"}, {"abcdef", "00443214c74254b635cf84653a56d7c675be77df", "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw"}, {"1", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j"}, {"split", "c5f38b70305f519bf66d85fb6cf03058f3dde463ecd7918f2dc743918f2d", "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w"}, {"addr", "009493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e32c728d3861e164cab28cb8f006448139c8f1740ffb8e7aa9e5232dc", "addr1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwqcyl47r"} + /* cspell:enable */ }; ITERATE(it, testVectors) { testcase_bech32(PTR_PIC(it->hrp), PTR_PIC(it->inputBytesHex), PTR_PIC(it->expectedHex)); diff --git a/src/bip44.c b/src/bip44.c index 759ae448..0907eb14 100644 --- a/src/bip44.c +++ b/src/bip44.c @@ -119,11 +119,11 @@ bool bip44_hasPoolColdKeyPrefix(const bip44_path_t* pathSpec) } // /1694'/1815' -bool bip44_hasGovernanceVotingKeyPrefix(const bip44_path_t* pathSpec) +bool bip44_hasCVoteKeyPrefix(const bip44_path_t* pathSpec) { #define CHECK(cond) if (!(cond)) return false CHECK(pathSpec->length > BIP44_I_COIN_TYPE); - CHECK(pathSpec->path[BIP44_I_PURPOSE] == harden(PURPOSE_GOVERNANCE_VOTING_KEY)); + CHECK(pathSpec->path[BIP44_I_PURPOSE] == harden(PURPOSE_CVOTE_KEY)); CHECK(pathSpec->path[BIP44_I_COIN_TYPE] == harden(ADA_COIN_TYPE)); return true; #undef CHECK @@ -267,11 +267,11 @@ bool bip44_isPoolColdKeyPath(const bip44_path_t* pathSpec) #undef CHECK } -bool bip44_isGovernanceVotingKeyPath(const bip44_path_t* pathSpec) +bool bip44_isCVoteKeyPath(const bip44_path_t* pathSpec) { #define CHECK(cond) if (!(cond)) return false CHECK(pathSpec->length == BIP44_I_ADDRESS + 1); - CHECK(bip44_hasGovernanceVotingKeyPrefix(pathSpec)); + CHECK(bip44_hasCVoteKeyPrefix(pathSpec)); CHECK(bip44_getAccount(pathSpec) >= HARDENED_BIP32); CHECK(pathSpec->path[BIP44_I_CHAIN] == 0); // in the future, more might be allowed CHECK(!isHardened(bip44_getAddressValue(pathSpec))); @@ -411,9 +411,9 @@ static bip44_path_type_t bip44_classifyMultisigWalletPath(const bip44_path_t* pa } } -static bip44_path_type_t bip44_classifyGovernanceVotingPath(const bip44_path_t* pathSpec) +static bip44_path_type_t bip44_classifyCVotePath(const bip44_path_t* pathSpec) { - ASSERT(bip44_hasGovernanceVotingKeyPrefix(pathSpec)); + ASSERT(bip44_hasCVoteKeyPrefix(pathSpec)); // account must be hardened if (!bip44_containsAccount(pathSpec)) { @@ -425,11 +425,11 @@ static bip44_path_type_t bip44_classifyGovernanceVotingPath(const bip44_path_t* switch (pathSpec->length) { case 3: { - return PATH_GOVERNANCE_VOTING_ACCOUNT; + return PATH_CVOTE_ACCOUNT; } case 5: { - return bip44_isGovernanceVotingKeyPath(pathSpec) ? - PATH_GOVERNANCE_VOTING_KEY : + return bip44_isCVoteKeyPath(pathSpec) ? + PATH_CVOTE_KEY : PATH_INVALID; } default: @@ -463,8 +463,8 @@ bip44_path_type_t bip44_classifyPath(const bip44_path_t* pathSpec) } } - if (bip44_hasGovernanceVotingKeyPrefix(pathSpec)) { - return bip44_classifyGovernanceVotingPath(pathSpec); + if (bip44_hasCVoteKeyPrefix(pathSpec)) { + return bip44_classifyCVotePath(pathSpec); } return PATH_INVALID; @@ -494,10 +494,10 @@ bool bip44_isPathReasonable(const bip44_path_t* pathSpec) case PATH_POOL_COLD_KEY: return bip44_hasReasonablePoolColdKeyIndex(pathSpec); - case PATH_GOVERNANCE_VOTING_ACCOUNT: + case PATH_CVOTE_ACCOUNT: return bip44_hasReasonableAccount(pathSpec); - case PATH_GOVERNANCE_VOTING_KEY: + case PATH_CVOTE_KEY: return bip44_hasReasonableAccount(pathSpec) && bip44_hasReasonableAddress(pathSpec); default: diff --git a/src/bip44.h b/src/bip44.h index f1e79849..75b882e4 100644 --- a/src/bip44.h +++ b/src/bip44.h @@ -22,7 +22,7 @@ static const uint32_t PURPOSE_MINT = 1855; static const uint32_t PURPOSE_POOL_COLD_KEY = 1853; -static const uint32_t PURPOSE_GOVERNANCE_VOTING_KEY = 1694; +static const uint32_t PURPOSE_CVOTE_KEY = 1694; static const uint32_t ADA_COIN_TYPE = 1815; @@ -42,7 +42,7 @@ enum { // wallet keys: // ordinary https://cips.cardano.org/cips/cip1852/ // multisig https://cips.cardano.org/cips/cip1854/ - // governance voting keys: + // cip36 vote keys: // https://cips.cardano.org/cips/cip36/ BIP44_I_PURPOSE = 0, BIP44_I_COIN_TYPE = 1, @@ -66,7 +66,7 @@ bool bip44_hasOrdinaryWalletKeyPrefix(const bip44_path_t* pathSpec); bool bip44_hasMultisigWalletKeyPrefix(const bip44_path_t* pathSpec); bool bip44_hasMintKeyPrefix(const bip44_path_t* pathSpec); bool bip44_hasPoolColdKeyPrefix(const bip44_path_t* pathSpec); -bool bip44_hasGovernanceVotingKeyPrefix(const bip44_path_t* pathSpec); +bool bip44_hasCVoteKeyPrefix(const bip44_path_t* pathSpec); bool bip44_containsAccount(const bip44_path_t* pathSpec); uint32_t bip44_getAccount(const bip44_path_t* pathSpec); @@ -82,7 +82,7 @@ bool bip44_isMintKeyPath(const bip44_path_t* pathSpec); bool bip44_isPoolColdKeyPath(const bip44_path_t* pathSpec); -bool bip44_isGovernanceVotingKeyPath(const bip44_path_t* pathSpec); +bool bip44_isCVoteKeyPath(const bip44_path_t* pathSpec); size_t bip44_printToStr(const bip44_path_t*, char* out, size_t outSize); @@ -96,7 +96,7 @@ typedef enum { PATH_ORDINARY_SPENDING_KEY, PATH_MULTISIG_SPENDING_KEY, - // hd wallet reward adress, withdrawal witness, pool owner + // hd wallet reward address, withdrawal witness, pool owner PATH_ORDINARY_STAKING_KEY, PATH_MULTISIG_STAKING_KEY, @@ -106,9 +106,9 @@ typedef enum { // pool cold key in pool registrations and retirements PATH_POOL_COLD_KEY, - // governance voting, incl. Catalyst - PATH_GOVERNANCE_VOTING_ACCOUNT, - PATH_GOVERNANCE_VOTING_KEY, + // cip36 voting, incl. Catalyst + PATH_CVOTE_ACCOUNT, + PATH_CVOTE_KEY, // none of the above PATH_INVALID, diff --git a/src/cardano.h b/src/cardano.h index 84fbd46b..cf79bccb 100644 --- a/src/cardano.h +++ b/src/cardano.h @@ -19,7 +19,7 @@ STATIC_ASSERT(LOVELACE_MAX_SUPPLY < LOVELACE_INVALID, "bad LOVELACE_INVALID"); #define TX_HASH_LENGTH 32 #define AUX_DATA_HASH_LENGTH 32 #define POOL_METADATA_HASH_LENGTH 32 -#define GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_HASH_LENGTH 32 +#define CVOTE_REGISTRATION_PAYLOAD_HASH_LENGTH 32 #define ED25519_SIGNATURE_LENGTH 64 #define SCRIPT_HASH_LENGTH 28 #define SCRIPT_DATA_HASH_LENGTH 32 diff --git a/src/errors.h b/src/errors.h index 68ecc4f0..578cf6ee 100644 --- a/src/errors.h +++ b/src/errors.h @@ -2,7 +2,7 @@ #define H_CARDANO_APP_ERRORS enum { - // Successfull responses + // Successful responses SUCCESS = 0x9000, // Start of error which trigger automatic response diff --git a/src/handlers.c b/src/handlers.c index 07204b1a..4c6cc5a1 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -13,7 +13,7 @@ #include "deriveNativeScriptHash.h" #include "signTx.h" #include "signOpCert.h" -#include "signGovernanceVote.h" +#include "signCVote.h" // The APDU protocol uses a single-byte instruction code (INS) to specify // which command should be executed. We'll use this code to dispatch on a @@ -34,7 +34,7 @@ handler_fn_t* lookupHandler(uint8_t ins) // 0x2* - signing related CASE(0x21, signTx_handleAPDU); CASE(0x22, signOpCert_handleAPDU); - CASE(0x23, signGovernanceVote_handleAPDU); + CASE(0x23, signCVote_handleAPDU); #ifdef DEVEL // 0xF* - debug_mode related diff --git a/src/messageSigning.c b/src/messageSigning.c index 5e463eb6..a6aab51f 100644 --- a/src/messageSigning.c +++ b/src/messageSigning.c @@ -76,11 +76,11 @@ void getWitness(bip44_path_t* pathSpec, #endif } -void getGovernanceVotingRegistrationSignature(bip44_path_t* pathSpec, - const uint8_t* payloadHashBuffer, size_t payloadHashSize, - uint8_t* outBuffer, size_t outSize) +void getCVoteRegistrationSignature(bip44_path_t* pathSpec, + const uint8_t* payloadHashBuffer, size_t payloadHashSize, + uint8_t* outBuffer, size_t outSize) { - ASSERT(payloadHashSize == GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_HASH_LENGTH); + ASSERT(payloadHashSize == CVOTE_REGISTRATION_PAYLOAD_HASH_LENGTH); ASSERT(outSize < BUFFER_SIZE_PARANOIA); #ifndef FUZZING diff --git a/src/messageSigning.h b/src/messageSigning.h index 634ae289..fbf18f89 100644 --- a/src/messageSigning.h +++ b/src/messageSigning.h @@ -7,9 +7,9 @@ void getWitness(bip44_path_t* pathSpec, const uint8_t* txHashBuffer, size_t txHashSize, uint8_t* outBuffer, size_t outSize); -void getGovernanceVotingRegistrationSignature(bip44_path_t* pathSpec, - const uint8_t* payloadHashBuffer, size_t payloadHashSize, - uint8_t* outBuffer, size_t outSize); +void getCVoteRegistrationSignature(bip44_path_t* pathSpec, + const uint8_t* payloadHashBuffer, size_t payloadHashSize, + uint8_t* outBuffer, size_t outSize); void getOpCertSignature(bip44_path_t* pathSpec, const uint8_t* opCertBodyBuffer, size_t opCertBodySize, diff --git a/src/securityPolicy.c b/src/securityPolicy.c index b4838a4c..5e613a75 100644 --- a/src/securityPolicy.c +++ b/src/securityPolicy.c @@ -86,8 +86,8 @@ security_policy_t policyForDerivePrivateKey(const bip44_path_t* path) case PATH_POOL_COLD_KEY: - case PATH_GOVERNANCE_VOTING_ACCOUNT: - case PATH_GOVERNANCE_VOTING_KEY: + case PATH_CVOTE_ACCOUNT: + case PATH_CVOTE_KEY: ALLOW(); break; @@ -146,7 +146,7 @@ security_policy_t policyForGetExtendedPublicKey(const bip44_path_t* pathSpec) PROMPT(); break; - case PATH_GOVERNANCE_VOTING_ACCOUNT: + case PATH_CVOTE_ACCOUNT: WARN_UNLESS(bip44_isPathReasonable(pathSpec)); // in expert mode, do not export keys without permission @@ -159,7 +159,7 @@ security_policy_t policyForGetExtendedPublicKey(const bip44_path_t* pathSpec) case PATH_ORDINARY_STAKING_KEY: case PATH_MULTISIG_SPENDING_KEY: case PATH_MULTISIG_STAKING_KEY: - case PATH_GOVERNANCE_VOTING_KEY: + case PATH_CVOTE_KEY: WARN_UNLESS(bip44_isPathReasonable(pathSpec)); // ask for permission (it is unusual if client asks this instead of the account key) PROMPT(); @@ -185,8 +185,8 @@ security_policy_t policyForGetExtendedPublicKeyBulkExport(const bip44_path_t* pa case PATH_MULTISIG_SPENDING_KEY: case PATH_MULTISIG_STAKING_KEY: case PATH_MINT_KEY: - case PATH_GOVERNANCE_VOTING_ACCOUNT: - case PATH_GOVERNANCE_VOTING_KEY: + case PATH_CVOTE_ACCOUNT: + case PATH_CVOTE_KEY: WARN_UNLESS(bip44_isPathReasonable(pathSpec)); // we do not show these paths since there may be many of them ALLOW(); @@ -976,13 +976,13 @@ security_policy_t policyForSignTxCertificate( case SIGN_TX_SIGNINGMODE_PLUTUS_TX: case SIGN_TX_SIGNINGMODE_ORDINARY_TX: - // pool registration is allowed only in POOL_REGISTRATION signging modes + // pool registration is allowed only in POOL_REGISTRATION signing modes DENY_IF(certificateType == CERTIFICATE_TYPE_STAKE_POOL_REGISTRATION); ALLOW(); break; case SIGN_TX_SIGNINGMODE_MULTISIG_TX: - // pool registration is allowed only in POOL_REGISTRATION signging modes + // pool registration is allowed only in POOL_REGISTRATION signing modes DENY_IF(certificateType == CERTIFICATE_TYPE_STAKE_POOL_REGISTRATION); // pool retirement is impossible with multisig keys DENY_IF(certificateType == CERTIFICATE_TYPE_STAKE_POOL_RETIREMENT); @@ -1541,10 +1541,10 @@ security_policy_t policyForSignTxAuxData(aux_data_type_t auxDataType) SHOW_IF(app_mode_expert()); ALLOW(); - case AUX_DATA_TYPE_CIP36_REGISTRATION: + case AUX_DATA_TYPE_CVOTE_REGISTRATION: // this is the policy for the initial prompt // details of the registration are governed by separate policies - // (see policyForGovernanceVotingRegistration...) + // (see policyForCVoteRegistration...) SHOW(); break; @@ -1590,7 +1590,7 @@ security_policy_t policyForSignTxMintConfirm(security_policy_t mintInitPolicy) break; case POLICY_SHOW_BEFORE_RESPONSE: - // all minted coins were shown, show a final cofirmation prompt as well + // all minted coins were shown, show a final confirmation prompt as well PROMPT(); break; @@ -1756,26 +1756,26 @@ security_policy_t policyForSignTxConfirm() PROMPT(); } -security_policy_t policyForGovernanceVotingRegistrationVotingKey() +security_policy_t policyForCVoteRegistrationVoteKey() { SHOW(); } -security_policy_t policyForGovernanceVotingRegistrationVotingKeyPath( +security_policy_t policyForCVoteRegistrationVoteKeyPath( bip44_path_t* path, - governance_voting_registration_format_t format + cvote_registration_format_t format ) { // encourages people to use the new format, // so that we can drop support for CIP15 sooner DENY_UNLESS(format == CIP36); - DENY_UNLESS(bip44_classifyPath(path) == PATH_GOVERNANCE_VOTING_KEY); + DENY_UNLESS(bip44_classifyPath(path) == PATH_CVOTE_KEY); WARN_UNLESS(bip44_isPathReasonable(path)); SHOW(); } -security_policy_t policyForGovernanceVotingRegistrationStakingKey( +security_policy_t policyForCVoteRegistrationStakingKey( const bip44_path_t* stakingKeyPath ) { @@ -1787,7 +1787,7 @@ security_policy_t policyForGovernanceVotingRegistrationStakingKey( // based on https://input-output-rnd.slack.com/archives/C036XSMFXE3/p1668185230182239 // TODO make sure this is what we want -security_policy_t policyForGovernanceVotingRegistrationVotingRewardsDestination( +security_policy_t policyForCVoteRegistrationPaymentDestination( const tx_output_destination_storage_t* destination, const uint8_t networkId ) @@ -1832,19 +1832,19 @@ security_policy_t policyForGovernanceVotingRegistrationVotingRewardsDestination( } -security_policy_t policyForGovernanceVotingRegistrationNonce() +security_policy_t policyForCVoteRegistrationNonce() { SHOW(); } -security_policy_t policyForGovernanceVotingRegistrationVotingPurpose() +security_policy_t policyForCVoteRegistrationVotingPurpose() { // since it will only be used for Catalyst, we don't show this value to non-experts SHOW_IF(app_mode_expert()); ALLOW(); } -security_policy_t policyForGovernanceVotingRegistrationConfirm() +security_policy_t policyForCVoteRegistrationConfirm() { PROMPT(); } @@ -1869,20 +1869,20 @@ security_policy_t policyForSignOpCert(const bip44_path_t* poolColdKeyPathSpec) DENY(); // should not be reached } -security_policy_t policyForSignGovernanceVoteInit() +security_policy_t policyForSignCVoteInit() { PROMPT(); } -security_policy_t policyForSignGovernanceVoteConfirm() +security_policy_t policyForSignCVoteConfirm() { PROMPT(); } -security_policy_t policyForSignGovernanceVoteWitness(bip44_path_t* path) +security_policy_t policyForSignCVoteWitness(bip44_path_t* path) { switch (bip44_classifyPath(path)) { - case PATH_GOVERNANCE_VOTING_KEY: + case PATH_CVOTE_KEY: WARN_UNLESS(bip44_isPathReasonable(path)); SHOW(); break; diff --git a/src/securityPolicy.h b/src/securityPolicy.h index 7bf29396..37613d7c 100644 --- a/src/securityPolicy.h +++ b/src/securityPolicy.h @@ -187,24 +187,24 @@ security_policy_t policyForSignTxConfirm(); security_policy_t policyForSignOpCert(const bip44_path_t* poolColdKeyPathSpec); -security_policy_t policyForGovernanceVotingRegistrationVotingKey(); -security_policy_t policyForGovernanceVotingRegistrationVotingKeyPath( +security_policy_t policyForCVoteRegistrationVoteKey(); +security_policy_t policyForCVoteRegistrationVoteKeyPath( bip44_path_t* path, - governance_voting_registration_format_t format + cvote_registration_format_t format ); -security_policy_t policyForGovernanceVotingRegistrationStakingKey( +security_policy_t policyForCVoteRegistrationStakingKey( const bip44_path_t* stakingKeyPath ); -security_policy_t policyForGovernanceVotingRegistrationVotingRewardsDestination( +security_policy_t policyForCVoteRegistrationPaymentDestination( const tx_output_destination_storage_t* destination, const uint8_t networkId ); -security_policy_t policyForGovernanceVotingRegistrationNonce(); -security_policy_t policyForGovernanceVotingRegistrationVotingPurpose(); -security_policy_t policyForGovernanceVotingRegistrationConfirm(); +security_policy_t policyForCVoteRegistrationNonce(); +security_policy_t policyForCVoteRegistrationVotingPurpose(); +security_policy_t policyForCVoteRegistrationConfirm(); -security_policy_t policyForSignGovernanceVoteInit(); -security_policy_t policyForSignGovernanceVoteConfirm(); -security_policy_t policyForSignGovernanceVoteWitness(bip44_path_t* path); +security_policy_t policyForSignCVoteInit(); +security_policy_t policyForSignCVoteConfirm(); +security_policy_t policyForSignCVoteWitness(bip44_path_t* path); #endif // H_CARDANO_APP_SECURITY_POLICY diff --git a/src/signGovernanceVote.c b/src/signCVote.c similarity index 91% rename from src/signGovernanceVote.c rename to src/signCVote.c index 1f99a563..1cc4c20d 100644 --- a/src/signGovernanceVote.c +++ b/src/signCVote.c @@ -1,15 +1,15 @@ #include "messageSigning.h" #include "securityPolicy.h" -#include "signGovernanceVote.h" +#include "signCVote.h" #include "signTxUtils.h" #include "state.h" #include "uiScreens.h" -static ins_sign_governance_vote_context_t* ctx = &(instructionState.signGovernanceVoteContext); +static ins_sign_cvote_context_t* ctx = &(instructionState.signCVoteContext); static void advanceStage() { - TRACE("Advancing governance voting stage from: %d", ctx->stage); + TRACE("Advancing cip36 voting stage from: %d", ctx->stage); switch (ctx->stage) { case VOTECAST_STAGE_INIT: @@ -43,11 +43,11 @@ static void advanceStage() } - TRACE("Advancing governance voting stage to: %d", ctx->stage); + TRACE("Advancing cip36 voting stage to: %d", ctx->stage); } // this is supposed to be called at the beginning of each APDU handler -static inline void CHECK_STAGE(sign_governance_vote_stage_t expected) +static inline void CHECK_STAGE(sign_cvote_stage_t expected) { TRACE("Checking stage... current one is %d, expected %d", ctx->stage, expected); VALIDATE(ctx->stage == expected, ERR_INVALID_STATE); @@ -73,7 +73,7 @@ static void handleInit_ui_runStep() UI_STEP(HANDLE_INIT_CONFIRM_START) { ui_displayPrompt( "Start new", - "governance vote?", + "vote? (CIP-36)", this_fn, respond_with_user_reject ); @@ -107,7 +107,7 @@ static void handleInit_ui_runStep() } __noinline_due_to_stack__ -void signGovernanceVote_handleInitAPDU( +void signCVote_handleInitAPDU( const uint8_t* wireDataBuffer, size_t wireDataSize ) { @@ -141,7 +141,7 @@ void signGovernanceVote_handleInitAPDU( } // Check security policy - security_policy_t policy = policyForSignGovernanceVoteInit(); + security_policy_t policy = policyForSignCVoteInit(); ENSURE_NOT_DENIED(policy); { @@ -174,7 +174,7 @@ void signGovernanceVote_handleInitAPDU( // ============================== VOTECAST CHUNK ============================== __noinline_due_to_stack__ -void signGovernanceVote_handleVotecastChunkAPDU( +void signCVote_handleVotecastChunkAPDU( const uint8_t* wireDataBuffer, size_t wireDataSize ) { @@ -237,7 +237,7 @@ static void handleConfirm_ui_runStep() } __noinline_due_to_stack__ -void signGovernanceVote_handleConfirmAPDU( +void signCVote_handleConfirmAPDU( const uint8_t* wireDataBuffer MARK_UNUSED, size_t wireDataSize ) { @@ -252,7 +252,7 @@ void signGovernanceVote_handleConfirmAPDU( VALIDATE(wireDataSize == 0, ERR_INVALID_DATA); } - security_policy_t policy = policyForSignGovernanceVoteConfirm(); + security_policy_t policy = policyForSignCVoteConfirm(); TRACE("Policy: %d", (int) policy); ENSURE_NOT_DENIED(policy); @@ -335,7 +335,7 @@ static void handleWitness_ui_runStep() } __noinline_due_to_stack__ -void signGovernanceVote_handleWitnessAPDU( +void signCVote_handleWitnessAPDU( const uint8_t* wireDataBuffer, size_t wireDataSize ) { @@ -358,13 +358,13 @@ void signGovernanceVote_handleWitnessAPDU( PRINTF("\n"); } - security_policy_t policy = policyForSignGovernanceVoteWitness(&ctx->witnessData.path); + security_policy_t policy = policyForSignCVoteWitness(&ctx->witnessData.path); TRACE("Policy: %d", (int) policy); ENSURE_NOT_DENIED(policy); { // compute witness - TRACE("getGovernanceVoteWitness"); + TRACE("getCVoteWitness"); TRACE("votecast hash:"); TRACE_BUFFER(ctx->votecastHash, SIZEOF(ctx->votecastHash)); @@ -400,17 +400,17 @@ static subhandler_fn_t* lookup_subhandler(uint8_t p1) switch (p1) { #define CASE(P1, HANDLER) case P1: return HANDLER; #define DEFAULT(HANDLER) default: return HANDLER; - CASE(0x01, signGovernanceVote_handleInitAPDU); - CASE(0x02, signGovernanceVote_handleVotecastChunkAPDU); - CASE(0x03, signGovernanceVote_handleConfirmAPDU); - CASE(0x04, signGovernanceVote_handleWitnessAPDU); + CASE(0x01, signCVote_handleInitAPDU); + CASE(0x02, signCVote_handleVotecastChunkAPDU); + CASE(0x03, signCVote_handleConfirmAPDU); + CASE(0x04, signCVote_handleWitnessAPDU); DEFAULT(NULL) #undef CASE #undef DEFAULT } } -void signGovernanceVote_handleAPDU( +void signCVote_handleAPDU( uint8_t p1, uint8_t p2, const uint8_t* wireDataBuffer, diff --git a/src/signGovernanceVote.h b/src/signCVote.h similarity index 73% rename from src/signGovernanceVote.h rename to src/signCVote.h index 2bc01df2..42eab7dd 100644 --- a/src/signGovernanceVote.h +++ b/src/signCVote.h @@ -1,5 +1,5 @@ -#ifndef H_CARDANO_APP_SIGN_GOVERNANCE_VOTE -#define H_CARDANO_APP_SIGN_GOVERNANCE_VOTE +#ifndef H_CARDANO_APP_SIGN_CVOTE +#define H_CARDANO_APP_SIGN_CVOTE #include "cardano.h" #include "common.h" @@ -16,10 +16,10 @@ typedef enum { VOTECAST_STAGE_CHUNK = 40, VOTECAST_STAGE_CONFIRM = 60, VOTECAST_STAGE_WITNESS = 80, -} sign_governance_vote_stage_t; +} sign_cvote_stage_t; typedef struct { - sign_governance_vote_stage_t stage; + sign_cvote_stage_t stage; int ui_step; size_t remainingVotecastBytes; @@ -38,8 +38,8 @@ typedef struct { uint8_t signature[ED25519_SIGNATURE_LENGTH]; } witnessData; }; -} ins_sign_governance_vote_context_t; +} ins_sign_cvote_context_t; -handler_fn_t signGovernanceVote_handleAPDU; +handler_fn_t signCVote_handleAPDU; -#endif // H_CARDANO_APP_SIGN_GOVERNANCE_VOTE +#endif // H_CARDANO_APP_SIGN_CVOTE diff --git a/src/signTx.c b/src/signTx.c index c36f8d2d..bee1171c 100644 --- a/src/signTx.c +++ b/src/signTx.c @@ -365,15 +365,15 @@ static inline void checkForFinishedSubmachines() } break; - case SIGN_STAGE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_SUBMACHINE: - if (signTxGovernanceVotingRegistration_isFinished()) { + case SIGN_STAGE_AUX_DATA_CVOTE_REGISTRATION_SUBMACHINE: + if (signTxCVoteRegistration_isFinished()) { TRACE(); ctx->stage = SIGN_STAGE_AUX_DATA; AUX_DATA_CTX->auxDataReceived = true; STATIC_ASSERT(SIZEOF(ctx->auxDataHash) == AUX_DATA_HASH_LENGTH, "Wrong auxiliary data hash length"); - STATIC_ASSERT(SIZEOF(AUX_DATA_CTX->stageContext.governance_voting_registration_subctx.auxDataHash) == AUX_DATA_HASH_LENGTH, "Wrong auxiliary data hash length"); - memmove(ctx->auxDataHash, AUX_DATA_CTX->stageContext.governance_voting_registration_subctx.auxDataHash, AUX_DATA_HASH_LENGTH); + STATIC_ASSERT(SIZEOF(AUX_DATA_CTX->stageContext.cvote_registration_subctx.auxDataHash) == AUX_DATA_HASH_LENGTH, "Wrong auxiliary data hash length"); + memmove(ctx->auxDataHash, AUX_DATA_CTX->stageContext.cvote_registration_subctx.auxDataHash, AUX_DATA_HASH_LENGTH); advanceStage(); } @@ -482,7 +482,7 @@ static void signTx_handleInit_ui_runStep() // technically, no pool reg. certificate as well, but the UI message would be too long ui_displayPaginatedText( "Warning:", - "cannot verify network id: no outputs or withrawals", + "cannot verify network id: no outputs or withdrawals", this_fn ); } @@ -726,33 +726,33 @@ static void signTx_handleAuxDataArbitraryHash_ui_runStep() enum { - HANDLE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_STEP_DISPLAY = 850, - HANDLE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_STEP_RESPOND, - HANDLE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_STEP_INVALID, + HANDLE_AUX_DATA_CVOTE_REGISTRATION_STEP_DISPLAY = 850, + HANDLE_AUX_DATA_CVOTE_REGISTRATION_STEP_RESPOND, + HANDLE_AUX_DATA_CVOTE_REGISTRATION_STEP_INVALID, }; -static void signTx_handleAuxDataGovernanceVotingRegistration_ui_runStep() +static void signTx_handleAuxDataCVoteRegistration_ui_runStep() { TRACE("UI step %d", ctx->ui_step); TRACE_STACK_USAGE(); - ui_callback_fn_t* this_fn = signTx_handleAuxDataGovernanceVotingRegistration_ui_runStep; + ui_callback_fn_t* this_fn = signTx_handleAuxDataCVoteRegistration_ui_runStep; UI_STEP_BEGIN(ctx->ui_step, this_fn); - UI_STEP(HANDLE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_STEP_DISPLAY) { + UI_STEP(HANDLE_AUX_DATA_CVOTE_REGISTRATION_STEP_DISPLAY) { ui_displayPrompt( - "Register governance", - "vote key?", + "Register vote", + "key (CIP-36)?", this_fn, respond_with_user_reject ); } - UI_STEP(HANDLE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_STEP_RESPOND) { + UI_STEP(HANDLE_AUX_DATA_CVOTE_REGISTRATION_STEP_RESPOND) { respondSuccessEmptyMsg(); - signTxGovernanceVotingRegistration_init(); - ctx->stage = SIGN_STAGE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_SUBMACHINE; + signTxCVoteRegistration_init(); + ctx->stage = SIGN_STAGE_AUX_DATA_CVOTE_REGISTRATION_SUBMACHINE; } - UI_STEP_END(HANDLE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_STEP_INVALID); + UI_STEP_END(HANDLE_AUX_DATA_CVOTE_REGISTRATION_STEP_INVALID); } __noinline_due_to_stack__ @@ -763,14 +763,14 @@ static void signTx_handleAuxDataAPDU(uint8_t p2, const uint8_t* wireDataBuffer, ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); ASSERT(ctx->includeAuxData == true); - // delegate to state sub-machine for governance voting registration data - if (signTxGovernanceVotingRegistration_isValidInstruction(p2)) { + // delegate to state sub-machine for CIP-36 voting registration data + if (signTxCVoteRegistration_isValidInstruction(p2)) { TRACE(); - CHECK_STAGE(SIGN_STAGE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_SUBMACHINE); + CHECK_STAGE(SIGN_STAGE_AUX_DATA_CVOTE_REGISTRATION_SUBMACHINE); TRACE_STACK_USAGE(); - signTxGovernanceVotingRegistration_handleAPDU(p2, wireDataBuffer, wireDataSize); + signTxCVoteRegistration_handleAPDU(p2, wireDataBuffer, wireDataSize); return; } @@ -794,7 +794,7 @@ static void signTx_handleAuxDataAPDU(uint8_t p2, const uint8_t* wireDataBuffer, break; } - case AUX_DATA_TYPE_CIP36_REGISTRATION: + case AUX_DATA_TYPE_CVOTE_REGISTRATION: break; default: @@ -823,18 +823,18 @@ static void signTx_handleAuxDataAPDU(uint8_t p2, const uint8_t* wireDataBuffer, signTx_handleAuxDataArbitraryHash_ui_runStep(); break; } - case AUX_DATA_TYPE_CIP36_REGISTRATION: + case AUX_DATA_TYPE_CVOTE_REGISTRATION: // select UI step switch (policy) { #define CASE(POLICY, UI_STEP) case POLICY: {ctx->ui_step=UI_STEP; break;} - CASE(POLICY_SHOW_BEFORE_RESPONSE, HANDLE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_STEP_DISPLAY); - CASE(POLICY_ALLOW_WITHOUT_PROMPT, HANDLE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_STEP_RESPOND); + CASE(POLICY_SHOW_BEFORE_RESPONSE, HANDLE_AUX_DATA_CVOTE_REGISTRATION_STEP_DISPLAY); + CASE(POLICY_ALLOW_WITHOUT_PROMPT, HANDLE_AUX_DATA_CVOTE_REGISTRATION_STEP_RESPOND); #undef CASE default: THROW(ERR_NOT_IMPLEMENTED); } - signTx_handleAuxDataGovernanceVotingRegistration_ui_runStep(); + signTx_handleAuxDataCVoteRegistration_ui_runStep(); break; default: ASSERT(false); @@ -901,7 +901,7 @@ static void constructInputLabel(const char* prefix, uint16_t index) char* label = BODY_CTX->stageData.input.label; const size_t labelSize = SIZEOF(BODY_CTX->stageData.input.label); explicit_bzero(label, labelSize); - // indexed from 0 as agreed with IOHK on Slack + // indexed from 0 as agreed with IOG on Slack snprintf(label, labelSize, "%s #%u", prefix, index); // make sure all the information is displayed to the user ASSERT(strlen(label) + 1 < labelSize); @@ -2572,7 +2572,7 @@ ins_sign_tx_aux_data_context_t* accessAuxDataContext() switch (ctx->stage) { case SIGN_STAGE_AUX_DATA: - case SIGN_STAGE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_SUBMACHINE: + case SIGN_STAGE_AUX_DATA_CVOTE_REGISTRATION_SUBMACHINE: return &(ctx->txPartCtx.aux_data_ctx); default: diff --git a/src/signTx.h b/src/signTx.h index c797df27..d50db9c9 100644 --- a/src/signTx.h +++ b/src/signTx.h @@ -10,7 +10,7 @@ #include "signTxMint.h" #include "signTxOutput.h" #include "signTxPoolRegistration.h" -#include "signTxGovernanceVotingRegistration.h" +#include "signTxCVoteRegistration.h" #include "signTxAuxData.h" // the signing mode significantly affects restrictions on tx being signed @@ -26,7 +26,7 @@ typedef enum { SIGN_STAGE_NONE = 0, SIGN_STAGE_INIT = 23, SIGN_STAGE_AUX_DATA = 24, - SIGN_STAGE_AUX_DATA_GOVERNANCE_VOTING_REGISTRATION_SUBMACHINE = 25, + SIGN_STAGE_AUX_DATA_CVOTE_REGISTRATION_SUBMACHINE = 25, SIGN_STAGE_BODY_INPUTS = 26, SIGN_STAGE_BODY_OUTPUTS = 27, SIGN_STAGE_BODY_OUTPUTS_SUBMACHINE = 28, @@ -121,7 +121,7 @@ typedef struct { aux_data_hash_builder_t auxDataHashBuilder; struct { - governance_voting_registration_context_t governance_voting_registration_subctx; + cvote_registration_context_t cvote_registration_subctx; } stageContext; } ins_sign_tx_aux_data_context_t; diff --git a/src/signTxAuxData.h b/src/signTxAuxData.h index d416192b..1e766fd9 100644 --- a/src/signTxAuxData.h +++ b/src/signTxAuxData.h @@ -3,7 +3,7 @@ typedef enum { AUX_DATA_TYPE_ARBITRARY_HASH = 0, - AUX_DATA_TYPE_CIP36_REGISTRATION = 1, + AUX_DATA_TYPE_CVOTE_REGISTRATION = 1, } aux_data_type_t; #endif // H_CARDANO_APP_SIGN_TX_AUX_DATA diff --git a/src/signTxGovernanceVotingRegistration.c b/src/signTxCVoteRegistration.c similarity index 56% rename from src/signTxGovernanceVotingRegistration.c rename to src/signTxCVoteRegistration.c index b3eb8f8d..50bed876 100644 --- a/src/signTxGovernanceVotingRegistration.c +++ b/src/signTxCVoteRegistration.c @@ -1,5 +1,5 @@ #include "app_mode.h" -#include "signTxGovernanceVotingRegistration.h" +#include "signTxCVoteRegistration.h" #include "state.h" #include "uiHelpers.h" #include "signTxUtils.h" @@ -13,28 +13,28 @@ static common_tx_data_t* commonTxData = &(instructionState.signTxContext.commonTxData); -static inline governance_voting_registration_context_t* accessSubContext() +static inline cvote_registration_context_t* accessSubContext() { - return &AUX_DATA_CTX->stageContext.governance_voting_registration_subctx; + return &AUX_DATA_CTX->stageContext.cvote_registration_subctx; } -bool signTxGovernanceVotingRegistration_isFinished() +bool signTxCVoteRegistration_isFinished() { - const governance_voting_registration_context_t* subctx = accessSubContext(); - TRACE("Governance voting registration submachine state: %d", subctx->state); + const cvote_registration_context_t* subctx = accessSubContext(); + TRACE("CIP-36 voting registration submachine state: %d", subctx->state); // we are also asserting that the state is valid switch (subctx->state) { - case STATE_GOVERNANCE_VOTING_REGISTRATION_FINISHED: + case STATE_CVOTE_REGISTRATION_FINISHED: return true; - case STATE_GOVERNANCE_VOTING_REGISTRATION_INIT: - case STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_KEY: - case STATE_GOVERNANCE_VOTING_REGISTRATION_DELEGATIONS: - case STATE_GOVERNANCE_VOTING_REGISTRATION_STAKING_KEY: - case STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_REWARDS_ADDRESS: - case STATE_GOVERNANCE_VOTING_REGISTRATION_NONCE: - case STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_PURPOSE: - case STATE_GOVERNANCE_VOTING_REGISTRATION_CONFIRM: + case STATE_CVOTE_REGISTRATION_INIT: + case STATE_CVOTE_REGISTRATION_VOTE_KEY: + case STATE_CVOTE_REGISTRATION_DELEGATIONS: + case STATE_CVOTE_REGISTRATION_STAKING_KEY: + case STATE_CVOTE_REGISTRATION_PAYMENT_ADDRESS: + case STATE_CVOTE_REGISTRATION_NONCE: + case STATE_CVOTE_REGISTRATION_VOTING_PURPOSE: + case STATE_CVOTE_REGISTRATION_CONFIRM: return false; default: @@ -42,86 +42,86 @@ bool signTxGovernanceVotingRegistration_isFinished() } } -void signTxGovernanceVotingRegistration_init() +void signTxCVoteRegistration_init() { explicit_bzero(&AUX_DATA_CTX->stageContext, SIZEOF(AUX_DATA_CTX->stageContext)); auxDataHashBuilder_init(&AUX_DATA_CTX->auxDataHashBuilder); - accessSubContext()->state = STATE_GOVERNANCE_VOTING_REGISTRATION_INIT; + accessSubContext()->state = STATE_CVOTE_REGISTRATION_INIT; } -static inline void CHECK_STATE(sign_tx_governance_voting_registration_state_t expected) +static inline void CHECK_STATE(sign_tx_cvote_registration_state_t expected) { - TRACE("Governance voting registration submachine state: current %d, expected %d", accessSubContext()->state, expected); + TRACE("CIP-36 voting registration submachine state: current %d, expected %d", accessSubContext()->state, expected); VALIDATE(accessSubContext()->state == expected, ERR_INVALID_STATE); } static inline void advanceState() { - governance_voting_registration_context_t* subctx = accessSubContext(); - TRACE("Advancing governance voting registration state from: %d", subctx->state); + cvote_registration_context_t* subctx = accessSubContext(); + TRACE("Advancing CIP-36 voting registration state from: %d", subctx->state); switch (subctx->state) { - case STATE_GOVERNANCE_VOTING_REGISTRATION_INIT: + case STATE_CVOTE_REGISTRATION_INIT: if (subctx->numDelegations > 0) { - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_DELEGATIONS; - auxDataHashBuilder_governanceVotingRegistration_enterDelegations( + subctx->state = STATE_CVOTE_REGISTRATION_DELEGATIONS; + auxDataHashBuilder_cVoteRegistration_enterDelegations( &AUX_DATA_CTX->auxDataHashBuilder, subctx->numDelegations ); } else { - // we expect a single voting key - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_KEY; + // we expect a single vote key + subctx->state = STATE_CVOTE_REGISTRATION_VOTE_KEY; } break; - case STATE_GOVERNANCE_VOTING_REGISTRATION_DELEGATIONS: + case STATE_CVOTE_REGISTRATION_DELEGATIONS: ASSERT(subctx->currentDelegation == subctx->numDelegations); - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_STAKING_KEY; + subctx->state = STATE_CVOTE_REGISTRATION_STAKING_KEY; break; - case STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_KEY: - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_STAKING_KEY; + case STATE_CVOTE_REGISTRATION_VOTE_KEY: + subctx->state = STATE_CVOTE_REGISTRATION_STAKING_KEY; break; - case STATE_GOVERNANCE_VOTING_REGISTRATION_STAKING_KEY: - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_REWARDS_ADDRESS; + case STATE_CVOTE_REGISTRATION_STAKING_KEY: + subctx->state = STATE_CVOTE_REGISTRATION_PAYMENT_ADDRESS; break; - case STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_REWARDS_ADDRESS: - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_NONCE; + case STATE_CVOTE_REGISTRATION_PAYMENT_ADDRESS: + subctx->state = STATE_CVOTE_REGISTRATION_NONCE; break; - case STATE_GOVERNANCE_VOTING_REGISTRATION_NONCE: - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_PURPOSE; + case STATE_CVOTE_REGISTRATION_NONCE: + subctx->state = STATE_CVOTE_REGISTRATION_VOTING_PURPOSE; break; - case STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_PURPOSE: - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_CONFIRM; + case STATE_CVOTE_REGISTRATION_VOTING_PURPOSE: + subctx->state = STATE_CVOTE_REGISTRATION_CONFIRM; break; - case STATE_GOVERNANCE_VOTING_REGISTRATION_CONFIRM: - subctx->state = STATE_GOVERNANCE_VOTING_REGISTRATION_FINISHED; + case STATE_CVOTE_REGISTRATION_CONFIRM: + subctx->state = STATE_CVOTE_REGISTRATION_FINISHED; break; default: ASSERT(false); } - TRACE("Advancing governance voting registration state to: %d", subctx->state); + TRACE("Advancing CIP-36 voting registration state to: %d", subctx->state); } // ============================== INIT ============================== -static void signTxGovernanceVotingRegistration_handleInitAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) +static void signTxCVoteRegistration_handleInitAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) { { - CHECK_STATE(STATE_GOVERNANCE_VOTING_REGISTRATION_INIT); + CHECK_STATE(STATE_CVOTE_REGISTRATION_INIT); ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); } - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); { explicit_bzero(&subctx->stateData, SIZEOF(subctx->stateData)); } @@ -132,7 +132,7 @@ static void signTxGovernanceVotingRegistration_handleInitAPDU(const uint8_t* wir read_view_t view = make_read_view(wireDataBuffer, wireDataBuffer + wireDataSize); subctx->format = parse_u1be(&view); - TRACE("Governance voting registration format = %d", (int) subctx->format); + TRACE("CIP-36 voting registration format = %d", (int) subctx->format); switch (subctx->format) { case CIP15: case CIP36: @@ -153,8 +153,8 @@ static void signTxGovernanceVotingRegistration_handleInitAPDU(const uint8_t* wir } { aux_data_hash_builder_t* auxDataHashBuilder = &AUX_DATA_CTX->auxDataHashBuilder; - auxDataHashBuilder_governanceVotingRegistration_enter(auxDataHashBuilder, subctx->format); - auxDataHashBuilder_governanceVotingRegistration_enterPayload(auxDataHashBuilder); + auxDataHashBuilder_cVoteRegistration_enter(auxDataHashBuilder, subctx->format); + auxDataHashBuilder_cVoteRegistration_enterPayload(auxDataHashBuilder); } respondSuccessEmptyMsg(); @@ -163,9 +163,9 @@ static void signTxGovernanceVotingRegistration_handleInitAPDU(const uint8_t* wir // ============================== VOTING KEY ============================== -static void _parseVotingKey(read_view_t* view) +static void _parseVoteKey(read_view_t* view) { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); subctx->stateData.delegation.type = parse_u1be(view); TRACE("delegation type = %d", (int) subctx->stateData.delegation.type); @@ -173,13 +173,13 @@ static void _parseVotingKey(read_view_t* view) case DELEGATION_KEY: { STATIC_ASSERT( - SIZEOF(subctx->stateData.delegation.votingPubKey) == GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH, - "wrong voting public key size" + SIZEOF(subctx->stateData.delegation.votePubKey) == CVOTE_PUBLIC_KEY_LENGTH, + "wrong vote public key size" ); view_parseBuffer( - subctx->stateData.delegation.votingPubKey, + subctx->stateData.delegation.votePubKey, view, - GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH + CVOTE_PUBLIC_KEY_LENGTH ); break; } @@ -188,12 +188,12 @@ static void _parseVotingKey(read_view_t* view) view_skipBytes( view, bip44_parseFromWire( - &subctx->stateData.delegation.votingPubKeyPath, + &subctx->stateData.delegation.votePubKeyPath, VIEW_REMAINING_TO_TUPLE_BUF_SIZE(view) ) ); TRACE(); - BIP44_PRINTF(&subctx->stateData.delegation.votingPubKeyPath); + BIP44_PRINTF(&subctx->stateData.delegation.votePubKeyPath); PRINTF("\n"); break; } @@ -203,20 +203,20 @@ static void _parseVotingKey(read_view_t* view) } } -security_policy_t _determineVotingKeyPolicy() +security_policy_t _determineVoteKeyPolicy() { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); switch (subctx->stateData.delegation.type) { case DELEGATION_PATH: - return policyForGovernanceVotingRegistrationVotingKeyPath( - &subctx->stateData.delegation.votingPubKeyPath, + return policyForCVoteRegistrationVoteKeyPath( + &subctx->stateData.delegation.votePubKeyPath, subctx->format ); case DELEGATION_KEY: - return policyForGovernanceVotingRegistrationVotingKey(); + return policyForCVoteRegistrationVoteKey(); default: ASSERT(false); @@ -224,16 +224,16 @@ security_policy_t _determineVotingKeyPolicy() return POLICY_DENY; } -static void _displayVotingKey(ui_callback_fn_t callback) +static void _displayVoteKey(ui_callback_fn_t callback) { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); switch (subctx->stateData.delegation.type) { case DELEGATION_KEY: { - STATIC_ASSERT(SIZEOF(subctx->stateData.delegation.votingPubKey) == GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH, "wrong voting public key size"); + STATIC_ASSERT(SIZEOF(subctx->stateData.delegation.votePubKey) == CVOTE_PUBLIC_KEY_LENGTH, "wrong vote public key size"); ui_displayBech32Screen( "Vote public key", "cvote_vk", - subctx->stateData.delegation.votingPubKey, GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH, + subctx->stateData.delegation.votePubKey, CVOTE_PUBLIC_KEY_LENGTH, callback ); break; @@ -241,7 +241,7 @@ static void _displayVotingKey(ui_callback_fn_t callback) case DELEGATION_PATH: { ui_displayPathScreen( "Vote public key", - &subctx->stateData.delegation.votingPubKeyPath, + &subctx->stateData.delegation.votePubKeyPath, callback ); break; @@ -252,47 +252,47 @@ static void _displayVotingKey(ui_callback_fn_t callback) } enum { - HANDLE_VOTING_KEY_STEP_WARNING = 8200, - HANDLE_VOTING_KEY_STEP_DISPLAY, - HANDLE_VOTING_KEY_STEP_RESPOND, - HANDLE_VOTING_KEY_STEP_INVALID, + HANDLE_VOTE_KEY_STEP_WARNING = 8200, + HANDLE_VOTE_KEY_STEP_DISPLAY, + HANDLE_VOTE_KEY_STEP_RESPOND, + HANDLE_VOTE_KEY_STEP_INVALID, }; -static void signTxGovernanceVotingRegistration_handleVotingKey_ui_runStep() +static void signTxCVoteRegistration_handleVoteKey_ui_runStep() { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); TRACE("UI step %d", subctx->ui_step); TRACE_STACK_USAGE(); - ui_callback_fn_t* this_fn = signTxGovernanceVotingRegistration_handleVotingKey_ui_runStep; + ui_callback_fn_t* this_fn = signTxCVoteRegistration_handleVoteKey_ui_runStep; UI_STEP_BEGIN(subctx->ui_step, this_fn); - UI_STEP(HANDLE_VOTING_KEY_STEP_WARNING) { + UI_STEP(HANDLE_VOTE_KEY_STEP_WARNING) { ui_displayPaginatedText( "WARNING:", "unusual vote key", this_fn ); } - UI_STEP(HANDLE_VOTING_KEY_STEP_DISPLAY) { - _displayVotingKey(this_fn); + UI_STEP(HANDLE_VOTE_KEY_STEP_DISPLAY) { + _displayVoteKey(this_fn); } - UI_STEP(HANDLE_VOTING_KEY_STEP_RESPOND) { + UI_STEP(HANDLE_VOTE_KEY_STEP_RESPOND) { respondSuccessEmptyMsg(); advanceState(); } - UI_STEP_END(HANDLE_VOTING_KEY_STEP_INVALID); + UI_STEP_END(HANDLE_VOTE_KEY_STEP_INVALID); } __noinline_due_to_stack__ -static void signTxGovernanceVotingRegistration_handleVotingKeyAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) +static void signTxCVoteRegistration_handleVoteKeyAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) { { - CHECK_STATE(STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_KEY); + CHECK_STATE(STATE_CVOTE_REGISTRATION_VOTE_KEY); ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); } - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); { explicit_bzero(&subctx->stateData, SIZEOF(subctx->stateData)); } @@ -300,12 +300,12 @@ static void signTxGovernanceVotingRegistration_handleVotingKeyAPDU(const uint8_t TRACE_BUFFER(wireDataBuffer, wireDataSize); read_view_t view = make_read_view(wireDataBuffer, wireDataBuffer + wireDataSize); - _parseVotingKey(&view); + _parseVoteKey(&view); VALIDATE(view_remainingSize(&view) == 0, ERR_INVALID_DATA); } - security_policy_t policy = _determineVotingKeyPolicy(); + security_policy_t policy = _determineVoteKeyPolicy(); TRACE("Policy: %d", (int) policy); ENSURE_NOT_DENIED(policy); @@ -316,18 +316,18 @@ static void signTxGovernanceVotingRegistration_handleVotingKeyAPDU(const uint8_t switch (subctx->stateData.delegation.type) { case DELEGATION_KEY: { - auxDataHashBuilder_governanceVotingRegistration_addVotingKey( - auxDataHashBuilder, subctx->stateData.delegation.votingPubKey, - GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH + auxDataHashBuilder_cVoteRegistration_addVoteKey( + auxDataHashBuilder, subctx->stateData.delegation.votePubKey, + CVOTE_PUBLIC_KEY_LENGTH ); break; } case DELEGATION_PATH: { - extendedPublicKey_t extVotingPubKey; - deriveExtendedPublicKey(&subctx->stateData.delegation.votingPubKeyPath, &extVotingPubKey); - auxDataHashBuilder_governanceVotingRegistration_addVotingKey( - auxDataHashBuilder, extVotingPubKey.pubKey, SIZEOF(extVotingPubKey.pubKey) + extendedPublicKey_t extVotePubKey; + deriveExtendedPublicKey(&subctx->stateData.delegation.votePubKeyPath, &extVotePubKey); + auxDataHashBuilder_cVoteRegistration_addVoteKey( + auxDataHashBuilder, extVotePubKey.pubKey, SIZEOF(extVotePubKey.pubKey) ); break; } @@ -341,46 +341,46 @@ static void signTxGovernanceVotingRegistration_handleVotingKeyAPDU(const uint8_t // select UI steps switch (policy) { #define CASE(POLICY, UI_STEP) case POLICY: {subctx->ui_step=UI_STEP; break;} - CASE(POLICY_PROMPT_WARN_UNUSUAL, HANDLE_VOTING_KEY_STEP_WARNING); - CASE(POLICY_SHOW_BEFORE_RESPONSE, HANDLE_VOTING_KEY_STEP_DISPLAY); - CASE(POLICY_ALLOW_WITHOUT_PROMPT, HANDLE_VOTING_KEY_STEP_RESPOND); + CASE(POLICY_PROMPT_WARN_UNUSUAL, HANDLE_VOTE_KEY_STEP_WARNING); + CASE(POLICY_SHOW_BEFORE_RESPONSE, HANDLE_VOTE_KEY_STEP_DISPLAY); + CASE(POLICY_ALLOW_WITHOUT_PROMPT, HANDLE_VOTE_KEY_STEP_RESPOND); #undef CASE default: THROW(ERR_NOT_IMPLEMENTED); } } - signTxGovernanceVotingRegistration_handleVotingKey_ui_runStep(); + signTxCVoteRegistration_handleVoteKey_ui_runStep(); } // ============================== DELEGATION ============================== enum { HANDLE_DELEGATION_STEP_WARNING = 8300, - HANDLE_DELEGATION_STEP_VOTING_KEY, + HANDLE_DELEGATION_STEP_VOTE_KEY, HANDLE_DELEGATION_STEP_WEIGHT, HANDLE_DELEGATION_STEP_RESPOND, HANDLE_DELEGATION_STEP_INVALID, }; -static void signTxGovernanceVotingRegistration_handleDelegation_ui_runStep() +static void signTxCVoteRegistration_handleDelegation_ui_runStep() { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); TRACE("UI step %d", subctx->ui_step); TRACE_STACK_USAGE(); - ui_callback_fn_t* this_fn = signTxGovernanceVotingRegistration_handleDelegation_ui_runStep; + ui_callback_fn_t* this_fn = signTxCVoteRegistration_handleDelegation_ui_runStep; UI_STEP_BEGIN(subctx->ui_step, this_fn); - UI_STEP(HANDLE_VOTING_KEY_STEP_WARNING) { + UI_STEP(HANDLE_VOTE_KEY_STEP_WARNING) { ui_displayPaginatedText( "WARNING:", "unusual vote key", this_fn ); } - UI_STEP(HANDLE_DELEGATION_STEP_VOTING_KEY) { - _displayVotingKey(this_fn); + UI_STEP(HANDLE_DELEGATION_STEP_VOTE_KEY) { + _displayVoteKey(this_fn); } UI_STEP(HANDLE_DELEGATION_STEP_WEIGHT) { ui_displayUint64Screen( @@ -400,11 +400,11 @@ static void signTxGovernanceVotingRegistration_handleDelegation_ui_runStep() } __noinline_due_to_stack__ -static void signTxGovernanceVotingRegistration_handleDelegationAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) +static void signTxCVoteRegistration_handleDelegationAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); { - CHECK_STATE(STATE_GOVERNANCE_VOTING_REGISTRATION_DELEGATIONS); + CHECK_STATE(STATE_CVOTE_REGISTRATION_DELEGATIONS); ASSERT(subctx->currentDelegation < subctx->numDelegations); } { @@ -414,16 +414,16 @@ static void signTxGovernanceVotingRegistration_handleDelegationAPDU(const uint8_ TRACE_BUFFER(wireDataBuffer, wireDataSize); read_view_t view = make_read_view(wireDataBuffer, wireDataBuffer + wireDataSize); - _parseVotingKey(&view); + _parseVoteKey(&view); subctx->stateData.delegation.weight = parse_u4be(&view); - TRACE("Governance voting registration delegation weight:"); + TRACE("CIP-36 voting registration delegation weight:"); TRACE_UINT64(subctx->stateData.delegation.weight); VALIDATE(view_remainingSize(&view) == 0, ERR_INVALID_DATA); } - security_policy_t policy = _determineVotingKeyPolicy(); + security_policy_t policy = _determineVoteKeyPolicy(); TRACE("Policy: %d", (int) policy); ENSURE_NOT_DENIED(policy); @@ -434,20 +434,20 @@ static void signTxGovernanceVotingRegistration_handleDelegationAPDU(const uint8_ switch (subctx->stateData.delegation.type) { case DELEGATION_KEY: { - auxDataHashBuilder_governanceVotingRegistration_addDelegation( + auxDataHashBuilder_cVoteRegistration_addDelegation( auxDataHashBuilder, - subctx->stateData.delegation.votingPubKey, GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH, + subctx->stateData.delegation.votePubKey, CVOTE_PUBLIC_KEY_LENGTH, subctx->stateData.delegation.weight ); break; } case DELEGATION_PATH: { - extendedPublicKey_t extVotingPubKey; - deriveExtendedPublicKey(&subctx->stateData.delegation.votingPubKeyPath, &extVotingPubKey); - auxDataHashBuilder_governanceVotingRegistration_addDelegation( + extendedPublicKey_t extVotePubKey; + deriveExtendedPublicKey(&subctx->stateData.delegation.votePubKeyPath, &extVotePubKey); + auxDataHashBuilder_cVoteRegistration_addDelegation( auxDataHashBuilder, - extVotingPubKey.pubKey, SIZEOF(extVotingPubKey.pubKey), + extVotePubKey.pubKey, SIZEOF(extVotePubKey.pubKey), subctx->stateData.delegation.weight ); break; @@ -463,7 +463,7 @@ static void signTxGovernanceVotingRegistration_handleDelegationAPDU(const uint8_ switch (policy) { #define CASE(POLICY, UI_STEP) case POLICY: {subctx->ui_step=UI_STEP; break;} CASE(POLICY_PROMPT_WARN_UNUSUAL, HANDLE_DELEGATION_STEP_WARNING); - CASE(POLICY_SHOW_BEFORE_RESPONSE, HANDLE_DELEGATION_STEP_VOTING_KEY); + CASE(POLICY_SHOW_BEFORE_RESPONSE, HANDLE_DELEGATION_STEP_VOTE_KEY); CASE(POLICY_ALLOW_WITHOUT_PROMPT, HANDLE_DELEGATION_STEP_RESPOND); #undef CASE default: @@ -471,7 +471,7 @@ static void signTxGovernanceVotingRegistration_handleDelegationAPDU(const uint8_ } } - signTxGovernanceVotingRegistration_handleDelegation_ui_runStep(); + signTxCVoteRegistration_handleDelegation_ui_runStep(); } // ============================== STAKING KEY ============================== @@ -483,12 +483,12 @@ enum { HANDLE_STAKING_KEY_STEP_INVALID, }; -static void signTxGovernanceVotingRegistration_handleStakingKey_ui_runStep() +static void signTxCVoteRegistration_handleStakingKey_ui_runStep() { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); TRACE("UI step %d", subctx->ui_step); TRACE_STACK_USAGE(); - ui_callback_fn_t* this_fn = signTxGovernanceVotingRegistration_handleStakingKey_ui_runStep; + ui_callback_fn_t* this_fn = signTxCVoteRegistration_handleStakingKey_ui_runStep; UI_STEP_BEGIN(subctx->ui_step, this_fn); @@ -513,15 +513,15 @@ static void signTxGovernanceVotingRegistration_handleStakingKey_ui_runStep() } __noinline_due_to_stack__ -static void signTxGovernanceVotingRegistration_handleStakingKeyAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) +static void signTxCVoteRegistration_handleStakingKeyAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) { TRACE_STACK_USAGE(); { // sanity checks - CHECK_STATE(STATE_GOVERNANCE_VOTING_REGISTRATION_STAKING_KEY); + CHECK_STATE(STATE_CVOTE_REGISTRATION_STAKING_KEY); ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); } - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); { explicit_bzero(&subctx->stakingKeyPath, SIZEOF(subctx->stakingKeyPath)); } @@ -540,7 +540,7 @@ static void signTxGovernanceVotingRegistration_handleStakingKeyAPDU(const uint8_ } - security_policy_t policy = policyForGovernanceVotingRegistrationStakingKey( + security_policy_t policy = policyForCVoteRegistrationStakingKey( &subctx->stakingKeyPath ); TRACE("Policy: %d", (int) policy); @@ -549,7 +549,7 @@ static void signTxGovernanceVotingRegistration_handleStakingKeyAPDU(const uint8_ { extendedPublicKey_t extStakingPubKey; deriveExtendedPublicKey(&subctx->stakingKeyPath, &extStakingPubKey); - auxDataHashBuilder_governanceVotingRegistration_addStakingKey( + auxDataHashBuilder_cVoteRegistration_addStakingKey( &AUX_DATA_CTX->auxDataHashBuilder, extStakingPubKey.pubKey, SIZEOF(extStakingPubKey.pubKey) ); } @@ -567,7 +567,7 @@ static void signTxGovernanceVotingRegistration_handleStakingKeyAPDU(const uint8_ } } - signTxGovernanceVotingRegistration_handleStakingKey_ui_runStep(); + signTxCVoteRegistration_handleStakingKey_ui_runStep(); } // ============================== VOTING REWARDS ADDRESS ============================== @@ -607,33 +607,33 @@ static size_t _destinationToAddress( } enum { - HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_WARNING = 8500, - HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_DISPLAY_ADDRESS, - HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_RESPOND, - HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_INVALID + HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_WARNING = 8500, + HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_DISPLAY_ADDRESS, + HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_RESPOND, + HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_INVALID }; __noinline_due_to_stack__ -static void signTxGovernanceVotingRegistration_handleVotingRewardsAddress_ui_runStep() +static void signTxCVoteRegistration_handlePaymentAddress_ui_runStep() { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); TRACE("UI step %d", subctx->ui_step); TRACE_STACK_USAGE(); - ui_callback_fn_t* this_fn = signTxGovernanceVotingRegistration_handleVotingRewardsAddress_ui_runStep; + ui_callback_fn_t* this_fn = signTxCVoteRegistration_handlePaymentAddress_ui_runStep; UI_STEP_BEGIN(subctx->ui_step, this_fn); - UI_STEP(HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_WARNING) { + UI_STEP(HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_WARNING) { ui_displayPaginatedText( "Unusual request", "Proceed with care", this_fn ); } - UI_STEP(HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_DISPLAY_ADDRESS) { + UI_STEP(HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_DISPLAY_ADDRESS) { uint8_t addressBuffer[MAX_ADDRESS_SIZE] = {0}; size_t addressSize = _destinationToAddress( - &subctx->stateData.rewardDestination, + &subctx->stateData.paymentDestination, addressBuffer, SIZEOF(addressBuffer) ); @@ -644,27 +644,27 @@ static void signTxGovernanceVotingRegistration_handleVotingRewardsAddress_ui_run this_fn ); } - UI_STEP(HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_RESPOND) { + UI_STEP(HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_RESPOND) { respondSuccessEmptyMsg(); advanceState(); } - UI_STEP_END(HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_INVALID); + UI_STEP_END(HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_INVALID); } __noinline_due_to_stack__ -static void signTxGovernanceVotingRegistration_handleVotingRewardsAddressAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) +static void signTxCVoteRegistration_handlePaymentAddressAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) { { // safety checks - CHECK_STATE(STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_REWARDS_ADDRESS); + CHECK_STATE(STATE_CVOTE_REGISTRATION_PAYMENT_ADDRESS); ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); } - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); { explicit_bzero( - &subctx->stateData.rewardDestination, - SIZEOF(subctx->stateData.rewardDestination) + &subctx->stateData.paymentDestination, + SIZEOF(subctx->stateData.paymentDestination) ); } { @@ -672,13 +672,13 @@ static void signTxGovernanceVotingRegistration_handleVotingRewardsAddressAPDU(co read_view_t view = make_read_view(wireDataBuffer, wireDataBuffer + wireDataSize); - view_parseDestination(&view, &subctx->stateData.rewardDestination); + view_parseDestination(&view, &subctx->stateData.paymentDestination); VALIDATE(view_remainingSize(&view) == 0, ERR_INVALID_DATA); } - security_policy_t policy = policyForGovernanceVotingRegistrationVotingRewardsDestination( - &subctx->stateData.rewardDestination, + security_policy_t policy = policyForCVoteRegistrationPaymentDestination( + &subctx->stateData.paymentDestination, commonTxData->networkId ); TRACE("Policy: %d", (int) policy); @@ -687,11 +687,11 @@ static void signTxGovernanceVotingRegistration_handleVotingRewardsAddressAPDU(co { uint8_t addressBuffer[MAX_ADDRESS_SIZE] = {0}; size_t addressSize = _destinationToAddress( - &subctx->stateData.rewardDestination, + &subctx->stateData.paymentDestination, addressBuffer, SIZEOF(addressBuffer) ); - auxDataHashBuilder_governanceVotingRegistration_addVotingRewardsAddress( + auxDataHashBuilder_cVoteRegistration_addPaymentAddress( &AUX_DATA_CTX->auxDataHashBuilder, addressBuffer, addressSize ); } @@ -700,15 +700,15 @@ static void signTxGovernanceVotingRegistration_handleVotingRewardsAddressAPDU(co // select UI steps switch (policy) { #define CASE(POLICY, UI_STEP) case POLICY: {subctx->ui_step=UI_STEP; break;} - CASE(POLICY_PROMPT_WARN_UNUSUAL, HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_WARNING); - CASE(POLICY_SHOW_BEFORE_RESPONSE, HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_DISPLAY_ADDRESS); - CASE(POLICY_ALLOW_WITHOUT_PROMPT, HANDLE_VOTING_REWARDS_ADDRESS_PARAMS_STEP_RESPOND); + CASE(POLICY_PROMPT_WARN_UNUSUAL, HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_WARNING); + CASE(POLICY_SHOW_BEFORE_RESPONSE, HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_DISPLAY_ADDRESS); + CASE(POLICY_ALLOW_WITHOUT_PROMPT, HANDLE_PAYMENT_ADDRESS_PARAMS_STEP_RESPOND); #undef CASE default: THROW(ERR_NOT_IMPLEMENTED); } - signTxGovernanceVotingRegistration_handleVotingRewardsAddress_ui_runStep(); + signTxCVoteRegistration_handlePaymentAddress_ui_runStep(); } } @@ -720,12 +720,12 @@ enum { HANDLE_NONCE_STEP_INVALID, }; -static void signTxGovernanceVotingRegistration_handleNonce_ui_runStep() +static void signTxCVoteRegistration_handleNonce_ui_runStep() { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); TRACE("UI step %d", subctx->ui_step); TRACE_STACK_USAGE(); - ui_callback_fn_t* this_fn = signTxGovernanceVotingRegistration_handleNonce_ui_runStep; + ui_callback_fn_t* this_fn = signTxCVoteRegistration_handleNonce_ui_runStep; UI_STEP_BEGIN(subctx->ui_step, this_fn); @@ -744,15 +744,15 @@ static void signTxGovernanceVotingRegistration_handleNonce_ui_runStep() } __noinline_due_to_stack__ -static void signTxGovernanceVotingRegistration_handleNonceAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) +static void signTxCVoteRegistration_handleNonceAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) { { // sanity checks - CHECK_STATE(STATE_GOVERNANCE_VOTING_REGISTRATION_NONCE); + CHECK_STATE(STATE_CVOTE_REGISTRATION_NONCE); ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); } - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); { explicit_bzero(&subctx->stateData, SIZEOF(subctx->stateData)); } @@ -761,16 +761,16 @@ static void signTxGovernanceVotingRegistration_handleNonceAPDU(const uint8_t* wi TRACE_BUFFER(wireDataBuffer, wireDataSize); VALIDATE(wireDataSize == 8, ERR_INVALID_DATA); subctx->stateData.nonce = u8be_read(wireDataBuffer); - TRACE("Governance voting registration nonce:"); + TRACE("CIP-36 voting registration nonce:"); TRACE_UINT64(subctx->stateData.nonce); } - security_policy_t policy = policyForGovernanceVotingRegistrationNonce(); + security_policy_t policy = policyForCVoteRegistrationNonce(); TRACE("Policy: %d", (int) policy); ENSURE_NOT_DENIED(policy); { - auxDataHashBuilder_governanceVotingRegistration_addNonce(&AUX_DATA_CTX->auxDataHashBuilder, subctx->stateData.nonce); + auxDataHashBuilder_cVoteRegistration_addNonce(&AUX_DATA_CTX->auxDataHashBuilder, subctx->stateData.nonce); } { @@ -785,7 +785,7 @@ static void signTxGovernanceVotingRegistration_handleNonceAPDU(const uint8_t* wi } } - signTxGovernanceVotingRegistration_handleNonce_ui_runStep(); + signTxCVoteRegistration_handleNonce_ui_runStep(); } // ============================== VOTING PURPOSE ============================== @@ -796,12 +796,12 @@ enum { HANDLE_VOTING_PURPOSE_STEP_INVALID, }; -static void signTxGovernanceVotingRegistration_handleVotingPurpose_ui_runStep() +static void signTxCVoteRegistration_handleVotingPurpose_ui_runStep() { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); TRACE("UI step %d", subctx->ui_step); TRACE_STACK_USAGE(); - ui_callback_fn_t* this_fn = signTxGovernanceVotingRegistration_handleVotingPurpose_ui_runStep; + ui_callback_fn_t* this_fn = signTxCVoteRegistration_handleVotingPurpose_ui_runStep; UI_STEP_BEGIN(subctx->ui_step, this_fn); @@ -822,14 +822,14 @@ static void signTxGovernanceVotingRegistration_handleVotingPurpose_ui_runStep() #define DEFAULT_VOTING_PURPOSE (0) __noinline_due_to_stack__ -static void signTxGovernanceVotingRegistration_handleVotingPurposeAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) +static void signTxCVoteRegistration_handleVotingPurposeAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) { { - CHECK_STATE(STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_PURPOSE); + CHECK_STATE(STATE_CVOTE_REGISTRATION_VOTING_PURPOSE); ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); } - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); { explicit_bzero(&subctx->stateData, SIZEOF(subctx->stateData)); } @@ -865,12 +865,12 @@ static void signTxGovernanceVotingRegistration_handleVotingPurposeAPDU(const uin return; } - security_policy_t policy = policyForGovernanceVotingRegistrationVotingPurpose(); + security_policy_t policy = policyForCVoteRegistrationVotingPurpose(); TRACE("Policy: %d", (int) policy); ENSURE_NOT_DENIED(policy); { - auxDataHashBuilder_governanceVotingRegistration_addVotingPurpose( + auxDataHashBuilder_cVoteRegistration_addVotingPurpose( &AUX_DATA_CTX->auxDataHashBuilder, subctx->stateData.votingPurpose ); @@ -887,7 +887,7 @@ static void signTxGovernanceVotingRegistration_handleVotingPurposeAPDU(const uin } } - signTxGovernanceVotingRegistration_handleVotingPurpose_ui_runStep(); + signTxCVoteRegistration_handleVotingPurpose_ui_runStep(); } @@ -900,12 +900,12 @@ enum { HANDLE_CONFIRM_STEP_INVALID, }; -static void signTxGovernanceVotingRegistration_handleConfirm_ui_runStep() +static void signTxCVoteRegistration_handleConfirm_ui_runStep() { - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); TRACE("UI step %d", subctx->ui_step); TRACE_STACK_USAGE(); - ui_callback_fn_t* this_fn = signTxGovernanceVotingRegistration_handleConfirm_ui_runStep; + ui_callback_fn_t* this_fn = signTxCVoteRegistration_handleConfirm_ui_runStep; UI_STEP_BEGIN(subctx->ui_step, this_fn); UI_STEP(HANDLE_CONFIRM_STEP_FINAL_CONFIRM) { @@ -938,7 +938,7 @@ static void signTxGovernanceVotingRegistration_handleConfirm_ui_runStep() STATIC_ASSERT(SIZEOF(subctx->auxDataHash) == AUX_DATA_HASH_LENGTH, "Wrong aux data hash length"); memmove(wireResponse.auxDataHash, subctx->auxDataHash, AUX_DATA_HASH_LENGTH); - STATIC_ASSERT(SIZEOF(subctx->stateData.registrationSignature) == ED25519_SIGNATURE_LENGTH, "Wrong governance voting registration signature length"); + STATIC_ASSERT(SIZEOF(subctx->stateData.registrationSignature) == ED25519_SIGNATURE_LENGTH, "Wrong CIP-36 voting registration signature length"); memmove(wireResponse.signature, subctx->stateData.registrationSignature, ED25519_SIGNATURE_LENGTH); io_send_buf(SUCCESS, (uint8_t*) &wireResponse, SIZEOF(wireResponse)); @@ -948,15 +948,15 @@ static void signTxGovernanceVotingRegistration_handleConfirm_ui_runStep() } __noinline_due_to_stack__ -static void signTxGovernanceVotingRegistration_handleConfirmAPDU(const uint8_t* wireDataBuffer MARK_UNUSED, size_t wireDataSize) +static void signTxCVoteRegistration_handleConfirmAPDU(const uint8_t* wireDataBuffer MARK_UNUSED, size_t wireDataSize) { { //sanity checks - CHECK_STATE(STATE_GOVERNANCE_VOTING_REGISTRATION_CONFIRM); + CHECK_STATE(STATE_CVOTE_REGISTRATION_CONFIRM); ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); } - governance_voting_registration_context_t* subctx = accessSubContext(); + cvote_registration_context_t* subctx = accessSubContext(); { explicit_bzero(&subctx->stateData, SIZEOF(subctx->stateData)); } @@ -966,23 +966,23 @@ static void signTxGovernanceVotingRegistration_handleConfirmAPDU(const uint8_t* VALIDATE(wireDataSize == 0, ERR_INVALID_DATA); } - security_policy_t policy = policyForGovernanceVotingRegistrationConfirm(); + security_policy_t policy = policyForCVoteRegistrationConfirm(); TRACE("Policy: %d", (int) policy); ENSURE_NOT_DENIED(policy); { aux_data_hash_builder_t* auxDataHashBuilder = &AUX_DATA_CTX->auxDataHashBuilder; { - uint8_t votingPayloadHashBuffer[GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_HASH_LENGTH] = {0}; - auxDataHashBuilder_governanceVotingRegistration_finalizePayload(auxDataHashBuilder, votingPayloadHashBuffer, AUX_DATA_HASH_LENGTH); - getGovernanceVotingRegistrationSignature( + uint8_t payloadHashBuffer[CVOTE_REGISTRATION_PAYLOAD_HASH_LENGTH] = {0}; + auxDataHashBuilder_cVoteRegistration_finalizePayload(auxDataHashBuilder, payloadHashBuffer, AUX_DATA_HASH_LENGTH); + getCVoteRegistrationSignature( &subctx->stakingKeyPath, - votingPayloadHashBuffer, GOVERNANCE_VOTING_REGISTRATION_PAYLOAD_HASH_LENGTH, + payloadHashBuffer, CVOTE_REGISTRATION_PAYLOAD_HASH_LENGTH, subctx->stateData.registrationSignature, ED25519_SIGNATURE_LENGTH ); } - auxDataHashBuilder_governanceVotingRegistration_addSignature(auxDataHashBuilder, subctx->stateData.registrationSignature, ED25519_SIGNATURE_LENGTH); - auxDataHashBuilder_governanceVotingRegistration_addAuxiliaryScripts(auxDataHashBuilder); + auxDataHashBuilder_cVoteRegistration_addSignature(auxDataHashBuilder, subctx->stateData.registrationSignature, ED25519_SIGNATURE_LENGTH); + auxDataHashBuilder_cVoteRegistration_addAuxiliaryScripts(auxDataHashBuilder); auxDataHashBuilder_finalize(auxDataHashBuilder, subctx->auxDataHash, AUX_DATA_HASH_LENGTH); } @@ -999,7 +999,7 @@ static void signTxGovernanceVotingRegistration_handleConfirmAPDU(const uint8_t* } } - signTxGovernanceVotingRegistration_handleConfirm_ui_runStep(); + signTxCVoteRegistration_handleConfirm_ui_runStep(); } @@ -1007,23 +1007,23 @@ static void signTxGovernanceVotingRegistration_handleConfirmAPDU(const uint8_t* enum { APDU_INSTRUCTION_INIT = 0x36, - APDU_INSTRUCTION_VOTING_KEY = 0x30, + APDU_INSTRUCTION_VOTE_KEY = 0x30, APDU_INSTRUCTION_DELEGATION = 0x37, APDU_INSTRUCTION_STAKING_KEY = 0x31, - APDU_INSTRUCTION_VOTING_REWARDS_ADDRESS = 0x32, + APDU_INSTRUCTION_PAYMENT_ADDRESS = 0x32, APDU_INSTRUCTION_NONCE = 0x33, APDU_INSTRUCTION_VOTING_PURPOSE = 0x35, APDU_INSTRUCTION_CONFIRM = 0x34 }; -bool signTxGovernanceVotingRegistration_isValidInstruction(uint8_t p2) +bool signTxCVoteRegistration_isValidInstruction(uint8_t p2) { switch (p2) { case APDU_INSTRUCTION_INIT: - case APDU_INSTRUCTION_VOTING_KEY: + case APDU_INSTRUCTION_VOTE_KEY: case APDU_INSTRUCTION_DELEGATION: case APDU_INSTRUCTION_STAKING_KEY: - case APDU_INSTRUCTION_VOTING_REWARDS_ADDRESS: + case APDU_INSTRUCTION_PAYMENT_ADDRESS: case APDU_INSTRUCTION_NONCE: case APDU_INSTRUCTION_VOTING_PURPOSE: case APDU_INSTRUCTION_CONFIRM: @@ -1034,41 +1034,41 @@ bool signTxGovernanceVotingRegistration_isValidInstruction(uint8_t p2) } } -void signTxGovernanceVotingRegistration_handleAPDU(uint8_t p2, const uint8_t* wireDataBuffer, size_t wireDataSize) +void signTxCVoteRegistration_handleAPDU(uint8_t p2, const uint8_t* wireDataBuffer, size_t wireDataSize) { ASSERT(wireDataSize < BUFFER_SIZE_PARANOIA); switch (p2) { case APDU_INSTRUCTION_INIT: - signTxGovernanceVotingRegistration_handleInitAPDU(wireDataBuffer, wireDataSize); + signTxCVoteRegistration_handleInitAPDU(wireDataBuffer, wireDataSize); break; - case APDU_INSTRUCTION_VOTING_KEY: - signTxGovernanceVotingRegistration_handleVotingKeyAPDU(wireDataBuffer, wireDataSize); + case APDU_INSTRUCTION_VOTE_KEY: + signTxCVoteRegistration_handleVoteKeyAPDU(wireDataBuffer, wireDataSize); break; case APDU_INSTRUCTION_DELEGATION: - signTxGovernanceVotingRegistration_handleDelegationAPDU(wireDataBuffer, wireDataSize); + signTxCVoteRegistration_handleDelegationAPDU(wireDataBuffer, wireDataSize); break; case APDU_INSTRUCTION_STAKING_KEY: - signTxGovernanceVotingRegistration_handleStakingKeyAPDU(wireDataBuffer, wireDataSize); + signTxCVoteRegistration_handleStakingKeyAPDU(wireDataBuffer, wireDataSize); break; - case APDU_INSTRUCTION_VOTING_REWARDS_ADDRESS: - signTxGovernanceVotingRegistration_handleVotingRewardsAddressAPDU(wireDataBuffer, wireDataSize); + case APDU_INSTRUCTION_PAYMENT_ADDRESS: + signTxCVoteRegistration_handlePaymentAddressAPDU(wireDataBuffer, wireDataSize); break; case APDU_INSTRUCTION_NONCE: - signTxGovernanceVotingRegistration_handleNonceAPDU(wireDataBuffer, wireDataSize); + signTxCVoteRegistration_handleNonceAPDU(wireDataBuffer, wireDataSize); break; case APDU_INSTRUCTION_VOTING_PURPOSE: - signTxGovernanceVotingRegistration_handleVotingPurposeAPDU(wireDataBuffer, wireDataSize); + signTxCVoteRegistration_handleVotingPurposeAPDU(wireDataBuffer, wireDataSize); break; case APDU_INSTRUCTION_CONFIRM: - signTxGovernanceVotingRegistration_handleConfirmAPDU(wireDataBuffer, wireDataSize); + signTxCVoteRegistration_handleConfirmAPDU(wireDataBuffer, wireDataSize); break; default: diff --git a/src/signTxCVoteRegistration.h b/src/signTxCVoteRegistration.h new file mode 100644 index 00000000..1d96dc5d --- /dev/null +++ b/src/signTxCVoteRegistration.h @@ -0,0 +1,70 @@ +#ifndef H_CARDANO_APP_SIGN_TX_CVOTE_REGISTRATION +#define H_CARDANO_APP_SIGN_TX_CVOTE_REGISTRATION + +#include "common.h" +#include "cardano.h" +#include "auxDataHashBuilder.h" +#include "txHashBuilder.h" +#include "addressUtilsShelley.h" + + +#define CVOTE_PUBLIC_KEY_LENGTH 32 + +// SIGN_STAGE_AUX_DATA = 24 +// AUX_DATA_TYPE_CVOTE_REGISTRATION = 1 +typedef enum { + STATE_CVOTE_REGISTRATION_INIT = 2410, + STATE_CVOTE_REGISTRATION_VOTE_KEY = 2411, + STATE_CVOTE_REGISTRATION_DELEGATIONS = 2412, + STATE_CVOTE_REGISTRATION_STAKING_KEY = 2413, + STATE_CVOTE_REGISTRATION_PAYMENT_ADDRESS = 2414, + STATE_CVOTE_REGISTRATION_NONCE = 2415, + STATE_CVOTE_REGISTRATION_VOTING_PURPOSE = 2416, + STATE_CVOTE_REGISTRATION_CONFIRM = 2417, + STATE_CVOTE_REGISTRATION_FINISHED = 2418 +} sign_tx_cvote_registration_state_t; + +typedef enum { + DELEGATION_KEY = 1, + DELEGATION_PATH = 2 +} cvote_delegation_type_t; + +typedef struct { + sign_tx_cvote_registration_state_t state; + int ui_step; + + cvote_registration_format_t format; + uint16_t numDelegations; // if 0, only a single key expected, no delegations + uint16_t currentDelegation; + /* + * Staking key path kept outside of stateData to produce the CIP-36 voting registration + * signature at the end of the flow without re-requesting the staking key path + * (with the undesired side-effect of allowing signing with a different key than included + * in the registration payload) + */ + bip44_path_t stakingKeyPath; + + uint8_t auxDataHash[AUX_DATA_HASH_LENGTH]; + + union { + struct { + cvote_delegation_type_t type; + bip44_path_t votePubKeyPath; + uint8_t votePubKey[CVOTE_PUBLIC_KEY_LENGTH]; + uint32_t weight; + } delegation; + tx_output_destination_storage_t paymentDestination; + uint64_t nonce; + uint64_t votingPurpose; + uint8_t registrationSignature[ED25519_SIGNATURE_LENGTH]; + } stateData; +} cvote_registration_context_t; + +void signTxCVoteRegistration_init(); + +bool signTxCVoteRegistration_isValidInstruction(uint8_t p2); +void signTxCVoteRegistration_handleAPDU(uint8_t p2, const uint8_t* wireDataBuffer, size_t wireDataSize); + +bool signTxCVoteRegistration_isFinished(); + +#endif // H_CARDANO_APP_SIGN_TX_CVOTE_REGISTRATION diff --git a/src/signTxGovernanceVotingRegistration.h b/src/signTxGovernanceVotingRegistration.h deleted file mode 100644 index bd304df6..00000000 --- a/src/signTxGovernanceVotingRegistration.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef H_CARDANO_APP_SIGN_TX_GOVERNANCE_VOTING_REGISTRATION -#define H_CARDANO_APP_SIGN_TX_GOVERNANCE_VOTING_REGISTRATION - -#include "common.h" -#include "cardano.h" -#include "auxDataHashBuilder.h" -#include "txHashBuilder.h" -#include "addressUtilsShelley.h" - - -#define GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH 32 - -// SIGN_STAGE_AUX_DATA = 24 -// AUX_DATA_TYPE_CIP36_REGISTRATION = 1 -typedef enum { - STATE_GOVERNANCE_VOTING_REGISTRATION_INIT = 2410, - STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_KEY = 2411, - STATE_GOVERNANCE_VOTING_REGISTRATION_DELEGATIONS = 2412, - STATE_GOVERNANCE_VOTING_REGISTRATION_STAKING_KEY = 2413, - STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_REWARDS_ADDRESS = 2414, - STATE_GOVERNANCE_VOTING_REGISTRATION_NONCE = 2415, - STATE_GOVERNANCE_VOTING_REGISTRATION_VOTING_PURPOSE = 2416, - STATE_GOVERNANCE_VOTING_REGISTRATION_CONFIRM = 2417, - STATE_GOVERNANCE_VOTING_REGISTRATION_FINISHED = 2418 -} sign_tx_governance_voting_registration_state_t; - -typedef enum { - DELEGATION_KEY = 1, - DELEGATION_PATH = 2 -} governance_voting_delegation_type_t; - -typedef struct { - sign_tx_governance_voting_registration_state_t state; - int ui_step; - - governance_voting_registration_format_t format; - uint16_t numDelegations; // if 0, only a single key expected, no delegations - uint16_t currentDelegation; - /* - * Staking key path kept outside of stateData to produce the governance voting registration - * signature at the end of the flow without re-requesting the staking key path - * (with the undesired side-effect of allowing signing with a different key than included - * in the registration payload) - */ - bip44_path_t stakingKeyPath; - - uint8_t auxDataHash[AUX_DATA_HASH_LENGTH]; - - union { - struct { - governance_voting_delegation_type_t type; - bip44_path_t votingPubKeyPath; - uint8_t votingPubKey[GOVERNANCE_VOTING_PUBLIC_KEY_LENGTH]; - uint32_t weight; - } delegation; - tx_output_destination_storage_t rewardDestination; - uint64_t nonce; - uint64_t votingPurpose; - uint8_t registrationSignature[ED25519_SIGNATURE_LENGTH]; - } stateData; -} governance_voting_registration_context_t; - -void signTxGovernanceVotingRegistration_init(); - -bool signTxGovernanceVotingRegistration_isValidInstruction(uint8_t p2); -void signTxGovernanceVotingRegistration_handleAPDU(uint8_t p2, const uint8_t* wireDataBuffer, size_t wireDataSize); - -bool signTxGovernanceVotingRegistration_isFinished(); - -#endif // H_CARDANO_APP_SIGN_TX_GOVERNANCE_VOTING_REGISTRATION diff --git a/src/signTxMint.c b/src/signTxMint.c index c996b7d8..cbd3b325 100644 --- a/src/signTxMint.c +++ b/src/signTxMint.c @@ -202,7 +202,7 @@ static void signTxMint_handleAssetGroupAPDU(const uint8_t* wireDataBuffer, size_ } { - // add tokengroup to tx + // add token group to tx TRACE("Adding token group hash to tx hash"); txHashBuilder_addMint_tokenGroup( &BODY_CTX->txHashBuilder, @@ -312,7 +312,7 @@ static void signTxMint_handleTokenAPDU(const uint8_t* wireDataBuffer, size_t wir } { - // add tokengroup to tx + // add token group to tx TRACE("Adding token group hash to tx hash"); txHashBuilder_addMint_token( &BODY_CTX->txHashBuilder, diff --git a/src/signTxOutput.c b/src/signTxOutput.c index 6f09ae2c..7ebb10f6 100644 --- a/src/signTxOutput.c +++ b/src/signTxOutput.c @@ -571,7 +571,7 @@ static void handleCollateralOutput_addressBytes() .includeRefScript = subctx->includeRefScript, }; - // TODO maybe restric to specific address types? we don't support datum in coll ret outputs + // TODO maybe restrict to specific address types? we don't support datum in coll ret outputs security_policy_t policy = policyForSignTxCollateralOutputAddressBytes( &output, commonTxData->txSigningMode, @@ -753,7 +753,7 @@ static void handleAssetGroupAPDU(const uint8_t* wireDataBuffer, size_t wireDataS VALIDATE(view_remainingSize(&view) == 0, ERR_INVALID_DATA); } { - // add tokengroup to tx + // add token group to tx TRACE("Adding token group hash to tx hash"); switch (ctx->stage) { @@ -871,7 +871,7 @@ static void handleTokenAPDU(const uint8_t* wireDataBuffer, size_t wireDataSize) VALIDATE(view_remainingSize(&view) == 0, ERR_INVALID_DATA); } { - // add tokengroup to tx + // add token group to tx TRACE("Adding token group hash to tx hash"); switch (ctx->stage) { diff --git a/src/signTxPoolRegistration.c b/src/signTxPoolRegistration.c index f641e7f5..78635b37 100644 --- a/src/signTxPoolRegistration.c +++ b/src/signTxPoolRegistration.c @@ -1276,7 +1276,7 @@ static void signTxPoolRegistration_handlePoolMetadataAPDU(const uint8_t* wireDat { md->urlSize = view_remainingSize(&view); VALIDATE(md->urlSize <= POOL_METADATA_URL_LENGTH_MAX, ERR_INVALID_DATA); - STATIC_ASSERT(SIZEOF(md->url) >= POOL_METADATA_URL_LENGTH_MAX, "wrong pool metada url size"); + STATIC_ASSERT(SIZEOF(md->url) >= POOL_METADATA_URL_LENGTH_MAX, "wrong pool metadata url size"); view_parseBuffer(md->url, &view, md->urlSize); // whitespace not allowed @@ -1334,7 +1334,7 @@ static void signTxPoolRegistration_handleConfirm_ui_runStep() UI_STEP_BEGIN(subctx->ui_step, this_fn); - // we display potencially suspicious facts about the certificate + // we display potentially suspicious facts about the certificate // that have not been explicitly shown to the user before: // missing owners or relays UI_STEP(HANDLE_CONFIRM_STEP_FINAL_NO_OWNERS) { diff --git a/src/signTxUtils.c b/src/signTxUtils.c index f879be47..daca4896 100644 --- a/src/signTxUtils.c +++ b/src/signTxUtils.c @@ -46,7 +46,8 @@ bool violatesSingleAccountOrStoreIt(const bip44_path_t* path) return false; } -void view_parseDestination(read_view_t* view, tx_output_destination_storage_t* destination) { +void view_parseDestination(read_view_t* view, tx_output_destination_storage_t* destination) +{ destination->type = parse_u1be(view); TRACE("Destination type %d", (int) destination->type); diff --git a/src/state.h b/src/state.h index 1d71bb90..8ca7f18a 100644 --- a/src/state.h +++ b/src/state.h @@ -7,7 +7,7 @@ #include "deriveNativeScriptHash.h" #include "signTx.h" #include "signOpCert.h" -#include "signGovernanceVote.h" +#include "signCVote.h" typedef union { @@ -17,7 +17,7 @@ typedef union { ins_derive_native_script_hash_context_t deriveNativeScriptHashContext; ins_sign_tx_context_t signTxContext; ins_sign_op_cert_context_t signOpCertContext; - ins_sign_governance_vote_context_t signGovernanceVoteContext; + ins_sign_cvote_context_t signCVoteContext; } instructionState_t; // Note(instructions are uint8_t but we have a special INS_NONE value diff --git a/src/textUtils.c b/src/textUtils.c index abbd1bf4..1eac4c93 100644 --- a/src/textUtils.c +++ b/src/textUtils.c @@ -301,6 +301,7 @@ bool str_isAllowedDnsName(const uint8_t* buffer, size_t bufferSize) #ifdef DEVEL +/* cspell:disable-next-line */ // converts a text to bytes (suitable for CBORization) and validates if chars are allowed size_t str_textToBuffer(const char* text, uint8_t* buffer, size_t bufferSize) { diff --git a/src/tokens_test.c b/src/tokens_test.c index 731e7773..c78be646 100644 --- a/src/tokens_test.c +++ b/src/tokens_test.c @@ -72,15 +72,15 @@ typedef struct { char expectedMint[50]; } token_testcase_t; -const token_testcase_t tokenTestcases[] = { +const token_testcase_t tokenTestCases[] = { { { 0x94, 0xcb, 0xb4, 0xfc, 0xbc, 0xaa, 0x29, 0x75, 0x77, 0x9f, 0x27, 0x3b, 0x26, 0x3e, 0xb3, 0xb5, 0xf2, 0x4a, 0x99, 0x51, 0xe4, 0x46, 0xd6, 0xdc, 0x4c, 0x13, 0x58, 0x64 }, { 0x52, 0x45, 0x56, 0x55 }, 4, 234, - "0.00000234 REVU", + "0.00000234 REVU", // cspell:disable-line -234, - "-0.00000234 REVU" + "-0.00000234 REVU" // cspell:disable-line }, { // no decimal places in our table @@ -96,26 +96,26 @@ const token_testcase_t tokenTestcases[] = { void test_decimalPlaces() { - for (size_t i = 0; i < ARRAY_LEN(tokenTestcases); i++) { + for (size_t i = 0; i < ARRAY_LEN(tokenTestCases); i++) { char tokenAmountStr[60]; token_group_t group; - memcpy(group.policyId, tokenTestcases[i].policyId, MINTING_POLICY_ID_SIZE); + memcpy(group.policyId, tokenTestCases[i].policyId, MINTING_POLICY_ID_SIZE); str_formatTokenAmountOutput( &group, - tokenTestcases[i].assetNameBytes, tokenTestcases[i].assetNameSize, - tokenTestcases[i].amountOutput, + tokenTestCases[i].assetNameBytes, tokenTestCases[i].assetNameSize, + tokenTestCases[i].amountOutput, tokenAmountStr, SIZEOF(tokenAmountStr) ); - EXPECT_EQ(strcmp(tokenAmountStr, tokenTestcases[i].expectedOutput), 0); + EXPECT_EQ(strcmp(tokenAmountStr, tokenTestCases[i].expectedOutput), 0); str_formatTokenAmountMint( &group, - tokenTestcases[i].assetNameBytes, tokenTestcases[i].assetNameSize, - tokenTestcases[i].amountMint, + tokenTestCases[i].assetNameBytes, tokenTestCases[i].assetNameSize, + tokenTestCases[i].amountMint, tokenAmountStr, SIZEOF(tokenAmountStr) ); - EXPECT_EQ(strcmp(tokenAmountStr, tokenTestcases[i].expectedMint), 0); + EXPECT_EQ(strcmp(tokenAmountStr, tokenTestCases[i].expectedMint), 0); } } diff --git a/src/txHashBuilder.c b/src/txHashBuilder.c index 0dc11251..23d198d3 100644 --- a/src/txHashBuilder.c +++ b/src/txHashBuilder.c @@ -432,7 +432,7 @@ static void addTokenGroup( { // Bytes[policyId] // Map(numTokens)[ - // // entries added later { * asset_name => auint } + // // entries added later { * asset_name => uint } // ] { BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, policyIdSize); @@ -474,7 +474,7 @@ static void addToken( ASSERT(assetNameSize <= ASSET_NAME_SIZE_MAX); { // add a map entry: - // Bytes[assetname] + // Bytes[asset_name] // Unsigned[Amount] { BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, assetNameSize); diff --git a/src/txHashBuilder_test.c b/src/txHashBuilder_test.c index 5b76abca..1a0f0a8a 100644 --- a/src/txHashBuilder_test.c +++ b/src/txHashBuilder_test.c @@ -349,7 +349,7 @@ static void addPoolRegistrationCertificate(tx_hash_builder_t* builder) pool_relay_t relay1; relay1.format = 1; relay1.port.isNull = true; - // a valid DNS AAAA record, since dnsName actually is suppposed to be an A or AAAA record + // a valid DNS AAAA record, since dnsName actually is supposed to be an A or AAAA record const char* dnsName = "AAAA 2400:cb00:2049:1::a29f:1804"; relay1.dnsNameSize = str_textToBuffer(dnsName, relay1.dnsName, SIZEOF(relay1.dnsName)); txHashBuilder_addPoolRegistrationCertificate_addRelay(builder, &relay1); @@ -499,6 +499,7 @@ void run_txHashBuilder_test() } // ? 7 : auxiliary_data_hash { + /* cspell:disable-next-line */ const char auxDataHashHex[] = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; uint8_t tmp[AUX_DATA_HASH_LENGTH] = {0}; size_t tmpSize = decode_hex(auxDataHashHex, tmp, SIZEOF(tmp)); diff --git a/tokenRegistry/convert.py b/tokenRegistry/convert.py index 8dc64a56..861c914b 100644 --- a/tokenRegistry/convert.py +++ b/tokenRegistry/convert.py @@ -6,7 +6,7 @@ # WARNING --- make sure that: # 1. token tickers are meaningful and none is "(unknown decimals)" # 2. buffers (e.g. tokenAmountStr) are big enough to hold the tickers -filename = "top100JsonList.json" +filename = "tokenList.json" registry = json.load(open(filename)) diff --git a/tokenRegistry/top100JsonList.json b/tokenRegistry/tokenList.json similarity index 98% rename from tokenRegistry/top100JsonList.json rename to tokenRegistry/tokenList.json index 2ebc8d6c..1fd16b5a 100644 --- a/tokenRegistry/top100JsonList.json +++ b/tokenRegistry/tokenList.json @@ -598,5 +598,17 @@ "name": "Indigo DAO Token", "ticker": "INDY", "decimals": 6 + }, + { + "assetSubject": "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344", + "name": "Djed USD", + "ticker": "DJED", + "decimals": 6 + }, + { + "assetSubject": "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069555344", + "name": "iUSD", + "ticker": "iUSD", + "decimals": 6 } ] diff --git a/tokenRegistry/token_data.c b/tokenRegistry/token_data.c index 2e4b6f95..34e208fe 100644 --- a/tokenRegistry/token_data.c +++ b/tokenRegistry/token_data.c @@ -97,4 +97,6 @@ { { 0x04, 0x93, 0xf4, 0x95, 0x30, 0x89, 0x8e, 0x3d, 0xfe, 0x7d, 0xc0, 0x94, 0x3d, 0x19, 0xbc, 0x1b, 0xdc, 0xb3, 0x6e, 0x10 }, 6, "C3" }, { { 0x83, 0x45, 0xbc, 0xd3, 0x13, 0x72, 0x01, 0x6d, 0x70, 0xb5, 0xb3, 0xd3, 0x3f, 0x93, 0x79, 0x9b, 0x26, 0xc4, 0xb2, 0x32 }, 4, "CLAY" }, { { 0x73, 0x88, 0x43, 0x9d, 0x27, 0xe1, 0x63, 0xeb, 0x8b, 0xd6, 0xe4, 0xff, 0x68, 0x43, 0xc8, 0xe5, 0x6b, 0xa0, 0xeb, 0x2d }, 8, "AGIX" }, -{ { 0xe1, 0xf1, 0xde, 0x48, 0x36, 0xc3, 0xed, 0xba, 0xb3, 0xee, 0x34, 0xda, 0x74, 0x96, 0x95, 0xf9, 0x83, 0x71, 0xe0, 0xff }, 6, "INDY" } +{ { 0xe1, 0xf1, 0xde, 0x48, 0x36, 0xc3, 0xed, 0xba, 0xb3, 0xee, 0x34, 0xda, 0x74, 0x96, 0x95, 0xf9, 0x83, 0x71, 0xe0, 0xff }, 6, "INDY" }, +{ { 0xa2, 0x62, 0x4d, 0xda, 0x5d, 0x49, 0x8d, 0x9e, 0x4d, 0x94, 0x42, 0xdb, 0xfa, 0x55, 0x14, 0x04, 0x0e, 0xb2, 0x16, 0xc7 }, 6, "DJED" }, +{ { 0x1e, 0xe2, 0x7e, 0xdf, 0xf4, 0x99, 0xcf, 0x88, 0xf0, 0x3a, 0x1e, 0xbc, 0x4f, 0x22, 0x6f, 0x4a, 0x4c, 0x07, 0x71, 0xde }, 6, "iUSD" }