Skip to content

Commit

Permalink
fix: multiple issues
Browse files Browse the repository at this point in the history
update ABI for advance state on libcmt
update ABI for advance state on rollup utility
fix return of cmt_rollup_finish
fix reported request_type of inpect states for rollup utility
  • Loading branch information
diegonehab committed Mar 14, 2024
1 parent 6951d01 commit 6550dbc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
4 changes: 3 additions & 1 deletion sys-utils/libcmt/include/libcmt/rollup.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ typedef struct cmt_rollup {

/** Public struct with the advance state contents */
typedef struct cmt_rollup_advance {
uint8_t sender[CMT_ADDRESS_LENGTH]; /**< the address of the input sender */
uint64_t chain_id; /**< network */
uint8_t app[CMT_ADDRESS_LENGTH]; /**< application address */
uint8_t sender[CMT_ADDRESS_LENGTH]; /**< input sender */
uint64_t block_number; /**< block number of this input */
uint64_t block_timestamp; /**< block timestamp of this input UNIX epoch format) */
uint64_t index; /**< input index (in relation to all inputs ever sent to the DApp) */
Expand Down
12 changes: 11 additions & 1 deletion sys-utils/libcmt/src/ioctl/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int cmt_io_yield(cmt_io_driver_t *_me, struct cmt_io_yield *rr) {

if (enabled) {
fprintf(stderr,
"yield {\n"
"tohost {\n"
"\t.dev = %d,\n"
"\t.cmd = %d,\n"
"\t.reason = %d,\n"
Expand All @@ -125,5 +125,15 @@ int cmt_io_yield(cmt_io_driver_t *_me, struct cmt_io_yield *rr) {
if (ioctl(me->fd, IOCTL_CMIO_YIELD, &req))
return -errno;
*rr = unpack(req);
if (enabled) {
fprintf(stderr,
"fromhost {\n"
"\t.dev = %d,\n"
"\t.cmd = %d,\n"
"\t.reason = %d,\n"
"\t.data = %d,\n"
"};\n",
rr->dev, rr->cmd, rr->reason, rr->data);
}
return 0;
}
19 changes: 13 additions & 6 deletions sys-utils/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
// Notice(bytes)
#define NOTICE CMT_ABI_FUNSEL(0xc2, 0x58, 0xd6, 0xe5)

// EvmAdvance(address,uint256,uint256,uint256,bytes)
#define EVM_ADVANCE CMT_ABI_FUNSEL(0xd2, 0x0c, 0x60, 0xb4)
// EvmAdvance(uint256,address,address,uint256,uint256,uint256,bytes)
#define EVM_ADVANCE CMT_ABI_FUNSEL(0xcc, 0x7d, 0xee, 0x1f)

// EvmInspect(bytes)
#define EVM_INSPECT CMT_ABI_FUNSEL(0x73, 0xd4, 0x41, 0x43)
Expand Down Expand Up @@ -186,10 +186,14 @@ int cmt_rollup_read_advance_state(cmt_rollup_t *me, cmt_rollup_advance_t *advanc
cmt_buf_t of[1];

size_t length = 0;
if (DBG(cmt_abi_check_funsel(rd, EVM_ADVANCE)) || DBG(cmt_abi_get_address(rd, advance->sender)) ||
if (DBG(cmt_abi_check_funsel(rd, EVM_ADVANCE)) ||
DBG(cmt_abi_get_uint(rd, sizeof(advance->chain_id), &advance->chain_id)) ||
DBG(cmt_abi_get_address(rd, advance->app)) ||
DBG(cmt_abi_get_address(rd, advance->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->index), &advance->index)) || DBG(cmt_abi_get_bytes_s(rd, of)) ||
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(st, of, &length, &advance->data)))
return -ENOBUFS;
advance->length = length;
Expand Down Expand Up @@ -253,9 +257,12 @@ int cmt_rollup_finish(cmt_rollup_t *me, cmt_rollup_finish_t *finish) {

cmt_merkle_get_root_hash(me->merkle, cmt_io_get_tx(me->io).begin);
finish->next_request_payload_length = CMT_WORD_LENGTH;
finish->next_request_type = accepted(me->io, &finish->next_request_payload_length);
int reason = accepted(me->io, &finish->next_request_payload_length);
if (reason < 0)
return reason;
finish->next_request_type = reason;
cmt_merkle_init(me->merkle);
return finish->next_request_type;
return 0;
}

int cmt_rollup_progress(cmt_rollup_t *me, uint32_t progress) {
Expand Down
18 changes: 11 additions & 7 deletions sys-utils/rollup/rollup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ static void print_help(void) {
voucher
emit a voucher read from stdin as a JSON object in the format
{"destination": <address>, "value": <string>, "payload": <string>}
where field "destination" contains a 20-byte EVM address in hex.
{"destination": <address>, "value": <value>, "payload": <string>}
where <address> contains a 20-byte EVM address in hex,
and <value> contains an big-endian 32-byte unsigned integer in hex.
if successful, prints to stdout a JSON object in the format
{"index": <number> }
where field "index" is the index allocated for the voucher
Expand Down Expand Up @@ -97,15 +98,17 @@ static void print_help(void) {
field "data" contains a JSON object in the format
{
"metadata": {
"msg_sender": <msg-sender>,
"chain_id": <number>,
"app": <address>,
"sender": <address>,
"epoch_index": <number>,
"input_index": <number>,
"block_number": <number>,
"timestamp": <number>
},
"payload": <string>
},
where field "msg_sender" contains a 20-byte EVM address in hex
where field <address> contains a 20-byte EVM address in hex
when field "request_type" contains "inspect_state",
field "data" contains a JSON object in the format
Expand Down Expand Up @@ -258,8 +261,10 @@ static void write_advance_state(rollup &r, cmt_rollup_finish_t *f) {
nlohmann::json j = {
{"request_type", "advance_state"},
{"data", {
{"chain_id", advance.chain_id},
{"payload", hex(reinterpret_cast<const uint8_t *>(advance.data), advance.length)},
{"msg_sender", hex(advance.sender, sizeof(advance.sender))},
{"app", hex(advance.app, sizeof(advance.app))},
{"sender", hex(advance.sender, sizeof(advance.sender))},
{"block_number", advance.block_number},
{"block_timestamp", advance.block_timestamp},
{"index", advance.index},
Expand All @@ -276,7 +281,7 @@ static void write_inspect_state(rollup &r, cmt_rollup_finish_t *f) {
return;

nlohmann::json j = {
{"request_type", "advance_state"},
{"request_type", "inspect_state"},
{"data", {
{"payload", hex(reinterpret_cast<const uint8_t *>(inspect.data), inspect.length)},
}}
Expand All @@ -291,7 +296,6 @@ static int finish_request_and_get_next(bool accept) try {
f.accept_previous_request = accept;
if (cmt_rollup_finish(r, &f))
return 1;

if (f.next_request_type == CMT_IO_REASON_ADVANCE) {
write_advance_state(r, &f);
} else if (f.next_request_type == CMT_IO_REASON_INSPECT) {
Expand Down

0 comments on commit 6550dbc

Please sign in to comment.