diff --git a/sys-utils/libcmt/src/abi.h b/sys-utils/libcmt/src/abi.h index 8a1fd718..8c6042fd 100644 --- a/sys-utils/libcmt/src/abi.h +++ b/sys-utils/libcmt/src/abi.h @@ -501,4 +501,3 @@ int cmt_abi_decode_uint_nn(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_ #endif /* CMT_ABI_H */ /** @} */ - diff --git a/sys-utils/libcmt/src/buf.h b/sys-utils/libcmt/src/buf.h index 230b5e18..549d589a 100644 --- a/sys-utils/libcmt/src/buf.h +++ b/sys-utils/libcmt/src/buf.h @@ -80,4 +80,3 @@ bool cmt_buf_split_by_comma(cmt_buf_t *x, cmt_buf_t *xs); #endif /* CMT_BUF_H */ /** @} */ - diff --git a/sys-utils/libcmt/src/io-mock.c b/sys-utils/libcmt/src/io-mock.c index adc13703..44b7f60e 100644 --- a/sys-utils/libcmt/src/io-mock.c +++ b/sys-utils/libcmt/src/io-mock.c @@ -22,7 +22,6 @@ #include #include - static int read_whole_file(const char *name, size_t max, void *data, size_t *length); static int write_whole_file(const char *name, size_t length, const void *data); @@ -116,8 +115,8 @@ static int store_output(cmt_io_driver_mock_t *me, const char *filepath, struct c if (rr->data > cmt_buf_length(me->tx)) return -ENOBUFS; - //char filepath[128 + 1 + 8 + 16]; - //snprintf(filepath, sizeof filepath, "%s.%s%d%s", me->input_filename, ns, *seq, me->input_fileext); + // char filepath[128 + 1 + 8 + 16]; + // snprintf(filepath, sizeof filepath, "%s.%s%d%s", me->input_filename, ns, *seq, me->input_fileext); int rc = write_whole_file(filepath, rr->data, me->tx->begin); if (rc) { @@ -128,7 +127,7 @@ static int store_output(cmt_io_driver_mock_t *me, const char *filepath, struct c fprintf(stderr, "wrote filename: \"%s\" (%u)\n", filepath, rr->data); } - //seq[0] += 1; + // seq[0] += 1; return 0; } @@ -155,10 +154,10 @@ static int mock_rx_accepted(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) { } if (me->input_seq++) { // skip the first char filepath[128 + 32 + 8 + 16]; - snprintf(filepath, sizeof filepath, - "%s.outputs_root_hash%s", me->input_filename, me->input_fileext); + snprintf(filepath, sizeof filepath, "%s.outputs_root_hash%s", me->input_filename, me->input_fileext); int rc = store_output(me, filepath, rr); - if (rc) return rc; + if (rc) + return rc; } if (load_next_input(me, rr)) return -ENODATA; diff --git a/sys-utils/libcmt/src/io.c b/sys-utils/libcmt/src/io.c index ed078bfd..a3476361 100644 --- a/sys-utils/libcmt/src/io.c +++ b/sys-utils/libcmt/src/io.c @@ -28,7 +28,6 @@ #include - int cmt_io_init(cmt_io_driver_t *_me) { int rc = 0; @@ -95,7 +94,7 @@ cmt_buf_t cmt_io_get_tx(cmt_io_driver_t *me) { } static uint32_t min(uint32_t a, uint32_t b) { - return a < b? a: b; + return a < b ? a : b; } cmt_buf_t cmt_io_get_rx(cmt_io_driver_t *me) { diff --git a/sys-utils/libcmt/src/io.h b/sys-utils/libcmt/src/io.h index 29d8a47a..b38e8f39 100644 --- a/sys-utils/libcmt/src/io.h +++ b/sys-utils/libcmt/src/io.h @@ -70,16 +70,16 @@ enum { /** Automatic reasons */ enum { - HTIF_YIELD_AUTOMATIC_REASON_PROGRESS = 1, /**< Progress */ - HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT = 2, /**< emit an output */ - HTIF_YIELD_AUTOMATIC_REASON_TX_REPORT = 4, /**< emit a report */ + HTIF_YIELD_AUTOMATIC_REASON_PROGRESS = 1, /**< Progress */ + HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT = 2, /**< emit an output */ + HTIF_YIELD_AUTOMATIC_REASON_TX_REPORT = 4, /**< emit a report */ }; /** Manual reasons */ enum { - HTIF_YIELD_MANUAL_REASON_RX_ACCEPTED = 1, /**< Accept and load next input */ - HTIF_YIELD_MANUAL_REASON_RX_REJECTED = 2, /**< Reject and revert */ - HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION = 4, /**< emit a exception and halt execution */ + HTIF_YIELD_MANUAL_REASON_RX_ACCEPTED = 1, /**< Accept and load next input */ + HTIF_YIELD_MANUAL_REASON_RX_REJECTED = 2, /**< Reject and revert */ + HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION = 4, /**< emit a exception and halt execution */ }; /** Reply reason when requesting @ref HTIF_YIELD_REASON_RX_ACCEPTED or HTIF_YIELD_REASON_RX_REJECTED */ @@ -165,4 +165,3 @@ cmt_buf_t cmt_io_get_rx(cmt_io_driver_t *me); int cmt_io_yield(cmt_io_driver_t *me, cmt_io_yield_t *rr); #endif /* CMT_IO_H */ - diff --git a/sys-utils/libcmt/src/keccak.c b/sys-utils/libcmt/src/keccak.c index 86d1b63e..03fd9258 100644 --- a/sys-utils/libcmt/src/keccak.c +++ b/sys-utils/libcmt/src/keccak.c @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "abi.h" #include "keccak.h" +#include "abi.h" #include diff --git a/sys-utils/libcmt/src/keccak.h b/sys-utils/libcmt/src/keccak.h index 6e6ce83a..96ec0812 100644 --- a/sys-utils/libcmt/src/keccak.h +++ b/sys-utils/libcmt/src/keccak.h @@ -129,4 +129,3 @@ uint8_t *cmt_keccak_data(size_t length, const void *data, uint8_t md[CMT_KECCAK_ uint32_t cmt_keccak_funsel(const char *decl); #endif /* CMT_KECCAK_H */ /** $@} */ - diff --git a/sys-utils/libcmt/src/merkle.c b/sys-utils/libcmt/src/merkle.c index f70d9cfd..79d7df55 100644 --- a/sys-utils/libcmt/src/merkle.c +++ b/sys-utils/libcmt/src/merkle.c @@ -21,6 +21,7 @@ #include #include +// clang-format off static const uint8_t pristine_hash[CMT_MERKLE_TREE_HEIGHT+1][CMT_KECCAK_LENGTH] = { {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}, {0xad,0x32,0x28,0xb6,0x76,0xf7,0xd3,0xcd,0x42,0x84,0xa5,0x44,0x3f,0x17,0xf1,0x96,0x2b,0x36,0xe4,0x91,0xb3,0x0a,0x40,0xb2,0x40,0x58,0x49,0xe5,0x97,0xba,0x5f,0xb5}, @@ -88,6 +89,7 @@ static const uint8_t pristine_hash[CMT_MERKLE_TREE_HEIGHT+1][CMT_KECCAK_LENGTH] {0x0a,0x16,0x29,0x46,0xe5,0x61,0x58,0xba,0xc0,0x67,0x3e,0x6d,0xd3,0xbd,0xfd,0xc1,0xe4,0xa0,0xe7,0x74,0x4a,0x12,0x0f,0xdb,0x64,0x00,0x50,0xc8,0xd7,0xab,0xe1,0xc6}, {0xe2,0xc3,0xed,0x40,0x52,0xee,0xb1,0xd6,0x05,0x14,0xb4,0xc3,0x8e,0xce,0x8d,0x73,0xa2,0x7f,0x37,0xfa,0x5b,0x36,0xdc,0xbf,0x33,0x8e,0x70,0xde,0x95,0x79,0x8c,0xaa} }; +// clang-format on static void copy_hash(const uint8_t src[CMT_KECCAK_LENGTH], uint8_t out[CMT_KECCAK_LENGTH]) { memcpy(out, src, CMT_KECCAK_LENGTH); @@ -173,7 +175,7 @@ int cmt_merkle_push_back(cmt_merkle_t *me, const uint8_t hash[CMT_KECCAK_LENGTH] if (me->leaf_count & bit) { /* ...concat it with current running right and replace running right with it. */ concat_hash(me->state[i], right, right); - /* otherwise... */ + /* otherwise... */ } else { /* ...just copy the current subtree hash to the state and we are done. */ copy_hash(right, me->state[i]); @@ -192,7 +194,7 @@ void cmt_merkle_get_root_hash(cmt_merkle_t *me, uint8_t root[CMT_KECCAK_LENGTH]) if (me->leaf_count & bit) { /* ...concat it with current root on the right and replace root */ concat_hash(me->state[i], root, root); - /* otherwise... */ + /* otherwise... */ } else { /* ...concat root with pristine tree on the right and replace root */ concat_hash(root, pristine_hash[i], root); diff --git a/sys-utils/libcmt/src/merkle.h b/sys-utils/libcmt/src/merkle.h index 08a231eb..eb2a0d29 100644 --- a/sys-utils/libcmt/src/merkle.h +++ b/sys-utils/libcmt/src/merkle.h @@ -30,7 +30,7 @@ enum { /** Opaque Merkle tree state. * initialize with: @ref cmt_merkle_init */ typedef struct { - uint64_t leaf_count; /**< number of leaves in tree */ + uint64_t leaf_count; /**< number of leaves in tree */ uint8_t state[CMT_MERKLE_TREE_HEIGHT][CMT_KECCAK_LENGTH]; /**< hashes of complete subtrees */ } cmt_merkle_t; @@ -100,4 +100,3 @@ int cmt_merkle_push_back_data(cmt_merkle_t *me, size_t length, const void *data) void cmt_merkle_get_root_hash(cmt_merkle_t *me, uint8_t root[CMT_KECCAK_LENGTH]); #endif /* CMT_MERKLE_H */ - diff --git a/sys-utils/libcmt/src/rollup.c b/sys-utils/libcmt/src/rollup.c index d29d90a9..7693dd3b 100644 --- a/sys-utils/libcmt/src/rollup.c +++ b/sys-utils/libcmt/src/rollup.c @@ -25,7 +25,7 @@ #include // Voucher(address,uint256,bytes) -#define VOUCHER CMT_ABI_FUNSEL(0x23, 0x7a, 0x81, 0x6f) +#define VOUCHER CMT_ABI_FUNSEL(0x23, 0x7a, 0x81, 0x6f) // Notice(bytes) #define NOTICE CMT_ABI_FUNSEL(0xc2, 0x58, 0xd6, 0xe5) @@ -72,10 +72,8 @@ void cmt_rollup_fini(cmt_rollup_t *me) { cmt_merkle_fini(me->merkle); } -int cmt_rollup_emit_voucher(cmt_rollup_t *me, - uint32_t address_length, const void *address_data, - uint32_t value_length, const void *value_data, - uint32_t length, const void *data, uint64_t *index) { +int cmt_rollup_emit_voucher(cmt_rollup_t *me, uint32_t address_length, const void *address_data, uint32_t value_length, + const void *value_data, uint32_t length, const void *data, uint64_t *index) { if (!me) return -EINVAL; if (!data && length) @@ -86,11 +84,9 @@ int cmt_rollup_emit_voucher(cmt_rollup_t *me, cmt_buf_t of[1]; void *params_base = tx->begin + 4; // after funsel - if (DBG(cmt_abi_put_funsel(wr, VOUCHER)) - || DBG(cmt_abi_put_uint_be(wr, address_length, address_data)) - || DBG(cmt_abi_put_uint_be(wr, value_length, value_data)) - || DBG(cmt_abi_put_bytes_s(wr, of)) - || DBG(cmt_abi_put_bytes_d(wr, of, length, data, params_base))) + if (DBG(cmt_abi_put_funsel(wr, VOUCHER)) || DBG(cmt_abi_put_uint_be(wr, address_length, address_data)) || + DBG(cmt_abi_put_uint_be(wr, value_length, value_data)) || DBG(cmt_abi_put_bytes_s(wr, of)) || + DBG(cmt_abi_put_bytes_d(wr, of, length, data, params_base))) return -ENOBUFS; size_t m = wr->begin - tx->begin; @@ -209,12 +205,10 @@ int cmt_rollup_read_advance_state(cmt_rollup_t *me, cmt_rollup_advance_t *advanc size_t payload_length = 0; 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_contract)) || - DBG(cmt_abi_get_address(rd, advance->msg_sender)) || + DBG(cmt_abi_get_address(rd, advance->app_contract)) || 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->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, &payload_length, &advance->payload))) return -ENOBUFS; advance->payload_length = payload_length; diff --git a/sys-utils/libcmt/src/rollup.h b/sys-utils/libcmt/src/rollup.h index 87eed5cf..aadf59d8 100644 --- a/sys-utils/libcmt/src/rollup.h +++ b/sys-utils/libcmt/src/rollup.h @@ -68,12 +68,12 @@ typedef struct cmt_rollup_finish { /** Public struct with generic io request/response */ typedef struct cmt_gio { - uint16_t domain; /**< domain for the gio request */ - uint32_t id_length; /**< length of id */ - void *id; /**< id for the request */ - uint16_t response_code; /**< response */ - uint32_t response_length; /**< length of response data */ - void *response; /**< response data */ + uint16_t domain; /**< domain for the gio request */ + uint32_t id_length; /**< length of id */ + void *id; /**< id for the request */ + uint16_t response_code; /**< response */ + uint32_t response_length; /**< length of response data */ + void *response; /**< response data */ } cmt_gio_request_t; /** Initialize a @ref cmt_rollup_t state. @@ -113,10 +113,8 @@ void cmt_rollup_fini(cmt_rollup_t *me); * |--:|-----------------------------| * | 0| success | * |< 0| failure with a -errno value | */ -int cmt_rollup_emit_voucher(cmt_rollup_t *me, - uint32_t address_length, const void *address_data, - uint32_t value_length, const void *value_data, - uint32_t length, const void *data, uint64_t *index); +int cmt_rollup_emit_voucher(cmt_rollup_t *me, uint32_t address_length, const void *address_data, uint32_t value_length, + const void *value_data, uint32_t length, const void *data, uint64_t *index); /** Emit a notice * @@ -130,8 +128,7 @@ int cmt_rollup_emit_voucher(cmt_rollup_t *me, * |--:|-----------------------------| * | 0| success | * |< 0| failure with a -errno value | */ -int cmt_rollup_emit_notice(cmt_rollup_t *me, - uint32_t data_length, const void *data, uint64_t *index); +int cmt_rollup_emit_notice(cmt_rollup_t *me, uint32_t data_length, const void *data, uint64_t *index); /** Emit a report * @param [in,out] me initialized cmt_rollup_t instance @@ -143,8 +140,7 @@ int cmt_rollup_emit_notice(cmt_rollup_t *me, * |--:|-----------------------------| * | 0| success | * |< 0| failure with a -errno value | */ -int cmt_rollup_emit_report(cmt_rollup_t *me, - uint32_t data_length, const void *data); +int cmt_rollup_emit_report(cmt_rollup_t *me, uint32_t data_length, const void *data); /** Emit a exception * @param [in,out] me initialized cmt_rollup_t instance @@ -156,8 +152,7 @@ int cmt_rollup_emit_report(cmt_rollup_t *me, * |--:|-----------------------------| * | 0| success | * |< 0| failure with a -errno value | */ -int cmt_rollup_emit_exception(cmt_rollup_t *me, - uint32_t data_length, const void *data); +int cmt_rollup_emit_exception(cmt_rollup_t *me, uint32_t data_length, const void *data); /** Read advance state * @@ -196,7 +191,6 @@ int cmt_rollup_read_inspect_state(cmt_rollup_t *me, cmt_rollup_inspect_t *inspec * |< 0| failure with a -errno value | */ int cmt_rollup_finish(cmt_rollup_t *me, cmt_rollup_finish_t *finish); - /** Performs a generic IO request * * @param [in,out] me initialized cmt_rollup_t instance @@ -238,4 +232,3 @@ int cmt_rollup_save_merkle(cmt_rollup_t *me, const char *path); int cmt_rollup_reset_merkle(cmt_rollup_t *me); #endif /* CMT_ROLLUP_H */ - diff --git a/sys-utils/libcmt/tests/abi-single.c b/sys-utils/libcmt/tests/abi-single.c index e97c235f..ebb04cc0 100644 --- a/sys-utils/libcmt/tests/abi-single.c +++ b/sys-utils/libcmt/tests/abi-single.c @@ -41,10 +41,38 @@ static void encode_u8() { uint8_t x = 0x01; uint8_t en[CMT_WORD_LENGTH]; uint8_t be[CMT_WORD_LENGTH] = { - 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, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, }; cmt_abi_encode_uint(sizeof(x), (void *) &x, en); assert(memcmp(en, be, sizeof(be)) == 0); @@ -54,10 +82,38 @@ static void encode_u16() { uint16_t x = UINT16_C(0x0123); uint8_t en[CMT_WORD_LENGTH]; uint8_t be[CMT_WORD_LENGTH] = { - 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, 0x23, + 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, + 0x23, }; cmt_abi_encode_uint(sizeof(x), (void *) &x, en); assert(memcmp(en, be, sizeof(be)) == 0); @@ -67,10 +123,38 @@ static void encode_u32() { uint32_t x = UINT32_C(0x01234567); uint8_t en[CMT_WORD_LENGTH]; uint8_t be[CMT_WORD_LENGTH] = { - 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, 0x23, 0x45, 0x67, + 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, + 0x23, + 0x45, + 0x67, }; cmt_abi_encode_uint(sizeof(x), (void *) &x, en); assert(memcmp(en, be, sizeof(be)) == 0); @@ -80,10 +164,38 @@ static void encode_u64() { uint64_t x = UINT64_C(0x0123456789abcdef); uint8_t en[CMT_WORD_LENGTH]; uint8_t be[CMT_WORD_LENGTH] = { - 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, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 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, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, }; cmt_abi_encode_uint(sizeof(x), (void *) &x, en); assert(memcmp(en, be, sizeof(be)) == 0); @@ -91,17 +203,73 @@ static void encode_u64() { static void encode_u256() { uint8_t x[CMT_WORD_LENGTH] = { - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, + 0x1f, + 0x1e, + 0x1d, + 0x1c, + 0x1b, + 0x1a, + 0x19, + 0x18, + 0x17, + 0x16, + 0x15, + 0x14, + 0x13, + 0x12, + 0x11, + 0x10, + 0x0f, + 0x0e, + 0x0d, + 0x0c, + 0x0b, + 0x0a, + 0x09, + 0x08, + 0x07, + 0x06, + 0x05, + 0x04, + 0x03, + 0x02, + 0x01, + 0x00, }; uint8_t en[CMT_WORD_LENGTH]; uint8_t be[CMT_WORD_LENGTH] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x06, + 0x07, + 0x08, + 0x09, + 0x0a, + 0x0b, + 0x0c, + 0x0d, + 0x0e, + 0x0f, + 0x10, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0x16, + 0x17, + 0x18, + 0x19, + 0x1a, + 0x1b, + 0x1c, + 0x1d, + 0x1e, + 0x1f, }; cmt_abi_encode_uint(sizeof(x), (void *) &x, en); assert(memcmp(en, be, sizeof(be)) == 0); @@ -109,10 +277,38 @@ static void encode_u256() { static void encode_edom() { uint8_t x[CMT_WORD_LENGTH + 1] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x06, + 0x07, + 0x08, + 0x09, + 0x0a, + 0x0b, + 0x0c, + 0x0d, + 0x0e, + 0x0f, + 0x10, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0x16, + 0x17, + 0x18, + 0x19, + 0x1a, + 0x1b, + 0x1c, + 0x1d, + 0x1e, + 0x1f, 0x20, }; uint8_t en[CMT_WORD_LENGTH]; @@ -123,10 +319,38 @@ static void encode_edom() { static void decode_u8() { uint8_t x, ex = 0x01; uint8_t be[CMT_WORD_LENGTH] = { - 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, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, }; assert(cmt_abi_decode_uint(be, sizeof(x), (void *) &x) == 0); assert(x == ex); @@ -135,10 +359,38 @@ static void decode_u8() { static void decode_u16() { uint16_t x, ex = UINT16_C(0x0123); uint8_t be[CMT_WORD_LENGTH] = { - 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, 0x23, + 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, + 0x23, }; assert(cmt_abi_decode_uint(be, sizeof(x), (void *) &x) == 0); assert(x == ex); @@ -147,10 +399,38 @@ static void decode_u16() { static void decode_u32() { uint32_t x, ex = UINT32_C(0x01234567); uint8_t be[CMT_WORD_LENGTH] = { - 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, 0x23, 0x45, 0x67, + 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, + 0x23, + 0x45, + 0x67, }; assert(cmt_abi_decode_uint(be, sizeof(x), (void *) &x) == 0); assert(x == ex); @@ -159,10 +439,38 @@ static void decode_u32() { static void decode_u64() { uint64_t x, ex = UINT64_C(0x0123456789abcdef); uint8_t be[CMT_WORD_LENGTH] = { - 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, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 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, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, }; assert(cmt_abi_decode_uint(be, sizeof(x), (void *) &x) == 0); assert(x == ex); @@ -171,16 +479,72 @@ static void decode_u64() { static void decode_u256() { uint8_t x[CMT_WORD_LENGTH], ex[CMT_WORD_LENGTH] = { - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, + 0x1f, + 0x1e, + 0x1d, + 0x1c, + 0x1b, + 0x1a, + 0x19, + 0x18, + 0x17, + 0x16, + 0x15, + 0x14, + 0x13, + 0x12, + 0x11, + 0x10, + 0x0f, + 0x0e, + 0x0d, + 0x0c, + 0x0b, + 0x0a, + 0x09, + 0x08, + 0x07, + 0x06, + 0x05, + 0x04, + 0x03, + 0x02, + 0x01, + 0x00, }; uint8_t be[CMT_WORD_LENGTH] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x06, + 0x07, + 0x08, + 0x09, + 0x0a, + 0x0b, + 0x0c, + 0x0d, + 0x0e, + 0x0f, + 0x10, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0x16, + 0x17, + 0x18, + 0x19, + 0x1a, + 0x1b, + 0x1c, + 0x1d, + 0x1e, + 0x1f, }; assert(cmt_abi_decode_uint(be, sizeof(x), x) == 0); assert(memcmp(x, ex, sizeof(ex)) == 0); @@ -190,10 +554,38 @@ static void decode_u256() { static void decode_edom() { uint64_t x; uint8_t be[CMT_WORD_LENGTH] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, - 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xAA, + 0x01, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, }; assert(cmt_abi_decode_uint(be, sizeof(x), (void *) &x) == -EDOM); } @@ -211,10 +603,38 @@ static void put_funsel() { static void put_uint() { uint64_t x = UINT64_C(0x0123456789abcdef); uint8_t be[CMT_WORD_LENGTH] = { - 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, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 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, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, }; CMT_BUF_DECL(b, 64); cmt_buf_t it[1] = {*b}; @@ -224,16 +644,41 @@ static void put_uint() { } static void put_address() { - uint8_t x[20] = { - 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0x01, 0x23, 0x45, 0x67 - }; + uint8_t x[20] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0x01, 0x23, 0x45, 0x67}; uint8_t be[CMT_WORD_LENGTH] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x23, 0x45, 0x67, - 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, - 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, + 0x01, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, + 0x01, + 0x23, + 0x45, + 0x67, }; CMT_BUF_DECL(b, 64); cmt_buf_t it[1] = {*b}; @@ -245,16 +690,86 @@ static void put_address() { static void put_bytes() { uint64_t x = UINT64_C(0x0123456789abcdef); uint8_t be[] = { - 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, 0x20, - 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, 0x08, - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 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, + 0x00, + 0x00, + 0x00, + 0x20, + 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, + 0x08, + 0xef, + 0xcd, + 0xab, + 0x89, + 0x67, + 0x45, + 0x23, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, }; CMT_BUF_DECL(b, 128); cmt_buf_t it[1] = {*b}, of[1]; @@ -277,10 +792,38 @@ static void get_funsel() { static void get_uint() { uint64_t x, ex = UINT64_C(0x0123456789abcdef); uint8_t be[CMT_WORD_LENGTH] = { - 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, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 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, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, }; CMT_BUF_DECL3(b, sizeof(be), be); cmt_buf_t rd[1] = {*b}; @@ -291,16 +834,41 @@ static void get_uint() { static void get_address() { uint8_t x[20]; - uint8_t ex[20] = { - 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0x01, 0x23, 0x45, 0x67 - }; + uint8_t ex[20] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0x01, 0x23, 0x45, 0x67}; uint8_t be[CMT_WORD_LENGTH] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x23, 0x45, 0x67, - 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, - 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, + 0x01, + 0x23, + 0x45, + 0x67, + 0x89, + 0xab, + 0xcd, + 0xef, + 0x01, + 0x23, + 0x45, + 0x67, }; CMT_BUF_DECL3(b, sizeof(be), be); cmt_buf_t it[1] = {*b}; @@ -312,16 +880,86 @@ static void get_address() { static void get_bytes() { uint64_t ex = UINT64_C(0x0123456789abcdef); uint8_t be[] = { - 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, 0x20, - 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, 0x08, - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 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, + 0x00, + 0x00, + 0x00, + 0x20, + 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, + 0x08, + 0xef, + 0xcd, + 0xab, + 0x89, + 0x67, + 0x45, + 0x23, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, }; CMT_BUF_DECL3(b, sizeof(be), be); cmt_buf_t it[1] = {*b}, of[1], bytes[1]; diff --git a/sys-utils/libcmt/tests/keccak.c b/sys-utils/libcmt/tests/keccak.c index c42aa086..baf02a13 100644 --- a/sys-utils/libcmt/tests/keccak.c +++ b/sys-utils/libcmt/tests/keccak.c @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "abi.h" #include "keccak.h" +#include "abi.h" #include #include diff --git a/sys-utils/libcmt/tests/rollup_echo.c b/sys-utils/libcmt/tests/rollup_echo.c index e9651b2a..b021897a 100644 --- a/sys-utils/libcmt/tests/rollup_echo.c +++ b/sys-utils/libcmt/tests/rollup_echo.c @@ -40,10 +40,38 @@ int main(void) { // cmt_rollup_load_merkle(rollup, "/tmp/merkle.dat"); uint8_t small[] = { - 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, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, }; for (;;) { int rc; @@ -62,7 +90,8 @@ int main(void) { break; } - rc = cmt_rollup_emit_voucher(&rollup, sizeof advance.msg_sender, advance.msg_sender, sizeof small, small, advance.payload_length, advance.payload, NULL); + rc = cmt_rollup_emit_voucher(&rollup, sizeof advance.msg_sender, advance.msg_sender, sizeof small, + small, advance.payload_length, advance.payload, NULL); if (rc < 0) { fprintf(stderr, "%s:%d Error on voucher %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc)); break;