Skip to content

Commit

Permalink
Rename metadata to aux data stage 2
Browse files Browse the repository at this point in the history
  • Loading branch information
refi93 committed Apr 6, 2021
1 parent cd292bf commit a3b45ab
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 110 deletions.
6 changes: 3 additions & 3 deletions src/cardano.h
Expand Up @@ -140,8 +140,8 @@ typedef struct {
} pool_relay_t;

typedef enum {
METADATA_TYPE_ARBITRARY_HASH = 0,
METADATA_TYPE_CATALYST_VOTING_KEY_REGISTRATION = 1,
} metadata_type_t;
AUX_DATA_TYPE_ARBITRARY_HASH = 0,
AUX_DATA_TYPE_CATALYST_VOTING_KEY_REGISTRATION = 1,
} AUX_DATA_TYPE_t;

#endif // H_CARDANO_APP_CARDANO
4 changes: 2 additions & 2 deletions src/securityPolicy.c
Expand Up @@ -642,7 +642,7 @@ security_policy_t policyForSignTxWitness(
DENY(); // should not be reached
}

security_policy_t policyForSignTxMetadata()
security_policy_t policyForSignTxAuxData()
{
SHOW();
}
Expand Down Expand Up @@ -678,7 +678,7 @@ security_policy_t policyForSignOpCert(const bip44_path_t* poolColdKeyPathSpec)
DENY(); // should not be reached
}

