Skip to content

Commit

Permalink
fixup! feat!: implement libcmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Jan 11, 2024
1 parent ee9017a commit 1734b6d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
23 changes: 11 additions & 12 deletions sys-utils/libcmt/README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions sys-utils/libcmt/src/abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions sys-utils/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1734b6d

Please sign in to comment.