diff --git a/sys-utils/libcmt/include/libcmt/abi.h b/sys-utils/libcmt/include/libcmt/abi.h index d0ab0ea..2b3a55c 100644 --- a/sys-utils/libcmt/include/libcmt/abi.h +++ b/sys-utils/libcmt/include/libcmt/abi.h @@ -115,7 +115,7 @@ #include enum { - CMT_WORD_LENGTH = 32, /**< length of a evm word in bytes */ + CMT_ABI_U256_LENGTH = 32, /**< length of a evm word in bytes */ CMT_ADDRESS_LENGTH = 20, /**< length of a evm address in bytes */ }; @@ -136,7 +136,7 @@ typedef struct cmt_abi_address { /** EVM u256 in big endian format */ typedef struct cmt_abi_u256 { - uint8_t data[CMT_WORD_LENGTH]; + uint8_t data[CMT_ABI_U256_LENGTH]; } cmt_abi_u256_t; typedef struct cmt_abi_bytes { @@ -522,7 +522,7 @@ int cmt_abi_peek_bytes_d(const cmt_buf_t *start, cmt_buf_t of[1], cmt_buf_t *byt * |-------:|---------------------------------------------------| * | 0| success | * | -EDOM| integer not representable in @p data_length bytes | */ -int cmt_abi_encode_uint(size_t n, const void *data, uint8_t out[CMT_WORD_LENGTH]); +int cmt_abi_encode_uint(size_t n, const void *data, uint8_t out[CMT_ABI_U256_LENGTH]); /** Encode @p n bytes of @p data into @p out (up to 32) in reverse order. * @@ -537,7 +537,7 @@ int cmt_abi_encode_uint(size_t n, const void *data, uint8_t out[CMT_WORD_LENGTH] * | -EDOM| integer not representable in @p data_length bytes | * * @note use @ref cmt_abi_encode_uint instead */ -int cmt_abi_encode_uint_nr(size_t n, const uint8_t *data, uint8_t out[CMT_WORD_LENGTH]); +int cmt_abi_encode_uint_nr(size_t n, const uint8_t *data, uint8_t out[CMT_ABI_U256_LENGTH]); /** Encode @p n bytes of @p data into @p out (up to 32) in normal order. * @@ -552,7 +552,7 @@ int cmt_abi_encode_uint_nr(size_t n, const uint8_t *data, uint8_t out[CMT_WORD_L * | -EDOM| integer not representable in @p data_length bytes | * * @note use @ref cmt_abi_encode_uint instead */ -int cmt_abi_encode_uint_nn(size_t n, const uint8_t *data, uint8_t out[CMT_WORD_LENGTH]); +int cmt_abi_encode_uint_nn(size_t n, const uint8_t *data, uint8_t out[CMT_ABI_U256_LENGTH]); /** Decode @p n bytes of @p data into @p out (up to 32). * @@ -565,7 +565,7 @@ int cmt_abi_encode_uint_nn(size_t n, const uint8_t *data, uint8_t out[CMT_WORD_L * |-------:|---------------------------------------------------| * | 0| success | * | -EDOM| integer not representable in @p data_length bytes | */ -int cmt_abi_decode_uint(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_t *out); +int cmt_abi_decode_uint(const uint8_t data[CMT_ABI_U256_LENGTH], size_t n, uint8_t *out); /** Decode @p n bytes of @p data into @p out (up to 32) in reverse order. * @@ -580,7 +580,7 @@ int cmt_abi_decode_uint(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_t * * | -EDOM| integer not representable in @p data_length bytes | * * @note if in doubt, use @ref cmt_abi_decode_uint */ -int cmt_abi_decode_uint_nr(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_t *out); +int cmt_abi_decode_uint_nr(const uint8_t data[CMT_ABI_U256_LENGTH], size_t n, uint8_t *out); /** Decode @p n bytes of @p data into @p out (up to 32) in normal order. * @@ -595,7 +595,7 @@ int cmt_abi_decode_uint_nr(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_ * | -EDOM| integer not representable in @p data_length bytes | * * @note if in doubt, use @ref cmt_abi_decode_uint */ -int cmt_abi_decode_uint_nn(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_t *out); +int cmt_abi_decode_uint_nn(const uint8_t data[CMT_ABI_U256_LENGTH], size_t n, uint8_t *out); #endif /* CMT_ABI_H */ /** @} */ diff --git a/sys-utils/libcmt/src/abi.c b/sys-utils/libcmt/src/abi.c index f7ccc89..9fdec72 100644 --- a/sys-utils/libcmt/src/abi.c +++ b/sys-utils/libcmt/src/abi.c @@ -45,33 +45,33 @@ int cmt_abi_put_funsel(cmt_buf_t *me, uint32_t funsel) { return 0; } -int cmt_abi_encode_uint_nr(size_t n, const uint8_t *data, uint8_t out[CMT_WORD_LENGTH]) { - if (n > CMT_WORD_LENGTH) { +int cmt_abi_encode_uint_nr(size_t n, const uint8_t *data, uint8_t out[CMT_ABI_U256_LENGTH]) { + if (n > CMT_ABI_U256_LENGTH) { return -EDOM; } for (size_t i = 0; i < n; ++i) { - out[CMT_WORD_LENGTH - 1 - i] = data[i]; + out[CMT_ABI_U256_LENGTH - 1 - i] = data[i]; } - for (size_t i = n; i < CMT_WORD_LENGTH; ++i) { - out[CMT_WORD_LENGTH - 1 - i] = 0; + for (size_t i = n; i < CMT_ABI_U256_LENGTH; ++i) { + out[CMT_ABI_U256_LENGTH - 1 - i] = 0; } return 0; } -int cmt_abi_encode_uint_nn(size_t n, const uint8_t *data, uint8_t out[CMT_WORD_LENGTH]) { - if (n > CMT_WORD_LENGTH) { +int cmt_abi_encode_uint_nn(size_t n, const uint8_t *data, uint8_t out[CMT_ABI_U256_LENGTH]) { + if (n > CMT_ABI_U256_LENGTH) { return -EDOM; } - for (size_t i = 0; i < CMT_WORD_LENGTH - n; ++i) { + for (size_t i = 0; i < CMT_ABI_U256_LENGTH - n; ++i) { out[i] = 0; } - for (size_t i = CMT_WORD_LENGTH - n; i < CMT_WORD_LENGTH; ++i) { - out[i] = data[i - CMT_WORD_LENGTH + n]; + for (size_t i = CMT_ABI_U256_LENGTH - n; i < CMT_ABI_U256_LENGTH; ++i) { + out[i] = data[i - CMT_ABI_U256_LENGTH + n]; } return 0; } -int cmt_abi_encode_uint(size_t n, const void *data, uint8_t out[CMT_WORD_LENGTH]) { +int cmt_abi_encode_uint(size_t n, const void *data, uint8_t out[CMT_ABI_U256_LENGTH]) { #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ return cmt_abi_encode_uint_nn(n, data, out); #else @@ -79,37 +79,37 @@ int cmt_abi_encode_uint(size_t n, const void *data, uint8_t out[CMT_WORD_LENGTH] #endif } -int cmt_abi_decode_uint_nr(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_t *out) { - if (n > CMT_WORD_LENGTH) { +int cmt_abi_decode_uint_nr(const uint8_t data[CMT_ABI_U256_LENGTH], size_t n, uint8_t *out) { + if (n > CMT_ABI_U256_LENGTH) { return -EDOM; } - for (size_t i = 0; i < CMT_WORD_LENGTH - n; ++i) { + for (size_t i = 0; i < CMT_ABI_U256_LENGTH - n; ++i) { if (data[i]) { return -EDOM; } } - for (size_t i = CMT_WORD_LENGTH - n; i < CMT_WORD_LENGTH; ++i) { - out[CMT_WORD_LENGTH - 1 - i] = data[i]; + for (size_t i = CMT_ABI_U256_LENGTH - n; i < CMT_ABI_U256_LENGTH; ++i) { + out[CMT_ABI_U256_LENGTH - 1 - i] = data[i]; } return 0; } -int cmt_abi_decode_uint_nn(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_t *out) { - if (n > CMT_WORD_LENGTH) { +int cmt_abi_decode_uint_nn(const uint8_t data[CMT_ABI_U256_LENGTH], size_t n, uint8_t *out) { + if (n > CMT_ABI_U256_LENGTH) { return -EDOM; } - for (size_t i = 0; i < CMT_WORD_LENGTH - n; ++i) { + for (size_t i = 0; i < CMT_ABI_U256_LENGTH - n; ++i) { if (data[i]) { return -EDOM; } } - for (size_t i = CMT_WORD_LENGTH - n; i < CMT_WORD_LENGTH; ++i) { - out[i - CMT_WORD_LENGTH + n] = data[i]; + for (size_t i = CMT_ABI_U256_LENGTH - n; i < CMT_ABI_U256_LENGTH; ++i) { + out[i - CMT_ABI_U256_LENGTH + n] = data[i]; } return 0; } -int cmt_abi_decode_uint(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_t *out) { +int cmt_abi_decode_uint(const uint8_t data[CMT_ABI_U256_LENGTH], size_t n, uint8_t *out) { #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ return cmt_abi_decode_uint_nn(data, n, out); #else @@ -119,10 +119,10 @@ int cmt_abi_decode_uint(const uint8_t data[CMT_WORD_LENGTH], size_t n, uint8_t * int cmt_abi_put_uint(cmt_buf_t *me, size_t data_length, const void *data) { cmt_buf_t x[1]; - if (data_length > CMT_WORD_LENGTH) { + if (data_length > CMT_ABI_U256_LENGTH) { return -EDOM; } - if (cmt_buf_split(me, CMT_WORD_LENGTH, x, me)) { + if (cmt_buf_split(me, CMT_ABI_U256_LENGTH, x, me)) { return -ENOBUFS; } return cmt_abi_encode_uint(data_length, data, x->begin); @@ -130,17 +130,17 @@ int cmt_abi_put_uint(cmt_buf_t *me, size_t data_length, const void *data) { int cmt_abi_put_uint_be(cmt_buf_t *me, size_t data_length, const void *data) { cmt_buf_t x[1]; - if (data_length > CMT_WORD_LENGTH) { + if (data_length > CMT_ABI_U256_LENGTH) { return -EDOM; } - if (cmt_buf_split(me, CMT_WORD_LENGTH, x, me)) { + if (cmt_buf_split(me, CMT_ABI_U256_LENGTH, x, me)) { return -ENOBUFS; } return cmt_abi_encode_uint_nn(data_length, data, x->begin); } int cmt_abi_put_uint256(cmt_buf_t *me, const cmt_abi_u256_t *value) { cmt_buf_t x[1]; - if (cmt_buf_split(me, CMT_WORD_LENGTH, x, me)) { + if (cmt_buf_split(me, CMT_ABI_U256_LENGTH, x, me)) { return -ENOBUFS; } return cmt_abi_encode_uint_nn(sizeof(*value), value->data, x->begin); @@ -153,23 +153,23 @@ int cmt_abi_put_bool(cmt_buf_t *me, bool value) { int cmt_abi_put_address(cmt_buf_t *me, const cmt_abi_address_t *address) { cmt_buf_t x[1]; - if (cmt_buf_split(me, CMT_WORD_LENGTH, x, me)) { + if (cmt_buf_split(me, CMT_ABI_U256_LENGTH, x, me)) { return -ENOBUFS; } return cmt_abi_encode_uint_nn(sizeof(*address), address->data, x->begin); } int cmt_abi_put_bytes_s(cmt_buf_t *me, cmt_buf_t *offset) { - return cmt_buf_split(me, CMT_WORD_LENGTH, offset, me); + return cmt_buf_split(me, CMT_ABI_U256_LENGTH, offset, me); } int cmt_abi_reserve_bytes_d(cmt_buf_t *me, cmt_buf_t *of, size_t n, cmt_buf_t *out, const void *start) { int rc = 0; cmt_buf_t tmp[1]; cmt_buf_t sz[1]; - size_t n32 = align_forward(n, CMT_WORD_LENGTH); + size_t n32 = align_forward(n, CMT_ABI_U256_LENGTH); - rc = cmt_buf_split(me, CMT_WORD_LENGTH, sz, tmp); + rc = cmt_buf_split(me, CMT_ABI_U256_LENGTH, sz, tmp); if (rc) { return rc; } @@ -228,10 +228,10 @@ int cmt_abi_check_funsel(cmt_buf_t *me, uint32_t expected) { int cmt_abi_get_uint(cmt_buf_t *me, size_t n, void *data) { cmt_buf_t x[1]; - if (n > CMT_WORD_LENGTH) { + if (n > CMT_ABI_U256_LENGTH) { return -EDOM; } - int rc = cmt_buf_split(me, CMT_WORD_LENGTH, x, me); + int rc = cmt_buf_split(me, CMT_ABI_U256_LENGTH, x, me); if (rc) { return rc; } @@ -242,10 +242,10 @@ int cmt_abi_get_uint(cmt_buf_t *me, size_t n, void *data) { int cmt_abi_get_uint_be(cmt_buf_t *me, size_t n, void *data) { cmt_buf_t x[1]; - if (n > CMT_WORD_LENGTH) { + if (n > CMT_ABI_U256_LENGTH) { return -EDOM; } - int rc = cmt_buf_split(me, CMT_WORD_LENGTH, x, me); + int rc = cmt_buf_split(me, CMT_ABI_U256_LENGTH, x, me); if (rc) { return rc; } @@ -266,7 +266,7 @@ int cmt_abi_get_bool(cmt_buf_t *me, bool *value) { int cmt_abi_get_address(cmt_buf_t *me, cmt_abi_address_t *address) { cmt_buf_t x[1]; - int rc = cmt_buf_split(me, CMT_WORD_LENGTH, x, me); + int rc = cmt_buf_split(me, CMT_ABI_U256_LENGTH, x, me); if (rc) { return rc; } @@ -274,7 +274,7 @@ int cmt_abi_get_address(cmt_buf_t *me, cmt_abi_address_t *address) { } int cmt_abi_get_bytes_s(cmt_buf_t *me, cmt_buf_t of[1]) { - return cmt_buf_split(me, CMT_WORD_LENGTH, of, me); + return cmt_buf_split(me, CMT_ABI_U256_LENGTH, of, me); } int cmt_abi_peek_bytes_d(const cmt_buf_t *start, cmt_buf_t of[1], cmt_buf_t *bytes) { diff --git a/sys-utils/libcmt/src/rollup.c b/sys-utils/libcmt/src/rollup.c index 8285885..93a13ff 100644 --- a/sys-utils/libcmt/src/rollup.c +++ b/sys-utils/libcmt/src/rollup.c @@ -315,7 +315,7 @@ 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); - me->fromhost_data = CMT_WORD_LENGTH; + me->fromhost_data = CMT_ABI_U256_LENGTH; int reason = accepted(me->io, &me->fromhost_data); if (reason < 0) { return reason; diff --git a/sys-utils/libcmt/tests/abi-single.c b/sys-utils/libcmt/tests/abi-single.c index a1056db..7159839 100644 --- a/sys-utils/libcmt/tests/abi-single.c +++ b/sys-utils/libcmt/tests/abi-single.c @@ -38,8 +38,8 @@ static void abi_funsel(void) { static void encode_u8(void) { uint8_t x = 0x01; - uint8_t en[CMT_WORD_LENGTH]; - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t en[CMT_ABI_U256_LENGTH]; + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -51,8 +51,8 @@ static void encode_u8(void) { static void encode_u16(void) { uint16_t x = UINT16_C(0x0123); - uint8_t en[CMT_WORD_LENGTH]; - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t en[CMT_ABI_U256_LENGTH]; + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -64,8 +64,8 @@ static void encode_u16(void) { static void encode_u32(void) { uint32_t x = UINT32_C(0x01234567); - uint8_t en[CMT_WORD_LENGTH]; - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t en[CMT_ABI_U256_LENGTH]; + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -77,8 +77,8 @@ static void encode_u32(void) { static void encode_u64(void) { uint64_t x = UINT64_C(0x0123456789abcdef); - uint8_t en[CMT_WORD_LENGTH]; - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t en[CMT_ABI_U256_LENGTH]; + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -89,14 +89,14 @@ static void encode_u64(void) { } static void encode_u256(void) { - uint8_t x[CMT_WORD_LENGTH] = { + uint8_t x[CMT_ABI_U256_LENGTH] = { // clang-format off 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, // clang-format on }; - uint8_t en[CMT_WORD_LENGTH]; - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t en[CMT_ABI_U256_LENGTH]; + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -107,14 +107,14 @@ static void encode_u256(void) { } static void encode_edom(void) { - uint8_t x[CMT_WORD_LENGTH + 1] = { + uint8_t x[CMT_ABI_U256_LENGTH + 1] = { // clang-format off 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, // clang-format on }; - uint8_t en[CMT_WORD_LENGTH]; + uint8_t en[CMT_ABI_U256_LENGTH]; assert(cmt_abi_encode_uint_nr(sizeof(x), x, en) == -EDOM); assert(cmt_abi_encode_uint_nn(sizeof(x), x, en) == -EDOM); } @@ -122,7 +122,7 @@ static void encode_edom(void) { static void decode_u8(void) { uint8_t x = 0; uint8_t ex = 0x01; - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -135,7 +135,7 @@ static void decode_u8(void) { static void decode_u16(void) { uint16_t x = 0; uint16_t ex = UINT16_C(0x0123); - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -148,7 +148,7 @@ static void decode_u16(void) { static void decode_u32(void) { uint32_t x = 0; uint32_t ex = UINT32_C(0x01234567); - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -161,7 +161,7 @@ static void decode_u32(void) { static void decode_u64(void) { uint64_t x = 0; uint64_t ex = UINT64_C(0x0123456789abcdef); - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -172,14 +172,14 @@ static void decode_u64(void) { } static void decode_u256(void) { - uint8_t x[CMT_WORD_LENGTH]; - uint8_t ex[CMT_WORD_LENGTH] = { + uint8_t x[CMT_ABI_U256_LENGTH]; + uint8_t ex[CMT_ABI_U256_LENGTH] = { // clang-format off 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, // clang-format on }; - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -190,7 +190,7 @@ static void decode_u256(void) { } static void decode_uint_edom(void) { - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -207,12 +207,12 @@ static void decode_uint_edom(void) { } { - uint8_t x[CMT_WORD_LENGTH + 1] = {0}; + uint8_t x[CMT_ABI_U256_LENGTH + 1] = {0}; assert(cmt_abi_decode_uint_nr(be, sizeof(x), x) == -EDOM); } { - uint8_t x[CMT_WORD_LENGTH + 1] = {0}; + uint8_t x[CMT_ABI_U256_LENGTH + 1] = {0}; assert(cmt_abi_decode_uint_nn(be, sizeof(x), x) == -EDOM); } } @@ -238,7 +238,7 @@ static void put_funsel_enobufs(void) { static void put_uint(void) { uint64_t x = UINT64_C(0x0123456789abcdef); - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -261,8 +261,8 @@ static void put_uint_enobufs(void) { } static void put_uint_edom(void) { - uint64_t x[CMT_WORD_LENGTH + 1] = {0}; - CMT_BUF_DECL(b, CMT_WORD_LENGTH); + uint64_t x[CMT_ABI_U256_LENGTH + 1] = {0}; + CMT_BUF_DECL(b, CMT_ABI_U256_LENGTH); cmt_buf_t it[1] = {*b}; assert(cmt_abi_put_uint(it, sizeof(x), &x) == -EDOM); @@ -270,7 +270,7 @@ static void put_uint_edom(void) { } static void put_bool(void) { - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -303,7 +303,7 @@ static void put_address(void) { static void put_address_enobufs(void) { cmt_abi_address_t x = {{0}}; - CMT_BUF_DECL(b, CMT_WORD_LENGTH - 1); + CMT_BUF_DECL(b, CMT_ABI_U256_LENGTH - 1); cmt_buf_t it[1] = {*b}; assert(cmt_abi_put_address(it, &x) == -ENOBUFS); @@ -368,7 +368,7 @@ static void peek_funsel_error(void) { static void get_uint(void) { uint64_t x = 0; uint64_t ex = UINT64_C(0x0123456789abcdef); - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -391,8 +391,8 @@ static void get_uint_enobufs(void) { } static void get_uint_edom(void) { - uint64_t x[CMT_WORD_LENGTH + 1] = {0}; - CMT_BUF_DECL(b, CMT_WORD_LENGTH); + uint64_t x[CMT_ABI_U256_LENGTH + 1] = {0}; + CMT_BUF_DECL(b, CMT_ABI_U256_LENGTH); cmt_buf_t it[1] = {*b}; assert(cmt_abi_get_uint(it, sizeof(x), &x) == -EDOM); @@ -402,7 +402,7 @@ static void get_uint_edom(void) { static void get_uint_be(void) { uint64_t x = 0; uint64_t ex = UINT64_C(0x0123456789abcdef); - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, @@ -418,7 +418,7 @@ static void get_uint_be(void) { static void get_bool(void) { bool x = false; bool ex = true; - uint8_t be[CMT_WORD_LENGTH] = { + uint8_t be[CMT_ABI_U256_LENGTH] = { // clang-format off 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, @@ -433,7 +433,7 @@ static void get_bool(void) { static void get_bool_enobufs(void) { bool x = false; - uint8_t be[CMT_WORD_LENGTH - 1] = { + uint8_t be[CMT_ABI_U256_LENGTH - 1] = { // clang-format off 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, @@ -467,7 +467,7 @@ static void get_address(void) { static void get_address_enobufs(void) { cmt_abi_address_t x; // clang-format off - uint8_t be[CMT_WORD_LENGTH - 1] = { + uint8_t be[CMT_ABI_U256_LENGTH - 1] = { 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, }; @@ -510,7 +510,7 @@ static void get_bytes_enobufs(void) { // clang-format on { // when offset of dynamic reagion failed - CMT_BUF_DECL3(b, 1 * CMT_WORD_LENGTH - 1, be); + CMT_BUF_DECL3(b, 1 * CMT_ABI_U256_LENGTH - 1, be); cmt_buf_t it[1] = {*b}; cmt_buf_t of[1] = {0}; cmt_buf_t bytes[1]; @@ -519,7 +519,7 @@ static void get_bytes_enobufs(void) { } { // dynamic reagion is too small to peek bytes - CMT_BUF_DECL3(b, 3 * CMT_WORD_LENGTH - 1, be); + CMT_BUF_DECL3(b, 3 * CMT_ABI_U256_LENGTH - 1, be); cmt_buf_t it[1] = {*b}; cmt_buf_t of[1] = {0}; cmt_buf_t bytes[1]; @@ -529,7 +529,7 @@ static void get_bytes_enobufs(void) { } { // dynamic reagion is too small to copy bytes - CMT_BUF_DECL3(b, 3 * CMT_WORD_LENGTH - 1, be); + CMT_BUF_DECL3(b, 3 * CMT_ABI_U256_LENGTH - 1, be); cmt_buf_t it[1] = {*b}; cmt_buf_t of[1] = {0}; diff --git a/sys-utils/libcmt/tests/rollup.c b/sys-utils/libcmt/tests/rollup.c index 750213c..abda9b0 100644 --- a/sys-utils/libcmt/tests/rollup.c +++ b/sys-utils/libcmt/tests/rollup.c @@ -79,7 +79,7 @@ static void check_first_input(cmt_rollup_t *rollup) { assert(memcmp(advance.msg_sender.data, expected_msg_sender, CMT_ADDRESS_LENGTH) == 0); assert(advance.block_number == 4); assert(advance.block_timestamp == 5); - assert(memcmp(&advance.prev_randao.data, expected_prev_randao.data, CMT_WORD_LENGTH) == 0); + assert(memcmp(&advance.prev_randao.data, expected_prev_randao.data, CMT_ABI_U256_LENGTH) == 0); assert(advance.index == 7); assert(advance.payload.length == strlen(expected_payload)); assert(memcmp(advance.payload.data, expected_payload, strlen(expected_payload)) == 0);