From 6942b717d8e3085fce03b9f61dbdc88a0f7f959b Mon Sep 17 00:00:00 2001 From: Diego Nehab <1635557+diegonehab@users.noreply.github.com> Date: Mon, 20 May 2024 17:04:57 +0100 Subject: [PATCH] fix: rollup-http-server and rollup util --- .../rollup-http-server/src/rollup/mod.rs | 26 ++++++++++++++----- sys-utils/rollup/rollup.cpp | 10 ++++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/rollup-http/rollup-http-server/src/rollup/mod.rs b/rollup-http/rollup-http-server/src/rollup/mod.rs index 646be3e3..d631b1aa 100644 --- a/rollup-http/rollup-http-server/src/rollup/mod.rs +++ b/rollup-http/rollup-http-server/src/rollup/mod.rs @@ -127,23 +127,36 @@ pub struct GIOResponse { pub response: String, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Validate)] pub struct AdvanceMetadata { + pub chain_id: u64, + #[validate(regex = "ETH_ADDR_REGEXP")] + pub app_contract: String, + #[validate(regex = "ETH_ADDR_REGEXP")] pub msg_sender: String, - pub input_index: u64, pub block_number: u64, pub block_timestamp: u64, + #[validate(regex = "ETH_U256_REGEXP")] + pub prev_randao: String, + pub input_index: u64, } impl From for AdvanceMetadata { fn from(other: cmt_rollup_advance_t) -> Self { - let mut address = "0x".to_string(); - address.push_str(&hex::encode(&other.msg_sender)); + let mut msg_sender = "0x".to_string(); + msg_sender.push_str(&hex::encode(&other.msg_sender)); + 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)); AdvanceMetadata { - input_index: other.index, + chain_id: other.chain_id, + app_contract: app_contract, + msg_sender: msg_sender, block_timestamp: other.block_timestamp, block_number: other.block_number, - msg_sender: address, + input_index: other.index, + prev_randao: prev_randao, } } } @@ -245,6 +258,7 @@ pub fn rollup_read_advance_state_request( app_contract: Default::default(), block_number: 0, block_timestamp: 0, + prev_randao: Default::default(), index: 0, payload_length: 0, payload: std::ptr::null::<::std::os::raw::c_uchar>() as *mut c_void, diff --git a/sys-utils/rollup/rollup.cpp b/sys-utils/rollup/rollup.cpp index b7b66337..67ab22e7 100644 --- a/sys-utils/rollup/rollup.cpp +++ b/sys-utils/rollup/rollup.cpp @@ -103,14 +103,15 @@ static void print_help(void) { "chain_id": , "app_contract":
, "msg_sender":
, - "epoch_index": , - "input_index": , "block_number": , "block_timestamp": + "prev_randao": , + "index": , "payload": }, where -
contains a 20-byte EVM address in hex, and +
contains a 20-byte EVM address in hex, + contains a big-endian 32-byte unsigned integer in hex, and contains arbitrary data in hex when field "request_type" contains "inspect_state", @@ -292,12 +293,13 @@ static int write_advance_state(rollup &r, const cmt_rollup_finish_t *f) { {"data", { {"chain_id", advance.chain_id}, - {"payload", hex(reinterpret_cast(advance.payload), advance.payload_length)}, {"app_contract", hex(advance.app_contract, sizeof(advance.app_contract))}, {"msg_sender", hex(advance.msg_sender, sizeof(advance.msg_sender))}, {"block_number", advance.block_number}, {"block_timestamp", advance.block_timestamp}, + {"prev_randao", hex(advance.prev_randao, sizeof(advance.prev_randao))}, {"index", advance.index}, + {"payload", hex(reinterpret_cast(advance.payload), advance.payload_length)}, }}}; std::cout << j.dump(2) << '\n'; return 0;