Skip to content

Commit

Permalink
Added pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamlabs committed Jun 27, 2022
1 parent 44778a3 commit 19a8474
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/signTx.c
Expand Up @@ -813,8 +813,9 @@ static void parseInput(uint8_t* wireDataBuffer, size_t wireDataSize)

VALIDATE(wireDataSize == SIZEOF(*wireUtxo), ERR_INVALID_DATA);

memmove(input->input_data.txHashBuffer, wireUtxo->txHash, SIZEOF(input->input_data.txHashBuffer));
input->input_data.index = u4be_read(wireUtxo->index);
tx_input_t* inputData = &input->input_data;
memmove(inputData->txHashBuffer, wireUtxo->txHash, SIZEOF(inputData->txHashBuffer));
inputData->index = u4be_read(wireUtxo->index);
}

static void constructInputLabel(const char* prefix, uint16_t index)
Expand Down Expand Up @@ -865,7 +866,7 @@ static void signTx_handleInputAPDU(uint8_t p2, uint8_t* wireDataBuffer, size_t w
TRACE("Adding input to tx hash");
txHashBuilder_addInput(
&BODY_CTX->txHashBuilder,
BODY_CTX->stageData.input.input_data
&BODY_CTX->stageData.input.input_data
);
}
{
Expand Down Expand Up @@ -1887,7 +1888,7 @@ static void signTx_handleCollateralAPDU(uint8_t p2, uint8_t* wireDataBuffer, siz
TRACE("Adding collateral to tx hash");
txHashBuilder_addCollateral(
&BODY_CTX->txHashBuilder,
BODY_CTX->stageData.input.input_data
&BODY_CTX->stageData.input.input_data
);
}
{
Expand Down
16 changes: 8 additions & 8 deletions src/txHashBuilder.c
Expand Up @@ -155,10 +155,10 @@ void txHashBuilder_enterInputs(tx_hash_builder_t* builder)
builder->state = TX_HASH_BUILDER_IN_INPUTS;
}

void txHashBuilder_addInput(tx_hash_builder_t *builder, tx_input_t input)
void txHashBuilder_addInput(tx_hash_builder_t *builder, const tx_input_t* input)
{
_TRACE("state = %d, remainingInputs = %u", builder->state, builder->remainingInputs);
size_t utxoHashSize = SIZEOF(input.txHashBuffer);
const size_t utxoHashSize = SIZEOF(input->txHashBuffer);

ASSERT(utxoHashSize < BUFFER_SIZE_PARANOIA);
ASSERT(builder->state == TX_HASH_BUILDER_IN_INPUTS);
Expand All @@ -173,10 +173,10 @@ void txHashBuilder_addInput(tx_hash_builder_t *builder, tx_input_t input)
{
ASSERT(utxoHashSize == TX_HASH_LENGTH);
BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, utxoHashSize);
BUILDER_APPEND_DATA(input.txHashBuffer, utxoHashSize);
BUILDER_APPEND_DATA(input->txHashBuffer, utxoHashSize);
}
{
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED, input.index);
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED, input->index);
}
}
}
Expand Down Expand Up @@ -1300,10 +1300,10 @@ void txHashBuilder_enterCollaterals(tx_hash_builder_t* builder)
builder->state = TX_HASH_BUILDER_IN_COLLATERALS;
}

