Skip to content

Commit

Permalink
Updated test vectors to Namada v0.33.0. Fixed non-MASP bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed Apr 24, 2024
1 parent bfcab23 commit bfe3643
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 42,781 deletions.
2 changes: 1 addition & 1 deletion app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static zxerr_t crypto_addTxnHashes(const parser_tx_t *txObj, concatenated_hashes
MEMCPY(hashes->hashes.ptr + hashes->hashesLen * HASH_LEN, txObj->initProposal.content_sechash.ptr, HASH_LEN);
hashes->indices.ptr[hashes->hashesLen] = txObj->initProposal.content_secidx;
hashes->hashesLen++;
if (txObj->initProposal.has_proposal_code) {
if (txObj->initProposal.proposal_type == DefaultWithWasm) {
MEMCPY(hashes->hashes.ptr + hashes->hashesLen * HASH_LEN, txObj->initProposal.proposal_code_sechash.ptr, HASH_LEN);
hashes->indices.ptr[hashes->hashesLen] = txObj->initProposal.proposal_code_secidx;
hashes->hashesLen++;
Expand Down
2 changes: 1 addition & 1 deletion app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ parser_error_t getNumItems(const parser_context_t *ctx, uint8_t *numItems) {
}
case InitProposal: {
*numItems = (app_mode_expert() ? INIT_PROPOSAL_EXPERT_PARAMS : INIT_PROPOSAL_NORMAL_PARAMS);
if (ctx->tx_obj->initProposal.proposal_type == Default && ctx->tx_obj->initProposal.has_proposal_code) {
if (ctx->tx_obj->initProposal.proposal_type == DefaultWithWasm) {
(*numItems)++;
} else if (ctx->tx_obj->initProposal.proposal_type == PGFSteward) {
*numItems += ctx->tx_obj->initProposal.pgf_steward_actions_num;
Expand Down
4 changes: 2 additions & 2 deletions app/src/parser_impl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extern "C" {
#define INIT_ACCOUNT_NORMAL_PARAMS 3
#define INIT_ACCOUNT_EXPERT_PARAMS 8

#define INIT_PROPOSAL_NORMAL_PARAMS 8
#define INIT_PROPOSAL_EXPERT_PARAMS 13
#define INIT_PROPOSAL_NORMAL_PARAMS 7
#define INIT_PROPOSAL_EXPERT_PARAMS 12

#define VOTE_PROPOSAL_NORMAL_PARAMS 4
#define VOTE_PROPOSAL_EXPERT_PARAMS 9
Expand Down
25 changes: 11 additions & 14 deletions app/src/parser_impl_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ static parser_error_t readInitProposalTxn(const bytes_t *data, const section_t *
parser_context_t ctx = {.buffer = data->ptr, .bufferLen = data->len, .offset = 0, .tx_obj = NULL};
MEMZERO(&v->initProposal, sizeof(v->initProposal));

// Check if the proposal has an ID
CHECK_ERROR(readUint64(&ctx, &v->initProposal.proposal_id));

// Read content section hash
v->initProposal.content_sechash.len = HASH_LEN;
CHECK_ERROR(readBytes(&ctx, &v->initProposal.content_sechash.ptr, v->initProposal.content_sechash.len))
Expand All @@ -311,16 +308,16 @@ static parser_error_t readInitProposalTxn(const bytes_t *data, const section_t *
CHECK_ERROR(readBytes(&ctx, &v->initProposal.author.ptr, v->initProposal.author.len))

// Proposal type
v->initProposal.has_proposal_code = 0;
CHECK_ERROR(readByte(&ctx, &v->initProposal.proposal_type))

switch (v->initProposal.proposal_type) {
case Default: {
// Proposal type 0 is Default(Option<Hash>), where Hash is the proposal code.
CHECK_ERROR(readByte(&ctx, &v->initProposal.has_proposal_code))
if (v->initProposal.has_proposal_code) {
v->initProposal.proposal_code_sechash.len = HASH_LEN;
CHECK_ERROR(readBytes(&ctx, &v->initProposal.proposal_code_sechash.ptr, v->initProposal.proposal_code_sechash.len))
}
break;
}

case DefaultWithWasm: {
v->initProposal.proposal_code_sechash.len = HASH_LEN;
CHECK_ERROR(readBytes(&ctx, &v->initProposal.proposal_code_sechash.ptr, v->initProposal.proposal_code_sechash.len))
break;
}

Expand Down Expand Up @@ -367,8 +364,8 @@ static parser_error_t readInitProposalTxn(const bytes_t *data, const section_t *
// Voting end epoch
CHECK_ERROR(readUint64(&ctx, &v->initProposal.voting_end_epoch))

// Grace epoch
CHECK_ERROR(readUint64(&ctx, &v->initProposal.grace_epoch))
// Activation epoch
CHECK_ERROR(readUint64(&ctx, &v->initProposal.activation_epoch))

bool found_content = false, found_code = false;
// Load the linked to data from the extra data sections
Expand All @@ -386,7 +383,7 @@ static parser_error_t readInitProposalTxn(const bytes_t *data, const section_t *
v->initProposal.content_hash.len = HASH_LEN;
found_content = true;
}
if (v->initProposal.proposal_type == Default && v->initProposal.has_proposal_code &&
if (v->initProposal.proposal_type == DefaultWithWasm &&
!memcmp(extraDataHash, v->initProposal.proposal_code_sechash.ptr, HASH_LEN)) {
// If this section contains the proposal code
v->initProposal.proposal_code_secidx = extra_data[i].idx;
Expand All @@ -397,7 +394,7 @@ static parser_error_t readInitProposalTxn(const bytes_t *data, const section_t *
}
}

const bool code_condition = (v->initProposal.proposal_type == Default) && (v->initProposal.has_proposal_code && !found_code);
const bool code_condition = (v->initProposal.proposal_type == DefaultWithWasm) && !found_code;
if (!found_content || code_condition) {
return parser_missing_field;
} else if (ctx.offset != ctx.bufferLen) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/parser_print_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ parser_error_t printProposal(const tx_init_proposal_t *initProposal, uint8_t dis
if (displayIdx == 0) {
snprintf(outKey, outKeyLen, "Proposal type");
switch (initProposal->proposal_type) {
case Default:
case Default: case DefaultWithWasm:
snprintf(outVal, outValLen, "Default");
break;

Expand All @@ -270,7 +270,7 @@ parser_error_t printProposal(const tx_init_proposal_t *initProposal, uint8_t dis
return parser_ok;
}

if (initProposal->proposal_type == Default) {
if (initProposal->proposal_type == Default || initProposal->proposal_type == DefaultWithWasm) {
snprintf(outKey, outKeyLen, "Proposal hash");
pageStringHex(outVal, outValLen, (const char*)initProposal->proposal_code_hash.ptr,
initProposal->proposal_code_hash.len, pageIdx, pageCount);
Expand Down
59 changes: 19 additions & 40 deletions app/src/parser_print_txn.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ static parser_error_t printInitProposalTxn( const parser_context_t *ctx,
uint32_t proposalElements = 1;
switch (initProposal->proposal_type) {
case Default:
proposalElements += initProposal->has_proposal_code;
break;
case DefaultWithWasm:
proposalElements += 1;
break;
case PGFSteward:
proposalElements += initProposal->pgf_steward_actions_num;
Expand All @@ -310,14 +312,14 @@ static parser_error_t printInitProposalTxn( const parser_context_t *ctx,
break;
}

if (displayIdx >= 2 && displayIdx < 2 + proposalElements) {
adjustedIdx = 2;
if (displayIdx >= 1 && displayIdx < 1 + proposalElements) {
adjustedIdx = 1;
}
if (displayIdx >= 2 + proposalElements) {
if (displayIdx >= 1 + proposalElements) {
adjustedIdx = displayIdx - proposalElements + 1;
}
const bool hasMemo = ctx->tx_obj->transaction.header.memoSection != NULL;
if (adjustedIdx >= 8 && !hasMemo) {
if (adjustedIdx >= 7 && !hasMemo) {
adjustedIdx++;
}
// Less than 20 characters are epochs are uint64
Expand All @@ -332,63 +334,53 @@ static parser_error_t printInitProposalTxn( const parser_context_t *ctx,
}
break;

case 1:
snprintf(outKey, outKeyLen, "ID");
// Less than 20 characters as proposal_id is an u64
char idString[25] = {0};
if (uint64_to_str(idString, sizeof(idString), ctx->tx_obj->initProposal.proposal_id) != NULL) {
return parser_unexpected_error;
}
snprintf(outVal, outValLen, "%s", idString);
break;

case 2: {
CHECK_ERROR(printProposal(&ctx->tx_obj->initProposal, (displayIdx - 2), outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
case 1: {
CHECK_ERROR(printProposal(&ctx->tx_obj->initProposal, (displayIdx - 1), outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;
}

case 3:
case 2:
snprintf(outKey, outKeyLen, "Author");
CHECK_ERROR(printAddress(ctx->tx_obj->initProposal.author, outVal, outValLen, pageIdx, pageCount))
break;
case 4:
case 3:
snprintf(outKey, outKeyLen, "Voting start epoch");
if (uint64_to_str(strEpoch, sizeof(strEpoch), ctx->tx_obj->initProposal.voting_start_epoch) != NULL) {
return parser_unexpected_error;
}
pageString(outVal, outValLen, strEpoch, pageIdx, pageCount);
break;
case 5:
case 4:
snprintf(outKey, outKeyLen, "Voting end epoch");
if (uint64_to_str(strEpoch, sizeof(strEpoch), ctx->tx_obj->initProposal.voting_end_epoch) != NULL) {
return parser_unexpected_error;
}
pageString(outVal, outValLen, strEpoch, pageIdx, pageCount);
break;
case 6:
snprintf(outKey, outKeyLen, "Grace epoch");
if (uint64_to_str(strEpoch, sizeof(strEpoch), ctx->tx_obj->initProposal.grace_epoch) != NULL) {
case 5:
snprintf(outKey, outKeyLen, "Activation epoch");
if (uint64_to_str(strEpoch, sizeof(strEpoch), ctx->tx_obj->initProposal.activation_epoch) != NULL) {
return parser_unexpected_error;
}
pageString(outVal, outValLen, strEpoch, pageIdx, pageCount);
break;
case 7:
case 6:
snprintf(outKey, outKeyLen, "Content");
char strContent[65] = {0};
const bytes_t *content = &ctx->tx_obj->initProposal.content_hash;
array_to_hexstr((char*) strContent, sizeof(strContent), content->ptr, content->len);
pageString(outVal, outValLen, (const char*) &strContent, pageIdx, pageCount);
break;

case 8:
case 7:
CHECK_ERROR(printMemo(ctx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))
break;

default:
if (!app_mode_expert()) {
return parser_display_idx_out_of_range;
}
adjustedIdx -= 9;
adjustedIdx -= 8;
return printExpert(ctx, adjustedIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount);
}

Expand Down Expand Up @@ -439,20 +431,7 @@ static parser_error_t printVoteProposalTxn( const parser_context_t *ctx,
snprintf(outKey, outKeyLen, "Vote");
switch (voteProposal->proposal_vote) {
case Yay:
switch (voteProposal->vote_type) {
case Default:
snprintf(outVal, outValLen, "yay");
break;
case PGFSteward:
snprintf(outVal, outValLen, "yay for PGF steward");
break;
case PGFPayment:
snprintf(outVal, outValLen, "yay for PGF payment");
break;

default:
return parser_unexpected_value;
}
snprintf(outVal, outValLen, "yay");
break;

case Nay:
Expand Down
10 changes: 4 additions & 6 deletions app/src/parser_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ typedef enum {

typedef enum {
Default = 0,
PGFSteward = 1,
PGFPayment = 2,
DefaultWithWasm = 1,
PGFSteward = 2,
PGFPayment = 3,
} yay_vote_type_e;

typedef enum {
Expand Down Expand Up @@ -126,17 +127,15 @@ typedef struct {
} pgf_payment_action_t;

typedef struct {
uint64_t proposal_id;
bytes_t content_hash;
bytes_t content_sechash;
bytes_t author;
uint64_t voting_start_epoch;
uint64_t voting_end_epoch;
uint64_t grace_epoch;
uint64_t activation_epoch;
uint8_t proposal_type;
union {
struct {
uint8_t has_proposal_code;
bytes_t proposal_code_sechash;
bytes_t proposal_code_hash;
};
Expand Down Expand Up @@ -169,7 +168,6 @@ typedef struct {
typedef struct {
uint64_t proposal_id;
proposal_vote_e proposal_vote;
yay_vote_type_e vote_type;
uint32_t number_of_councils;
bytes_t councils;
bytes_t eth_bridge_signature;
Expand Down
2 changes: 1 addition & 1 deletion deps/nanosplus-secure-sdk
2 changes: 1 addition & 1 deletion deps/nanox-secure-sdk
Loading

0 comments on commit bfe3643

Please sign in to comment.