security_policy_t policyForSignTxMetadataCatalystVotingRewardsAddressParams(
security_policy_t policyForCatalystVotingRewardsAddressParams(
const addressParams_t* params,
const uint8_t networkId
)
Expand Down
4 changes: 2 additions & 2 deletions src/securityPolicy.h
Expand Up @@ -91,7 +91,7 @@ security_policy_t policyForSignTxStakePoolRegistrationConfirm(

security_policy_t policyForSignTxWithdrawal();

security_policy_t policyForSignTxMetadata();
security_policy_t policyForSignTxAuxData();

security_policy_t policyForSignTxValidityIntervalStart();

Expand All @@ -104,7 +104,7 @@ security_policy_t policyForSignTxConfirm();

security_policy_t policyForSignOpCert(const bip44_path_t* poolColdKeyPathSpec);

security_policy_t policyForSignTxMetadataCatalystVotingRewardsAddressParams(
security_policy_t policyForCatalystVotingRewardsAddressParams(
const addressParams_t* params,
const uint8_t networkId
);
Expand Down
52 changes: 26 additions & 26 deletions src/signTx.c
Expand Up @@ -91,17 +91,17 @@ static inline void advanceStage()
// we should have received all withdrawals
ASSERT(ctx->currentWithdrawal == ctx->numWithdrawals);

ctx->stage = SIGN_STAGE_METADATA;
ctx->stage = SIGN_STAGE_AUX_DATA;

if (ctx->includeMetadata) {
if (ctx->includeAuxData) {
break;
}

// intentional fallthrough

case SIGN_STAGE_METADATA:
if (ctx->includeMetadata) {
ASSERT(ctx->metadataReceived);
case SIGN_STAGE_AUX_DATA:
if (ctx->includeAuxData) {
ASSERT(ctx->auxDataReceived);
}

ctx->stage = SIGN_STAGE_VALIDITY_INTERVAL;
Expand Down Expand Up @@ -202,10 +202,10 @@ static inline void checkForFinishedSubmachines()
break;

case SIGN_STAGE_AUX_DATA_CATALYST_VOTING_SUBMACHINE:
if (signTxMetadataCatalystVoting_isFinished()) {
if (signTxAuxDataCatalystVoting_isFinished()) {
TRACE();
ctx->stage = SIGN_STAGE_METADATA;
ctx->metadataReceived = true;
ctx->stage = SIGN_STAGE_AUX_DATA;
ctx->auxDataReceived = true;

advanceStage();
}
Expand Down Expand Up @@ -288,7 +288,7 @@ static void signTx_handleInitAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t wi
// initialization
ctx->feeReceived = false;
ctx->ttlReceived = false;
ctx->metadataReceived = false;
ctx->auxDataReceived = false;
ctx->validityIntervalStartReceived = false;

ctx->currentInput = 0;
Expand All @@ -308,7 +308,7 @@ static void signTx_handleInitAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t wi
uint8_t protocolMagic[4];

uint8_t includeTtl;
uint8_t includeMetadata;
uint8_t includeAuxData;
uint8_t includeValidityIntervalStart;
uint8_t signTxUsecase;

Expand All @@ -333,8 +333,8 @@ static void signTx_handleInitAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t wi
ctx->includeTtl = signTx_parseIncluded(wireHeader->includeTtl);
TRACE("Include ttl %d", ctx->includeTtl);

ctx->includeMetadata = signTx_parseIncluded(wireHeader->includeMetadata);
TRACE("Include metadata %d", ctx->includeMetadata);
ctx->includeAuxData = signTx_parseIncluded(wireHeader->includeAuxData);
TRACE("Include auxiliary data %d", ctx->includeAuxData);

ctx->includeValidityIntervalStart = signTx_parseIncluded(wireHeader->includeValidityIntervalStart);
TRACE("Include validity interval start %d", ctx->includeValidityIntervalStart);
Expand Down Expand Up @@ -443,7 +443,7 @@ static void signTx_handleInitAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t wi
ctx->includeTtl,
ctx->numCertificates,
ctx->numWithdrawals,
ctx->includeMetadata,
ctx->includeAuxData,
ctx->includeValidityIntervalStart
);

Expand Down Expand Up @@ -1272,7 +1272,7 @@ static void signTx_handleAuxDataCatalystVoting_ui_runStep()
}
UI_STEP(HANDLE_AUX_DATA_CATALYST_VOTING_STEP_RESPOND) {
respondSuccessEmptyMsg();
signTxMetadataCatalystVoting_init();
signTxAuxDataCatalystVoting_init();
ctx->stage = SIGN_STAGE_AUX_DATA_CATALYST_VOTING_SUBMACHINE;
}
UI_STEP_END(HANDLE_AUX_DATA_CATALYST_VOTING_STEP_INVALID);
Expand All @@ -1283,19 +1283,19 @@ static void signTx_handleAuxDataAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t
{
{
TRACE_STACK_USAGE();
ASSERT(ctx->includeMetadata == true);
ASSERT(ctx->includeAuxData == true);

// delegate to state sub-machine for stake pool registration certificate data
if (signTxMetadataCatalystVoting_isValidInstruction(p2)) {
if (signTxAuxDataCatalystVoting_isValidInstruction(p2)) {
TRACE();
CHECK_STAGE(SIGN_STAGE_AUX_DATA_CATALYST_VOTING_SUBMACHINE);

TRACE_STACK_USAGE();

signTxMetadataCatalystVoting_handleAPDU(p2, wireDataBuffer, wireDataSize);
signTxAuxDataCatalystVoting_handleAPDU(p2, wireDataBuffer, wireDataSize);
return;
} else {
CHECK_STAGE(SIGN_STAGE_METADATA);
CHECK_STAGE(SIGN_STAGE_AUX_DATA);
}
}

Expand All @@ -1308,14 +1308,14 @@ static void signTx_handleAuxDataAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t
ctx->stageData.auxData.type = parse_u1be(&view);

switch (ctx->stageData.auxData.type) {
case METADATA_TYPE_ARBITRARY_HASH:
case AUX_DATA_TYPE_ARBITRARY_HASH:
// parse data
VALIDATE(view_remainingSize(&view) == METADATA_HASH_LENGTH, ERR_INVALID_DATA);
STATIC_ASSERT(SIZEOF(ctx->stageData.auxData.auxDataHash) == METADATA_HASH_LENGTH, "wrong metadata hash length");
view_memmove(ctx->stageData.auxData.auxDataHash, &view, METADATA_HASH_LENGTH);
ctx->metadataReceived = true;
ctx->auxDataReceived = true;
break;
case METADATA_TYPE_CATALYST_VOTING_KEY_REGISTRATION:
case AUX_DATA_TYPE_CATALYST_VOTING_KEY_REGISTRATION:
break;
default:
THROW(ERR_INVALID_DATA);
Expand All @@ -1325,12 +1325,12 @@ static void signTx_handleAuxDataAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t
}


security_policy_t policy = policyForSignTxMetadata();
security_policy_t policy = policyForSignTxAuxData();
TRACE("Policy: %d", (int) policy);
ENSURE_NOT_DENIED(policy);

switch (ctx->stageData.auxData.type) {
case METADATA_TYPE_ARBITRARY_HASH: {
case AUX_DATA_TYPE_ARBITRARY_HASH: {
// select UI step
switch (policy) {
#define CASE(POLICY, UI_STEP) case POLICY: {ctx->ui_step=UI_STEP; break;}
Expand All @@ -1340,17 +1340,17 @@ static void signTx_handleAuxDataAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t
default:
THROW(ERR_NOT_IMPLEMENTED);
}
// add metadata to tx
// add auxiliary data to tx
TRACE("Adding auxiliary data hash to tx hash");
txHashBuilder_addMetadata(
txHashBuilder_addAuxData(
&ctx->txHashBuilder,
ctx->stageData.auxData.auxDataHash, SIZEOF(ctx->stageData.auxData.auxDataHash)
);
TRACE();
signTx_handleAuxDataArbitraryHash_ui_runStep();
break;
}
case METADATA_TYPE_CATALYST_VOTING_KEY_REGISTRATION:
case AUX_DATA_TYPE_CATALYST_VOTING_KEY_REGISTRATION:
// select UI step
switch (policy) {
#define CASE(POLICY, UI_STEP) case POLICY: {ctx->ui_step=UI_STEP; break;}
Expand Down
12 changes: 6 additions & 6 deletions src/signTx.h
Expand Up @@ -9,7 +9,7 @@
#include "addressUtilsShelley.h"
#include "signTxOutput.h"
#include "signTxPoolRegistration.h"
#include "signTxMetadataCatalystVoting.h"
#include "signTxAuxDataCatalystVoting.h"

// the use case significantly affects restrictions on tx being signed
typedef enum {
Expand All @@ -29,7 +29,7 @@ typedef enum {
SIGN_STAGE_CERTIFICATES = 29,
SIGN_STAGE_CERTIFICATES_POOL = 30, // pool registration certificate sub-machine
SIGN_STAGE_WITHDRAWALS = 31,
SIGN_STAGE_METADATA = 32,
SIGN_STAGE_AUX_DATA = 32,
SIGN_STAGE_AUX_DATA_CATALYST_VOTING_SUBMACHINE = 33,
SIGN_STAGE_VALIDITY_INTERVAL = 34,
SIGN_STAGE_CONFIRM = 35,
Expand Down Expand Up @@ -66,7 +66,7 @@ typedef struct {
} sign_tx_withdrawal_data_t;

typedef struct {
metadata_type_t type;
AUX_DATA_TYPE_t type;

// only for arbitrary metadata hash
uint8_t auxDataHash[METADATA_HASH_LENGTH];
Expand All @@ -85,7 +85,7 @@ typedef struct {
bool includeTtl;
uint16_t numCertificates;
uint16_t numWithdrawals; // reward withdrawals
bool includeMetadata;
bool includeAuxData;
bool includeValidityIntervalStart;
uint16_t numWitnesses;

Expand All @@ -97,7 +97,7 @@ typedef struct {

bool feeReceived;
bool ttlReceived;
bool metadataReceived;
bool auxDataReceived;
bool validityIntervalStartReceived;

// TODO move these to commonTxData?
Expand All @@ -120,7 +120,7 @@ typedef struct {
union {
pool_registration_context_t pool_registration_subctx;
output_context_t output_subctx;
metadata_catalayst_voting_context_t metadata_catalayst_voting_subctx;
aux_data_catalyst_voting_context_t aux_data_catalayst_voting_subctx;
} stageContext;

int ui_step;
Expand Down

0 comments on commit a3b45ab

Please sign in to comment.