Skip to content

Commit

Permalink
feat: output unification v2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mpolitzer committed Jul 2, 2024
1 parent 2f441c7 commit eb150af
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sys-utils/libcmt/include/libcmt/merkle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion sys-utils/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions sys-utils/libcmt/tests/merkle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand All @@ -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]);
}
Expand Down

0 comments on commit eb150af

Please sign in to comment.