From 635eaed6d924433a939125007c88e4f549959c34 Mon Sep 17 00:00:00 2001 From: abenso Date: Wed, 20 Nov 2024 17:44:15 -0300 Subject: [PATCH] format files --- app/rust/include/rslib.h | 3 ++- app/src/common/parser_common.h | 2 +- app/src/common/tx.c | 4 +--- app/src/common/tx.h | 4 ++-- app/src/crypto.c | 7 ++++--- app/src/crypto.h | 2 +- app/src/crypto_helper.c | 1 - app/src/parser_impl.c | 26 +++++++++++++------------- app/src/parser_interface.c | 24 ++++++++++++++---------- tests/parser_impl.cpp | 22 ++++++++++++---------- tests/plan_effect_hash.cpp | 12 +++++------- 11 files changed, 55 insertions(+), 52 deletions(-) diff --git a/app/rust/include/rslib.h b/app/rust/include/rslib.h index f322cf92..425eb772 100644 --- a/app/rust/include/rslib.h +++ b/app/rust/include/rslib.h @@ -29,7 +29,8 @@ int32_t rs_bech32_encode(const uint8_t *hrp_ptr, size_t hrp_len, const uint8_t * parser_error_t rs_compute_transaction_plan(transaction_plan_t *plan, uint8_t *output, size_t output_len); parser_error_t rs_spend_action_hash(spend_key_bytes_t *sk, spend_plan_t *plan, uint8_t *output, size_t output_len); -parser_error_t rs_output_action_hash(spend_key_bytes_t *sk, output_plan_t *plan, bytes_t *memo_key, uint8_t *output, size_t output_len); +parser_error_t rs_output_action_hash(spend_key_bytes_t *sk, output_plan_t *plan, bytes_t *memo_key, uint8_t *output, + size_t output_len); parser_error_t rs_generic_action_hash(bytes_t *data, uint8_t action_type, uint8_t *output, size_t output_len); #ifdef __cplusplus diff --git a/app/src/common/parser_common.h b/app/src/common/parser_common.h index d779cfe7..460fa9ef 100644 --- a/app/src/common/parser_common.h +++ b/app/src/common/parser_common.h @@ -22,8 +22,8 @@ extern "C" { #include #include -#include "parser_txdef.h" #include "keys_def.h" +#include "parser_txdef.h" #define CHECK_ERROR(__CALL) \ { \ diff --git a/app/src/common/tx.c b/app/src/common/tx.c index 9acb5693..135d7866 100644 --- a/app/src/common/tx.c +++ b/app/src/common/tx.c @@ -82,9 +82,7 @@ const char *tx_parse() { void tx_parse_reset() { MEMZERO(&tx_obj, sizeof(tx_obj)); } -parser_tx_t* tx_get_txObject() { - return &tx_obj; -} +parser_tx_t *tx_get_txObject() { return &tx_obj; } zxerr_t tx_getNumItems(uint8_t *num_items) { parser_error_t err = parser_getNumItems(&ctx_parsed_tx, num_items); diff --git a/app/src/common/tx.h b/app/src/common/tx.h index 54f5fe31..3cc39279 100644 --- a/app/src/common/tx.h +++ b/app/src/common/tx.h @@ -17,8 +17,8 @@ #include "coin.h" #include "os.h" -#include "zxerror.h" #include "parser_txdef.h" +#include "zxerror.h" void tx_initialize(); @@ -26,7 +26,7 @@ void tx_initialize(); void tx_reset(); /// Returns the transaction object -parser_tx_t* tx_get_txObject(); +parser_tx_t *tx_get_txObject(); /// Appends buffer to the end of the current transaction buffer /// Transaction buffer will grow until it reaches the maximum allowed size diff --git a/app/src/crypto.c b/app/src/crypto.c index ea285541..cd1d95f0 100644 --- a/app/src/crypto.c +++ b/app/src/crypto.c @@ -20,9 +20,9 @@ #include "crypto_helper.h" #include "cx.h" #include "keys_def.h" -#include "zxmacros.h" #include "parser_interface.h" #include "zxformat.h" +#include "zxmacros.h" uint32_t hdPath[HDPATH_LEN_DEFAULT]; @@ -143,7 +143,8 @@ zxerr_t crypto_sign(parser_tx_t *tx_obj, uint8_t *signature, uint16_t signatureM CATCH_ZX_ERROR(computeSpendKey(&keys)); for (uint16_t i = 0; i < tx_obj->plan.actions.qty; i++) { - CATCH_ZX_ERROR(compute_action_hash(&tx_obj->actions_plan[i], &keys.skb, &tx_obj->plan.memo.key, &tx_obj->plan.actions.hashes[i])); + CATCH_ZX_ERROR(compute_action_hash(&tx_obj->actions_plan[i], &keys.skb, &tx_obj->plan.memo.key, + &tx_obj->plan.actions.hashes[i])); } CATCH_ZX_ERROR(compute_transaction_plan(&tx_obj->plan, tx_obj->effect_hash, sizeof(tx_obj->effect_hash))); @@ -152,7 +153,7 @@ zxerr_t crypto_sign(parser_tx_t *tx_obj, uint8_t *signature, uint16_t signatureM return zxerr_ok; -catch_zx_error: +catch_zx_error: MEMZERO(&keys, sizeof(keys)); MEMZERO(signature, signatureMaxlen); diff --git a/app/src/crypto.h b/app/src/crypto.h index b0db07b6..3710c9cd 100644 --- a/app/src/crypto.h +++ b/app/src/crypto.h @@ -25,8 +25,8 @@ extern "C" { #include "coin.h" #include "keys_def.h" -#include "zxerror.h" #include "parser_txdef.h" +#include "zxerror.h" extern uint32_t hdPath[HDPATH_LEN_DEFAULT]; diff --git a/app/src/crypto_helper.c b/app/src/crypto_helper.c index 58abb387..049019f5 100644 --- a/app/src/crypto_helper.c +++ b/app/src/crypto_helper.c @@ -40,4 +40,3 @@ zxerr_t compute_keys(keys_t *keys) { return zxerr_ok; } - diff --git a/app/src/parser_impl.c b/app/src/parser_impl.c index 6d675df4..a2c1c7bb 100644 --- a/app/src/parser_impl.c +++ b/app/src/parser_impl.c @@ -87,15 +87,15 @@ parser_error_t decode_output_plan(const bytes_t *data, output_plan_t *output) { } parser_error_t decode_delegate_plan(const bytes_t *data, delegate_plan_t *delegate) { - penumbra_core_component_stake_v1_Delegate delegate_plan = - penumbra_core_component_stake_v1_Delegate_init_default; + penumbra_core_component_stake_v1_Delegate delegate_plan = penumbra_core_component_stake_v1_Delegate_init_default; pb_istream_t spend_stream = pb_istream_from_buffer(data->ptr, data->len); CHECK_APP_CANARY() // Set up fixed size fields fixed_size_field_t validator_identity_arg; - setup_decode_fixed_field(&delegate_plan.validator_identity.ik, &validator_identity_arg, &delegate->validator_identity.ik, 32); + setup_decode_fixed_field(&delegate_plan.validator_identity.ik, &validator_identity_arg, &delegate->validator_identity.ik, + 32); if (!pb_decode(&spend_stream, penumbra_core_component_stake_v1_Delegate_fields, &delegate_plan)) { return parser_delegate_plan_error; @@ -116,15 +116,15 @@ parser_error_t decode_delegate_plan(const bytes_t *data, delegate_plan_t *delega } parser_error_t decode_undelegate_plan(const bytes_t *data, undelegate_plan_t *undelegate) { - penumbra_core_component_stake_v1_Undelegate undelegate_plan = - penumbra_core_component_stake_v1_Undelegate_init_default; + penumbra_core_component_stake_v1_Undelegate undelegate_plan = penumbra_core_component_stake_v1_Undelegate_init_default; pb_istream_t spend_stream = pb_istream_from_buffer(data->ptr, data->len); CHECK_APP_CANARY() // Set up fixed size fields fixed_size_field_t validator_identity_arg; - setup_decode_fixed_field(&undelegate_plan.validator_identity.ik, &validator_identity_arg, &undelegate->validator_identity.ik, 32); + setup_decode_fixed_field(&undelegate_plan.validator_identity.ik, &validator_identity_arg, + &undelegate->validator_identity.ik, 32); if (!pb_decode(&spend_stream, penumbra_core_component_stake_v1_Undelegate_fields, &undelegate_plan)) { return parser_undelegate_plan_error; @@ -160,10 +160,7 @@ bool decode_action(pb_istream_t *stream, const pb_field_t *field, void **arg) { return false; } - bytes_t action_data = { - .ptr = stream->state + 3, - .len = stream->bytes_left - 3 - }; + bytes_t action_data = {.ptr = stream->state + 3, .len = stream->bytes_left - 3}; decode_arg[actions_qty].action_data = action_data; @@ -279,7 +276,8 @@ parser_error_t _read(parser_context_t *c, parser_tx_t *v) { switch (v->actions_plan[i].action_type) { case penumbra_core_transaction_v1_ActionPlan_spend_tag: print_buffer(&v->actions_plan[i].action.spend.note.address.inner, "real spend action note address inner"); - print_buffer(&v->actions_plan[i].action.spend.note.value.asset_id.inner, "real spend action note value asset id inner"); + print_buffer(&v->actions_plan[i].action.spend.note.value.asset_id.inner, + "real spend action note value asset id inner"); print_buffer(&v->actions_plan[i].action.spend.note.rseed, "real spend action note rseed"); print_buffer(&v->actions_plan[i].action.spend.randomizer, "real spend action proof randomizer"); print_buffer(&v->actions_plan[i].action.spend.value_blinding, "real spend action proof value_blinding"); @@ -291,10 +289,12 @@ parser_error_t _read(parser_context_t *c, parser_tx_t *v) { // printf("amount lo: %lu\n", actions_plan[i].action.spend.note.value.amount.lo); break; case penumbra_core_transaction_v1_ActionPlan_output_tag: - print_buffer(&v->actions_plan[i].action.output.value.asset_id.inner, "real output action note value asset id inner"); + print_buffer(&v->actions_plan[i].action.output.value.asset_id.inner, + "real output action note value asset id inner"); // printf("output value amount hi: %lu\n", actions_plan[i].action.output.value.amount.hi); // printf("output value amount lo: %lu\n", actions_plan[i].action.output.value.amount.lo); - print_buffer(&v->actions_plan[i].action.output.dest_address.inner, "real output action note dest address inner"); + print_buffer(&v->actions_plan[i].action.output.dest_address.inner, + "real output action note dest address inner"); print_buffer(&v->actions_plan[i].action.output.rseed, "real output action note rseed"); print_buffer(&v->actions_plan[i].action.output.value_blinding, "real output action note value_blinding"); print_buffer(&v->actions_plan[i].action.output.proof_blinding_r, "real output action note proof_blinding_r"); diff --git a/app/src/parser_interface.c b/app/src/parser_interface.c index ab821c23..e3a72aac 100644 --- a/app/src/parser_interface.c +++ b/app/src/parser_interface.c @@ -18,9 +18,9 @@ #include #include "keys_def.h" +#include "protobuf/penumbra/core/transaction/v1/transaction.pb.h" #include "rslib.h" #include "zxformat.h" -#include "protobuf/penumbra/core/transaction/v1/transaction.pb.h" void print_buffer_interface(uint8_t *buffer, size_t len, const char *title) { #if defined(LEDGER_SPECIFIC) @@ -47,27 +47,31 @@ zxerr_t compute_transaction_plan(transaction_plan_t *plan, uint8_t *effect_hash, return zxerr_ok; } -zxerr_t compute_action_hash(action_t *action, spend_key_bytes_t *sk_bytes, bytes_t *memo_key,action_hash_t *output) { - if (action == NULL || output == NULL) - return zxerr_unknown; +zxerr_t compute_action_hash(action_t *action, spend_key_bytes_t *sk_bytes, bytes_t *memo_key, action_hash_t *output) { + if (action == NULL || output == NULL) return zxerr_unknown; switch (action->action_type) { case penumbra_core_transaction_v1_ActionPlan_spend_tag: - if (sk_bytes == NULL) + if (sk_bytes == NULL) { return zxerr_unknown; - if (rs_spend_action_hash(sk_bytes, &action->action.spend, (uint8_t *)output, 64) != parser_ok) + } + if (rs_spend_action_hash(sk_bytes, &action->action.spend, (uint8_t *)output, 64) != parser_ok) { return zxerr_encoding_failed; + } break; case penumbra_core_transaction_v1_ActionPlan_output_tag: - if (sk_bytes == NULL) - return zxerr_unknown; - if (rs_output_action_hash(sk_bytes, &action->action.output, memo_key, (uint8_t *)output, 64) != parser_ok) + if (sk_bytes == NULL) { + return zxerr_unknown; + } + if (rs_output_action_hash(sk_bytes, &action->action.output, memo_key, (uint8_t *)output, 64) != parser_ok) { return zxerr_encoding_failed; + } break; case penumbra_core_transaction_v1_ActionPlan_delegate_tag: case penumbra_core_transaction_v1_ActionPlan_undelegate_tag: - if (rs_generic_action_hash(&action->action_data, action->action_type, (uint8_t *)output, 64) != parser_ok) + if (rs_generic_action_hash(&action->action_data, action->action_type, (uint8_t *)output, 64) != parser_ok) { return zxerr_encoding_failed; + } break; default: return zxerr_unknown; diff --git a/tests/parser_impl.cpp b/tests/parser_impl.cpp index 59393204..9c3321c7 100644 --- a/tests/parser_impl.cpp +++ b/tests/parser_impl.cpp @@ -28,7 +28,6 @@ #include "parser_txdef.h" #include "zxformat.h" - using namespace std; TEST(SCALE, ReadBytes) { @@ -36,24 +35,27 @@ TEST(SCALE, ReadBytes) { parser_tx_t tx_obj = {0}; parser_error_t err; uint8_t buffer[6000]; - auto bufferLen = parseHexString( - buffer, sizeof(buffer), - "0a47ca02440a220a20f9b7b3723506cca29bdfb54b409d7ffff96f23aaa8998101f23ff9ec4c955c861a0a08b9a1f789a28c94de02220a08b5a8ba94d2b2ed8d032a0608d10910d109123808e0d6e5821b1223706e7964772d31383432333733323334373436313838363932363135333332333035341a0b0a0908c6e09fded6c3cb37"); + auto bufferLen = + parseHexString(buffer, sizeof(buffer), + "0a47ca02440a220a20f9b7b3723506cca29bdfb54b409d7ffff96f23aaa8998101f23ff9ec4c955c861a0a08b9a1f789a28c" + "94de02220a08b5a8ba94d2b2ed8d032a0608d10910d109123808e0d6e5821b1223706e7964772d3138343233373332333437" + "3436313838363932363135333332333035341a0b0a0908c6e09fded6c3cb37"); spend_key_bytes_t sk_bytes = {0}; - std::array sk_bytes_raw = { - 0xa1, 0xff, 0xba, 0x0c, 0x37, 0x93, 0x1f, 0x0a, 0x62, 0x61, 0x37, 0x52, 0x0d, 0xa6, 0x50, 0x63, - 0x2d, 0x35, 0x85, 0x3b, 0xf5, 0x91, 0xb3, 0x6b, 0xb4, 0x28, 0x63, 0x0a, 0x4d, 0x87, 0xc4, 0xdc - }; + std::array sk_bytes_raw = {0xa1, 0xff, 0xba, 0x0c, 0x37, 0x93, 0x1f, 0x0a, 0x62, 0x61, 0x37, + 0x52, 0x0d, 0xa6, 0x50, 0x63, 0x2d, 0x35, 0x85, 0x3b, 0xf5, 0x91, + 0xb3, 0x6b, 0xb4, 0x28, 0x63, 0x0a, 0x4d, 0x87, 0xc4, 0xdc}; std::copy(sk_bytes_raw.begin(), sk_bytes_raw.end(), sk_bytes); ctx.sk_bytes = &sk_bytes; err = parser_parse(&ctx, buffer, bufferLen, &tx_obj); ASSERT_EQ(err, parser_ok) << parser_getErrorDescription(err); - std::string expected = "09cb80cda44cd051971bcc9fa1acc71a4d4366d52b2f4ee49fdc15eb18d30dbde75373d5cfbadf467277da61907a21ec8ce3d5dd9c04af70ee67ce4beff7bcae"; + std::string expected = + "09cb80cda44cd051971bcc9fa1acc71a4d4366d52b2f4ee49fdc15eb18d30dbde75373d5cfbadf467277da61907a21ec8ce3d5dd9c04af70ee6" + "7ce4beff7bcae"; char actual[129]; array_to_hexstr(actual, sizeof(actual), tx_obj.effect_hash, sizeof(tx_obj.effect_hash)); - + EXPECT_EQ(std::string(actual), expected); } diff --git a/tests/plan_effect_hash.cpp b/tests/plan_effect_hash.cpp index 0a576583..24ac4317 100644 --- a/tests/plan_effect_hash.cpp +++ b/tests/plan_effect_hash.cpp @@ -83,11 +83,10 @@ void check_testcase(const testcase_t &tc, bool expert_mode) { parser_context_t ctx = {0}; parser_error_t err; - spend_key_bytes_t sk_bytes = {0}; - std::array sk_bytes_raw = { - 0xa1, 0xff, 0xba, 0x0c, 0x37, 0x93, 0x1f, 0x0a, 0x62, 0x61, 0x37, 0x52, 0x0d, 0xa6, 0x50, 0x63, - 0x2d, 0x35, 0x85, 0x3b, 0xf5, 0x91, 0xb3, 0x6b, 0xb4, 0x28, 0x63, 0x0a, 0x4d, 0x87, 0xc4, 0xdc - }; + spend_key_bytes_t sk_bytes = {0}; + std::array sk_bytes_raw = {0xa1, 0xff, 0xba, 0x0c, 0x37, 0x93, 0x1f, 0x0a, 0x62, 0x61, 0x37, + 0x52, 0x0d, 0xa6, 0x50, 0x63, 0x2d, 0x35, 0x85, 0x3b, 0xf5, 0x91, + 0xb3, 0x6b, 0xb4, 0x28, 0x63, 0x0a, 0x4d, 0x87, 0xc4, 0xdc}; std::copy(sk_bytes_raw.begin(), sk_bytes_raw.end(), sk_bytes); ctx.sk_bytes = &sk_bytes; @@ -102,11 +101,10 @@ void check_testcase(const testcase_t &tc, bool expert_mode) { std::string expected = tc.hash; char actual[129]; array_to_hexstr(actual, sizeof(actual), tx_obj.effect_hash, sizeof(tx_obj.effect_hash)); - + EXPECT_EQ(std::string(actual), expected); } - INSTANTIATE_TEST_SUITE_P (JsonTestCasesCurrentTxVer, JsonTestsA, ::testing::ValuesIn(GetJsonTestCases("plan_effect_hash_testcases.json")));