From c3b1bdefb4295432b12f8caea4324f810e78ac6d Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:43:49 -0300 Subject: [PATCH] fixup! feat: add libdriver --- linux/libcmt/examples/rollup.c | 12 +++++------- linux/libcmt/include/libcmt/rollup.h | 6 +++--- linux/libcmt/src/merkle.c | 2 +- linux/libcmt/src/mock/rollup-driver.c | 2 +- linux/libcmt/src/rollup.c | 10 ++++++++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/linux/libcmt/examples/rollup.c b/linux/libcmt/examples/rollup.c index 94303da7..a2bf6104 100644 --- a/linux/libcmt/examples/rollup.c +++ b/linux/libcmt/examples/rollup.c @@ -29,7 +29,7 @@ int main(void) break; } cmt_rollup_emit_voucher(&rollup, advance.sender, advance.length, advance.data); - cmt_rollup_emit_report(&rollup, inspect.length, inspect.data); + cmt_rollup_emit_report(&rollup, advance.length, advance.data); break; case CMT_ROLLUP_INSPECT_STATE: @@ -44,12 +44,10 @@ int main(void) cmt_rollup_emit_report(&rollup, inspect.length, inspect.data); break; - default: - finish.accept_previous_request = false; - break; + default: // <- end of inputs when testing + cmt_rollup_fini(&rollup); + return EXIT_SUCCESS; } } - - cmt_rollup_fini(&rollup); - return 0; + return EXIT_SUCCESS; } diff --git a/linux/libcmt/include/libcmt/rollup.h b/linux/libcmt/include/libcmt/rollup.h index 17034edc..c33ad9c5 100644 --- a/linux/libcmt/include/libcmt/rollup.h +++ b/linux/libcmt/include/libcmt/rollup.h @@ -128,9 +128,9 @@ cmt_rollup_emit_report(cmt_rollup_t *me * - 0 success * - -ENOBUFS no space left in @p me */ int -cmt_rollup_emit_report(cmt_rollup_t *me - ,size_t n - ,const void *data); +cmt_rollup_emit_exception(cmt_rollup_t *me + ,size_t n + ,const void *data); /** read advance state * diff --git a/linux/libcmt/src/merkle.c b/linux/libcmt/src/merkle.c index 834a6259..6e5cf6d0 100644 --- a/linux/libcmt/src/merkle.c +++ b/linux/libcmt/src/merkle.c @@ -105,7 +105,7 @@ int cmt_merkle_push_back(cmt_merkle_t *me, uint8_t hash[CMT_KECCAK_LENGTH]) if (me->leaf_count == UINT64_MAX) return -ENOBUFS; - unsigned n = ((uint64_t)ffsll(++me->leaf_count)-1u); + unsigned n = (uint64_t)ffsll(++me->leaf_count) - 1u; for (unsigned i=0; istate[i], hash, hash); memcpy(me->state[n], hash, CMT_KECCAK_LENGTH); diff --git a/linux/libcmt/src/mock/rollup-driver.c b/linux/libcmt/src/mock/rollup-driver.c index 3d2a73d2..71b4fd46 100644 --- a/linux/libcmt/src/mock/rollup-driver.c +++ b/linux/libcmt/src/mock/rollup-driver.c @@ -80,7 +80,7 @@ int cmt_rollup_driver_write_report(struct cmt_rollup_driver *me, size_t n) char filename[1024]; if (!me) return -EINVAL; snprintf(filename, sizeof(filename), "input-%u-report-%u.bin", - me->input_seq, ++me->output_seq - 1); + me->input_seq, ++me->report_seq - 1); return cmt_rollup_driver_mock_write(me, n, filename); } diff --git a/linux/libcmt/src/rollup.c b/linux/libcmt/src/rollup.c index c3b93722..cb23785f 100644 --- a/linux/libcmt/src/rollup.c +++ b/linux/libcmt/src/rollup.c @@ -97,16 +97,22 @@ int cmt_rollup_emit_notice(cmt_rollup_t *me, size_t length, const void *data) int cmt_rollup_emit_report(cmt_rollup_t *me, size_t length, const void *data) { if (!me) return -EINVAL; + if (!data && length) return -EINVAL; + if (cmt_buf_length(me->tx) < length) + return -ENOBUFS; - memcpy(me->tx, data, length); + memcpy(me->tx->begin, data, length); return cmt_rollup_driver_write_report(me->rollup_driver, length); } int cmt_rollup_emit_exception(cmt_rollup_t *me, size_t length, const void *data) { if (!me) return -EINVAL; + if (!data && length) return -EINVAL; + if (cmt_buf_length(me->tx) < length) + return -ENOBUFS; - memcpy(me->tx, data, length); + memcpy(me->tx->begin, data, length); return cmt_rollup_driver_write_exception(me->rollup_driver, length); }