Skip to content

Commit

Permalink
feat!: expose a u256 type
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed May 21, 2024
1 parent 6942b71 commit d471727
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions rollup-http/rollup-http-server/src/rollup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl From<cmt_rollup_advance_t> for AdvanceMetadata {
let mut app_contract = "0x".to_string();
app_contract.push_str(&hex::encode(&other.app_contract));
let mut prev_randao = "0x".to_string();
prev_randao.push_str(&hex::encode(&other.prev_randao));
prev_randao.push_str(&hex::encode(&other.prev_randao.data));
AdvanceMetadata {
chain_id: other.chain_id,
app_contract: app_contract,
Expand Down Expand Up @@ -258,7 +258,9 @@ pub fn rollup_read_advance_state_request(
app_contract: Default::default(),
block_number: 0,
block_timestamp: 0,
prev_randao: Default::default(),
prev_randao: { cmt_u256_t {
data: Default::default(),
}},
index: 0,
payload_length: 0,
payload: std::ptr::null::<::std::os::raw::c_uchar>() as *mut c_void,
Expand Down
2 changes: 1 addition & 1 deletion sys-utils/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +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->prev_randao), advance->prev_randao.data))
|| 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
6 changes: 5 additions & 1 deletion sys-utils/libcmt/src/rollup.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ typedef struct cmt_rollup {
cmt_merkle_t merkle[1];
} cmt_rollup_t;

typedef struct cmt_u256 {
uint8_t data[CMT_WORD_LENGTH];
} cmt_u256_t;

/** Public struct with the advance state contents */
typedef struct cmt_rollup_advance {
uint64_t chain_id; /**< network */
uint8_t app_contract[CMT_ADDRESS_LENGTH]; /**< application contract address */
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 */
cmt_u256_t prev_randao; /**< 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
6 changes: 3 additions & 3 deletions sys-utils/libcmt/tests/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +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] = {
cmt_u256_t expected_prev_randao = {{
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 @@ -79,7 +79,7 @@ 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(memcmp(advance.prev_randao, expected_prev_randao, CMT_WORD_LENGTH) == 0);
assert(memcmp(&advance.prev_randao, expected_prev_randao.data, 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 d471727

Please sign in to comment.