From 99b9e8a90f9923488b3a779eeebacaefdaa8465d Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Mon, 20 May 2024 10:26:10 -0300 Subject: [PATCH] feat!: Add prevrandao field to EvmAdvance --- sys-utils/libcmt/src/rollup.c | 5 +++-- sys-utils/libcmt/src/rollup.h | 1 + sys-utils/libcmt/tests/create-data.sh | 3 ++- sys-utils/libcmt/tests/data.h | 12 +++++++----- sys-utils/libcmt/tests/rollup.c | 9 ++++++++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sys-utils/libcmt/src/rollup.c b/sys-utils/libcmt/src/rollup.c index 4aa41dfb..8c46d69d 100644 --- a/sys-utils/libcmt/src/rollup.c +++ b/sys-utils/libcmt/src/rollup.c @@ -28,8 +28,8 @@ // Notice(bytes) #define NOTICE CMT_ABI_FUNSEL(0xc2, 0x58, 0xd6, 0xe5) -// EvmAdvance(uint256,address,address,uint256,uint256,uint256,bytes) -#define EVM_ADVANCE CMT_ABI_FUNSEL(0xcc, 0x7d, 0xee, 0x1f) +// EvmAdvance(uint256,address,address,uint256,uint256,uint256,uint256,bytes) +#define EVM_ADVANCE CMT_ABI_FUNSEL(0x41, 0x5b, 0xf3, 0x63) #define DBG(X) debug(X, #X, __FILE__, __LINE__) static int debug(int rc, const char *expr, const char *file, int line) { @@ -249,6 +249,7 @@ int cmt_rollup_read_advance_state(cmt_rollup_t *me, cmt_rollup_advance_t *advanc || DBG(cmt_abi_get_address(rd, advance->msg_sender)) || DBG(cmt_abi_get_uint(rd, sizeof(advance->block_number), &advance->block_number)) || DBG(cmt_abi_get_uint(rd, sizeof(advance->block_timestamp), &advance->block_timestamp)) + || DBG(cmt_abi_get_uint(rd, sizeof(advance->prev_randao), advance->prev_randao)) || DBG(cmt_abi_get_uint(rd, sizeof(advance->index), &advance->index)) || DBG(cmt_abi_get_bytes_s(rd, of)) || DBG(cmt_abi_get_bytes_d(anchor, of, &payload_length, &advance->payload))) { diff --git a/sys-utils/libcmt/src/rollup.h b/sys-utils/libcmt/src/rollup.h index 80c46ffb..b5222452 100644 --- a/sys-utils/libcmt/src/rollup.h +++ b/sys-utils/libcmt/src/rollup.h @@ -48,6 +48,7 @@ typedef struct cmt_rollup_advance { uint8_t msg_sender[CMT_ADDRESS_LENGTH]; /**< input sender address */ uint64_t block_number; /**< block number of this input */ uint64_t block_timestamp; /**< block timestamp of this input UNIX epoch format) */ + uint8_t prev_randao[CMT_WORD_LENGTH]; /**< The latest RANDAO mix of the post beacon state of the previous block */ uint64_t index; /**< input index (in relation to all inputs ever sent to the DApp) */ uint32_t payload_length; /**< length in bytes of the payload field */ void *payload; /**< payload for this input */ diff --git a/sys-utils/libcmt/tests/create-data.sh b/sys-utils/libcmt/tests/create-data.sh index 82747dda..d98096c5 100755 --- a/sys-utils/libcmt/tests/create-data.sh +++ b/sys-utils/libcmt/tests/create-data.sh @@ -6,13 +6,14 @@ echo "#ifndef DATA_H" echo "#define DATA_H" echo "#include " echo "uint8_t valid_advance_0[] = {" -cast calldata "EvmAdvance(uint256,address,address,uint256,uint256,uint256,bytes)" \ +cast calldata "EvmAdvance(uint256,address,address,uint256,uint256,uint256,uint256,bytes)" \ 0x0000000000000000000000000000000000000001 \ 0x0000000000000000000000000000000000000002 \ 0x0000000000000000000000000000000000000003 \ 0x0000000000000000000000000000000000000004 \ 0x0000000000000000000000000000000000000005 \ 0x0000000000000000000000000000000000000006 \ + 0x0000000000000000000000000000000000000007 \ 0x`echo -en "advance-0" | xxd -p -c0` | xxd -r -p | xxd -i echo "};" diff --git a/sys-utils/libcmt/tests/data.h b/sys-utils/libcmt/tests/data.h index 4cf554b7..eb7d44b3 100644 --- a/sys-utils/libcmt/tests/data.h +++ b/sys-utils/libcmt/tests/data.h @@ -2,7 +2,7 @@ #define DATA_H #include uint8_t valid_advance_0[] = { - 0xcc, 0x7d, 0xee, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x41, 0x5b, 0xf3, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -20,13 +20,15 @@ uint8_t valid_advance_0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x61, 0x64, 0x76, 0x61, - 0x6e, 0x63, 0x65, 0x2d, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x2d, + 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t valid_inspect_0[] = { 0x69, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x74, 0x2d, 0x30 diff --git a/sys-utils/libcmt/tests/rollup.c b/sys-utils/libcmt/tests/rollup.c index 1071621a..b6e871e9 100644 --- a/sys-utils/libcmt/tests/rollup.c +++ b/sys-utils/libcmt/tests/rollup.c @@ -64,6 +64,12 @@ static void check_first_input(cmt_rollup_t *rollup) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, }; + uint8_t expected_prev_randao[CMT_WORD_LENGTH] = { + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; char expected_payload[] = "advance-0"; // clang-format on @@ -73,7 +79,8 @@ static void check_first_input(cmt_rollup_t *rollup) { assert(memcmp(advance.msg_sender, expected_msg_sender, CMT_ADDRESS_LENGTH) == 0); assert(advance.block_number == 4); assert(advance.block_timestamp == 5); - assert(advance.index == 6); + assert(memcmp(advance.prev_randao, expected_prev_randao, CMT_WORD_LENGTH) == 0); + assert(advance.index == 7); assert(advance.payload_length == strlen(expected_payload)); assert(memcmp(advance.payload, expected_payload, strlen(expected_payload)) == 0); }