void txHashBuilder_addCollateral(tx_hash_builder_t *builder, tx_input_t collInput)
void txHashBuilder_addCollateral(tx_hash_builder_t *builder, const tx_input_t* collInput)
{
_TRACE("state = %d, remainingCollaterals = %u", builder->state, builder->remainingCollaterals);
size_t utxoHashSize = SIZEOF(collInput.txHashBuffer);
const size_t utxoHashSize = SIZEOF(collInput->txHashBuffer);

ASSERT(utxoHashSize < BUFFER_SIZE_PARANOIA);
ASSERT(builder->state == TX_HASH_BUILDER_IN_COLLATERALS);
Expand All @@ -1318,10 +1318,10 @@ void txHashBuilder_addCollateral(tx_hash_builder_t *builder, tx_input_t collInpu
{
ASSERT(utxoHashSize == TX_HASH_LENGTH);
BUILDER_APPEND_CBOR(CBOR_TYPE_BYTES, utxoHashSize);
BUILDER_APPEND_DATA(collInput.txHashBuffer, utxoHashSize);
BUILDER_APPEND_DATA(collInput->txHashBuffer, utxoHashSize);
}
{
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED, collInput.index);
BUILDER_APPEND_CBOR(CBOR_TYPE_UNSIGNED, collInput->index);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/txHashBuilder.h
Expand Up @@ -112,7 +112,7 @@ void txHashBuilder_init(
);

void txHashBuilder_enterInputs(tx_hash_builder_t* builder);
void txHashBuilder_addInput(tx_hash_builder_t *builder, tx_input_t input);
void txHashBuilder_addInput(tx_hash_builder_t *builder, const tx_input_t* input);

void txHashBuilder_enterOutputs(tx_hash_builder_t* builder);
void txHashBuilder_addOutput_topLevelData(
Expand Down Expand Up @@ -239,7 +239,7 @@ void txHashBuilder_addScriptDataHash(
);

void txHashBuilder_enterCollaterals(tx_hash_builder_t* builder);
void txHashBuilder_addCollateral(tx_hash_builder_t *builder, tx_input_t collInput);
void txHashBuilder_addCollateral(tx_hash_builder_t *builder, const tx_input_t* collInput);

void txHashBuilder_enterRequiredSigners(tx_hash_builder_t* builder);
void txHashBuilder_addRequiredSigner(
Expand Down
2 changes: 1 addition & 1 deletion src/txHashBuilder_test.c
Expand Up @@ -384,7 +384,7 @@ void run_txHashBuilder_test()
tx_input_t input;
memmove(input.txHashBuffer, tmp, tmpSize);
input.index = it->index;
txHashBuilder_addInput(&builder, input);
txHashBuilder_addInput(&builder, &input);
}

addOutputs(&builder);
Expand Down
12 changes: 7 additions & 5 deletions src/uiScreens.c
Expand Up @@ -837,22 +837,24 @@ void ui_displayInputScreen(
const sign_tx_transaction_input_t* input,
ui_callback_fn_t callback)
{
char txHex[2 * SIZEOF(input->input_data.txHashBuffer) + 1] = {0};
const tx_input_t* inputData = &input->input_data;
ASSERT(SIZEOF(inputData->txHashBuffer) == TX_HASH_LENGTH);
char txHex[2 * TX_HASH_LENGTH + 1] = {0};
explicit_bzero(txHex, SIZEOF(txHex));

size_t length = encode_hex(
input->input_data.txHashBuffer, SIZEOF(input->input_data.txHashBuffer),
inputData->txHashBuffer, TX_HASH_LENGTH,
txHex, SIZEOF(txHex)
);
ASSERT(length == strlen(txHex));
ASSERT(length == 2 * SIZEOF(input->input_data.txHashBuffer));
ASSERT(length == 2 * TX_HASH_LENGTH);

// index 32 bit (10) + separator (" / ") + utxo hash hex format + \0
// + 1 byte to detect if everything has been written
char inputStr[10 + 3 + SIZEOF(input->input_data.txHashBuffer) * 2 + 1 + 1] = {0};
char inputStr[10 + 3 + TX_HASH_LENGTH * 2 + 1 + 1] = {0};
explicit_bzero(inputStr, SIZEOF(inputStr));

snprintf(inputStr, SIZEOF(inputStr), "%u / %s", input->input_data.index, txHex);
snprintf(inputStr, SIZEOF(inputStr), "%u / %s", inputData->index, txHex);
// make sure all the information is displayed to the user
ASSERT(strlen(inputStr) + 1 < SIZEOF(inputStr));

Expand Down

0 comments on commit 19a8474

Please sign in to comment.