From 1734b6db681eafd03d1678da5bb659a098020721 Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Thu, 11 Jan 2024 04:26:39 -0300 Subject: [PATCH] fixup! feat!: implement libcmt --- sys-utils/libcmt/README.md | 23 +++++++++++------------ sys-utils/libcmt/src/abi.c | 4 ++-- sys-utils/libcmt/src/rollup.c | 6 ++++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/sys-utils/libcmt/README.md b/sys-utils/libcmt/README.md index 95b5ec24..d1961ea3 100644 --- a/sys-utils/libcmt/README.md +++ b/sys-utils/libcmt/README.md @@ -1,16 +1,15 @@ -High level +This is a C library to facilitate IO interactions of applications running in the cartesi-machine. -- @ref libcmt\_rollup +The high level @ref libcmt\_rollup API provides functions for common operations, such as generating vouchers, notices, retrieving the next input, etc. +Check the [cartesi documentation](https://docs.cartesi.io/) for an introduction and explanation of the rollup interaction model. -Utility +In addition to the above mentioned module, we provide @ref libcmt\_io\_driver, a thin abstraction of the linux kernel driver. -- @ref libcmt\_abi -- @ref libcmt\_buf -- @ref libcmt\_merkle -- @ref libcmt\_keccak +And finally there are the utility modules used by the high level API. +- @ref libcmt\_abi is a Ethereum Virtual Machine Application Binary Interface (EVM-ABI) encoder / decoder. +- @ref libcmt\_buf is a bounds checking buffer. +- @ref libcmt\_merkle is a sparse merkle tree implementation on top of keccak. +- @ref libcmt\_keccak is the hashing function used extensively by Ethereum. -Low level - -- @ref libcmt\_io\_driver - -Download the static library from [cartesi tools](https://github.com/cartesi/machine-emulator-tools/). +The header files and a compiled RISC-V version of this library can be found [here](https://github.com/cartesi/machine-emulator-tools/). +We also provide `.pc` (pkg-config) files to facilitate linking. diff --git a/sys-utils/libcmt/src/abi.c b/sys-utils/libcmt/src/abi.c index ca12095b..87235d06 100644 --- a/sys-utils/libcmt/src/abi.c +++ b/sys-utils/libcmt/src/abi.c @@ -182,10 +182,10 @@ uint32_t cmt_abi_peek_funsel(cmt_buf_t *me) int cmt_abi_check_funsel(cmt_buf_t *me, uint32_t expected) { if (cmt_buf_length(me) < 4) - return ENOBUFS; + return -ENOBUFS; if (cmt_abi_peek_funsel(me) != expected) - return EBADMSG; + return -EBADMSG; me->begin += 4; return 0; diff --git a/sys-utils/libcmt/src/rollup.c b/sys-utils/libcmt/src/rollup.c index a121b769..4a4fba5e 100644 --- a/sys-utils/libcmt/src/rollup.c +++ b/sys-utils/libcmt/src/rollup.c @@ -261,8 +261,10 @@ int cmt_rollup_finish(cmt_rollup_t *me, cmt_rollup_finish_t *finish) } cmt_merkle_get_root_hash(me->merkle, me->tx->begin); - return finish->next_request_type = accepted - (me->io, &finish->next_request_payload_length); + finish->next_request_type = + accepted(me->io, &finish->next_request_payload_length); + cmt_merkle_init(me->merkle); + return finish->next_request_type; } int