Skip to content

Commit

Permalink
feat!: Add prevrandao field to EvmAdvance
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed May 20, 2024
1 parent 14a2b86 commit 99b9e8a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
5 changes: 3 additions & 2 deletions sys-utils/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))) {
Expand Down
1 change: 1 addition & 0 deletions sys-utils/libcmt/src/rollup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion sys-utils/libcmt/tests/create-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ echo "#ifndef DATA_H"
echo "#define DATA_H"
echo "#include <stdint.h>"
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 "};"

Expand Down
12 changes: 7 additions & 5 deletions sys-utils/libcmt/tests/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define DATA_H
#include <stdint.h>
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,
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion sys-utils/libcmt/tests/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
}
Expand Down

0 comments on commit 99b9e8a

Please sign in to comment.