From eb150af5410e3fbc42344e1c9bc886b7d0912964 Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:57:04 -0300 Subject: [PATCH] feat: output unification v2 Outputs root hash merkle tree is the same for all inputs, we stop resetting it for each input (v1). With that the tree will grow indefinetely and thus we also increased its depth to 2^63 leafs. Merkle tree tests also had to be updated because changing its depth also changes its root hash. --- sys-utils/libcmt/include/libcmt/merkle.h | 2 +- sys-utils/libcmt/src/rollup.c | 1 - sys-utils/libcmt/tests/merkle.c | 12 ++++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sys-utils/libcmt/include/libcmt/merkle.h b/sys-utils/libcmt/include/libcmt/merkle.h index 0da02b23..08537c7a 100644 --- a/sys-utils/libcmt/include/libcmt/merkle.h +++ b/sys-utils/libcmt/include/libcmt/merkle.h @@ -24,7 +24,7 @@ #include "keccak.h" enum { - CMT_MERKLE_TREE_HEIGHT = 16, /**< merkle tree height */ + CMT_MERKLE_TREE_HEIGHT = 63, /**< merkle tree height */ }; /** Opaque Merkle tree state. diff --git a/sys-utils/libcmt/src/rollup.c b/sys-utils/libcmt/src/rollup.c index bc7f658e..0cc3c345 100644 --- a/sys-utils/libcmt/src/rollup.c +++ b/sys-utils/libcmt/src/rollup.c @@ -322,7 +322,6 @@ int cmt_rollup_finish(cmt_rollup_t *me, cmt_rollup_finish_t *finish) { } finish->next_request_type = reason; finish->next_request_payload_length = me->fromhost_data; - cmt_merkle_init(me->merkle); return 0; } diff --git a/sys-utils/libcmt/tests/merkle.c b/sys-utils/libcmt/tests/merkle.c index f552720f..5ef0efdf 100644 --- a/sys-utils/libcmt/tests/merkle.c +++ b/sys-utils/libcmt/tests/merkle.c @@ -63,9 +63,9 @@ void test_merkle_push_back_and_get_root(void) { uint8_t root[CMT_KECCAK_LENGTH]; cmt_merkle_get_root_hash(&merkle, root); - uint8_t expected_root[CMT_KECCAK_LENGTH] = {0x27, 0x33, 0xe5, 0x0f, 0x52, 0x6e, 0xc2, 0xfa, 0x19, 0xa2, 0x2b, 0x31, - 0xe8, 0xed, 0x50, 0xf2, 0x3c, 0xd1, 0xfd, 0xf9, 0x4c, 0x91, 0x54, 0xed, 0x3a, 0x76, 0x09, 0xa2, 0xf1, 0xff, - 0x98, 0x1f}; + uint8_t expected_root[CMT_KECCAK_LENGTH] = {0x0a, 0x16, 0x29, 0x46, 0xe5, 0x61, 0x58, 0xba, 0xc0, 0x67, 0x3e, 0x6d, + 0xd3, 0xbd, 0xfd, 0xc1, 0xe4, 0xa0, 0xe7, 0x74, 0x4a, 0x12, 0x0f, 0xdb, 0x64, 0x00, 0x50, 0xc8, 0xd7, 0xab, + 0xe1, 0xc6}; for (int i = 0; i < CMT_KECCAK_LENGTH; ++i) { assert(root[i] == expected_root[i]); } @@ -85,9 +85,9 @@ void test_cmt_merkle_push_back_data_and_get_root(void) { uint8_t root[CMT_KECCAK_LENGTH]; cmt_merkle_get_root_hash(&merkle, root); - uint8_t expected_root[CMT_KECCAK_LENGTH] = {0xe8, 0xe0, 0x47, 0x71, 0x14, 0xcb, 0x63, 0x0c, 0x4d, 0x14, 0xee, 0xa2, - 0x49, 0xeb, 0x2c, 0x63, 0xd8, 0x4c, 0x9c, 0x68, 0x5d, 0xdf, 0x35, 0xd1, 0x37, 0x01, 0x9e, 0x65, 0x9a, 0xe2, - 0x04, 0x18}; + uint8_t expected_root[CMT_KECCAK_LENGTH] = {0x45, 0xa6, 0xfd, 0x68, 0x45, 0xc1, 0x7f, 0xe0, 0x21, 0x7f, 0xf0, 0xfd, + 0x9b, 0x2c, 0x02, 0x1f, 0x2f, 0x2e, 0xe3, 0x9e, 0xe1, 0x99, 0x7d, 0xf3, 0x1f, 0x2d, 0x4c, 0x81, 0x7d, 0x3d, + 0x1b, 0xf7}; for (int i = 0; i < CMT_KECCAK_LENGTH; ++i) { assert(root[i] == expected_root[i]); }