@deroll/cmio 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/AUTHORS +1 -0
  2. package/LICENSE +202 -0
  3. package/README.md +122 -0
  4. package/binding.gyp +53 -0
  5. package/deps/machine-guest-tools/AUTHORS +7 -0
  6. package/deps/machine-guest-tools/sys-utils/libcmt/include/libcmt/abi.h +589 -0
  7. package/deps/machine-guest-tools/sys-utils/libcmt/include/libcmt/buf.h +82 -0
  8. package/deps/machine-guest-tools/sys-utils/libcmt/include/libcmt/io.h +168 -0
  9. package/deps/machine-guest-tools/sys-utils/libcmt/include/libcmt/keccak.h +131 -0
  10. package/deps/machine-guest-tools/sys-utils/libcmt/include/libcmt/merkle.h +118 -0
  11. package/deps/machine-guest-tools/sys-utils/libcmt/include/libcmt/rollup.h +260 -0
  12. package/deps/machine-guest-tools/sys-utils/libcmt/include/libcmt/util.h +34 -0
  13. package/deps/machine-guest-tools/sys-utils/libcmt/src/abi.c +315 -0
  14. package/deps/machine-guest-tools/sys-utils/libcmt/src/buf.c +121 -0
  15. package/deps/machine-guest-tools/sys-utils/libcmt/src/io-mock.c +319 -0
  16. package/deps/machine-guest-tools/sys-utils/libcmt/src/io.c +164 -0
  17. package/deps/machine-guest-tools/sys-utils/libcmt/src/keccak.c +156 -0
  18. package/deps/machine-guest-tools/sys-utils/libcmt/src/merkle.c +202 -0
  19. package/deps/machine-guest-tools/sys-utils/libcmt/src/rollup.c +455 -0
  20. package/deps/machine-guest-tools/sys-utils/libcmt/src/util.c +52 -0
  21. package/lib/index.d.mts +18 -0
  22. package/lib/index.d.ts +162 -0
  23. package/lib/index.js +230 -0
  24. package/lib/index.mjs +19 -0
  25. package/package.json +70 -0
  26. package/prebuilds/darwin-arm64/@deroll+cmio.node +0 -0
  27. package/src/addon.cc +411 -0
@@ -0,0 +1,202 @@
1
+ /* Copyright Cartesi and individual authors (see AUTHORS)
2
+ * SPDX-License-Identifier: Apache-2.0
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ #include "libcmt/merkle.h"
17
+ #include "libcmt/util.h"
18
+
19
+ #include <errno.h>
20
+ #include <stdbool.h>
21
+ #include <stdio.h>
22
+ #include <string.h>
23
+ #include <strings.h>
24
+
25
+ // clang-format off
26
+ static const uint8_t pristine_hash[][CMT_KECCAK_LENGTH] = {
27
+ {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},
28
+ {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},
29
+ {0xb4,0xc1,0x19,0x51,0x95,0x7c,0x6f,0x8f,0x64,0x2c,0x4a,0xf6,0x1c,0xd6,0xb2,0x46,0x40,0xfe,0xc6,0xdc,0x7f,0xc6,0x07,0xee,0x82,0x06,0xa9,0x9e,0x92,0x41,0x0d,0x30},
30
+ {0x21,0xdd,0xb9,0xa3,0x56,0x81,0x5c,0x3f,0xac,0x10,0x26,0xb6,0xde,0xc5,0xdf,0x31,0x24,0xaf,0xba,0xdb,0x48,0x5c,0x9b,0xa5,0xa3,0xe3,0x39,0x8a,0x04,0xb7,0xba,0x85},
31
+ {0xe5,0x87,0x69,0xb3,0x2a,0x1b,0xea,0xf1,0xea,0x27,0x37,0x5a,0x44,0x09,0x5a,0x0d,0x1f,0xb6,0x64,0xce,0x2d,0xd3,0x58,0xe7,0xfc,0xbf,0xb7,0x8c,0x26,0xa1,0x93,0x44},
32
+ {0x0e,0xb0,0x1e,0xbf,0xc9,0xed,0x27,0x50,0x0c,0xd4,0xdf,0xc9,0x79,0x27,0x2d,0x1f,0x09,0x13,0xcc,0x9f,0x66,0x54,0x0d,0x7e,0x80,0x05,0x81,0x11,0x09,0xe1,0xcf,0x2d},
33
+ {0x88,0x7c,0x22,0xbd,0x87,0x50,0xd3,0x40,0x16,0xac,0x3c,0x66,0xb5,0xff,0x10,0x2d,0xac,0xdd,0x73,0xf6,0xb0,0x14,0xe7,0x10,0xb5,0x1e,0x80,0x22,0xaf,0x9a,0x19,0x68},
34
+ {0xff,0xd7,0x01,0x57,0xe4,0x80,0x63,0xfc,0x33,0xc9,0x7a,0x05,0x0f,0x7f,0x64,0x02,0x33,0xbf,0x64,0x6c,0xc9,0x8d,0x95,0x24,0xc6,0xb9,0x2b,0xcf,0x3a,0xb5,0x6f,0x83},
35
+ {0x98,0x67,0xcc,0x5f,0x7f,0x19,0x6b,0x93,0xba,0xe1,0xe2,0x7e,0x63,0x20,0x74,0x24,0x45,0xd2,0x90,0xf2,0x26,0x38,0x27,0x49,0x8b,0x54,0xfe,0xc5,0x39,0xf7,0x56,0xaf},
36
+ {0xce,0xfa,0xd4,0xe5,0x08,0xc0,0x98,0xb9,0xa7,0xe1,0xd8,0xfe,0xb1,0x99,0x55,0xfb,0x02,0xba,0x96,0x75,0x58,0x50,0x78,0x71,0x09,0x69,0xd3,0x44,0x0f,0x50,0x54,0xe0},
37
+ {0xf9,0xdc,0x3e,0x7f,0xe0,0x16,0xe0,0x50,0xef,0xf2,0x60,0x33,0x4f,0x18,0xa5,0xd4,0xfe,0x39,0x1d,0x82,0x09,0x23,0x19,0xf5,0x96,0x4f,0x2e,0x2e,0xb7,0xc1,0xc3,0xa5},
38
+ {0xf8,0xb1,0x3a,0x49,0xe2,0x82,0xf6,0x09,0xc3,0x17,0xa8,0x33,0xfb,0x8d,0x97,0x6d,0x11,0x51,0x7c,0x57,0x1d,0x12,0x21,0xa2,0x65,0xd2,0x5a,0xf7,0x78,0xec,0xf8,0x92},
39
+ {0x34,0x90,0xc6,0xce,0xeb,0x45,0x0a,0xec,0xdc,0x82,0xe2,0x82,0x93,0x03,0x1d,0x10,0xc7,0xd7,0x3b,0xf8,0x5e,0x57,0xbf,0x04,0x1a,0x97,0x36,0x0a,0xa2,0xc5,0xd9,0x9c},
40
+ {0xc1,0xdf,0x82,0xd9,0xc4,0xb8,0x74,0x13,0xea,0xe2,0xef,0x04,0x8f,0x94,0xb4,0xd3,0x55,0x4c,0xea,0x73,0xd9,0x2b,0x0f,0x7a,0xf9,0x6e,0x02,0x71,0xc6,0x91,0xe2,0xbb},
41
+ {0x5c,0x67,0xad,0xd7,0xc6,0xca,0xf3,0x02,0x25,0x6a,0xde,0xdf,0x7a,0xb1,0x14,0xda,0x0a,0xcf,0xe8,0x70,0xd4,0x49,0xa3,0xa4,0x89,0xf7,0x81,0xd6,0x59,0xe8,0xbe,0xcc},
42
+ {0xda,0x7b,0xce,0x9f,0x4e,0x86,0x18,0xb6,0xbd,0x2f,0x41,0x32,0xce,0x79,0x8c,0xdc,0x7a,0x60,0xe7,0xe1,0x46,0x0a,0x72,0x99,0xe3,0xc6,0x34,0x2a,0x57,0x96,0x26,0xd2},
43
+ {0x27,0x33,0xe5,0x0f,0x52,0x6e,0xc2,0xfa,0x19,0xa2,0x2b,0x31,0xe8,0xed,0x50,0xf2,0x3c,0xd1,0xfd,0xf9,0x4c,0x91,0x54,0xed,0x3a,0x76,0x09,0xa2,0xf1,0xff,0x98,0x1f},
44
+ {0xe1,0xd3,0xb5,0xc8,0x07,0xb2,0x81,0xe4,0x68,0x3c,0xc6,0xd6,0x31,0x5c,0xf9,0x5b,0x9a,0xde,0x86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43,0xd0,0xe1,0xff,0xba,0xb7,0x34,0x64,0x8c,0x83,0x8d,0xfb,0x05,0x27,0xd9,0x71,0xb6,0x02,0xbc,0x21,0x6c,0x96,0x19,0xef},
52
+ {0x0a,0xbf,0x5a,0xc9,0x74,0xa1,0xed,0x57,0xf4,0x05,0x0a,0xa5,0x10,0xdd,0x9c,0x74,0xf5,0x08,0x27,0x7b,0x39,0xd7,0x97,0x3b,0xb2,0xdf,0xcc,0xc5,0xee,0xb0,0x61,0x8d},
53
+ {0xb8,0xcd,0x74,0x04,0x6f,0xf3,0x37,0xf0,0xa7,0xbf,0x2c,0x8e,0x03,0xe1,0x0f,0x64,0x2c,0x18,0x86,0x79,0x8d,0x71,0x80,0x6a,0xb1,0xe8,0x88,0xd9,0xe5,0xee,0x87,0xd0},
54
+ {0x83,0x8c,0x56,0x55,0xcb,0x21,0xc6,0xcb,0x83,0x31,0x3b,0x5a,0x63,0x11,0x75,0xdf,0xf4,0x96,0x37,0x72,0xcc,0xe9,0x10,0x81,0x88,0xb3,0x4a,0xc8,0x7c,0x81,0xc4,0x1e},
55
+ {0x66,0x2e,0xe4,0xdd,0x2d,0xd7,0xb2,0xbc,0x70,0x79,0x61,0xb1,0xe6,0x46,0xc4,0x04,0x76,0x69,0xdc,0xb6,0x58,0x4f,0x0d,0x8d,0x77,0x0d,0xaf,0x5d,0x7e,0x7d,0xeb,0x2e},
56
+ {0x38,0x8a,0xb2,0x0e,0x25,0x73,0xd1,0x71,0xa8,0x81,0x08,0xe7,0x9d,0x82,0x0e,0x98,0xf2,0x6c,0x0b,0x84,0xaa,0x8b,0x2f,0x4a,0xa4,0x96,0x8d,0xbb,0x81,0x8e,0xa3,0x22},
57
+ {0x93,0x23,0x7c,0x50,0xba,0x75,0xee,0x48,0x5f,0x4c,0x22,0xad,0xf2,0xf7,0x41,0x40,0x0b,0xdf,0x8d,0x6a,0x9c,0xc7,0xdf,0x7e,0xca,0xe5,0x76,0x22,0x16,0x65,0xd7,0x35},
58
+ {0x84,0x48,0x81,0x8b,0xb4,0xae,0x45,0x62,0x84,0x9e,0x94,0x9e,0x17,0xac,0x16,0xe0,0xbe,0x16,0x68,0x8e,0x15,0x6b,0x5c,0xf1,0x5e,0x09,0x8c,0x62,0x7c,0x00,0x56,0xa9},
59
+ {0x27,0xae,0x5b,0xa0,0x8d,0x72,0x91,0xc9,0x6c,0x8c,0xbd,0xdc,0xc1,0x48,0xbf,0x48,0xa6,0xd6,0x8c,0x79,0x74,0xb9,0x43,0x56,0xf5,0x37,0x54,0xef,0x61,0x71,0xd7,0x57},
60
+ {0xbf,0x55,0x8b,0xeb,0xd2,0xce,0xec,0x7f,0x3c,0x5d,0xce,0x04,0xa4,0x78,0x2f,0x88,0xc2,0xc6,0x03,0x6a,0xe7,0x8e,0xe2,0x06,0xd0,0xbc,0x52,0x89,0xd2,0x04,0x61,0xa2},
61
+ {0xe2,0x19,0x08,0xc2,0x96,0x8c,0x06,0x99,0x04,0x0a,0x6f,0xd8,0x66,0xa5,0x77,0xa9,0x9a,0x9d,0x2e,0xc8,0x87,0x45,0xc8,0x15,0xfd,0x4a,0x47,0x2c,0x78,0x92,0x44,0xda},
62
+ {0xae,0x82,0x4d,0x72,0xdd,0xc2,0x72,0xaa,0xb6,0x8a,0x8c,0x30,0x22,0xe3,0x6f,0x10,0x45,0x44,0x37,0xc1,0x88,0x6f,0x3f,0xf9,0x92,0x7b,0x64,0xf2,0x32,0xdf,0x41,0x4f},
63
+ {0x27,0xe4,0x29,0xa4,0xbe,0xf3,0x08,0x3b,0xc3,0x1a,0x67,0x1d,0x04,0x6e,0xa5,0xc1,0xf5,0xb8,0xc3,0x09,0x4d,0x72,0x86,0x8d,0x9d,0xfd,0xc1,0x2c,0x73,0x34,0xac,0x5f},
64
+ {0x74,0x3c,0xc5,0xc3,0x65,0xa9,0xa6,0xa1,0x5c,0x1f,0x24,0x0a,0xc2,0x58,0x80,0xc7,0xa9,0xd1,0xde,0x29,0x06,0x96,0xcb,0x76,0x60,0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0xd7,0xfe,0xe1,0x57,0x64,0x84,0x5d,0xb8,0x75,0xf6,0x43,0x25,0x59,0xff,0x8d,0xbc,0x90,0x55,0x32,0x44,0x31,0xbc,0x34,0xe5,0xb9,0x3d,0x15,0xda},
79
+ {0x30,0x73,0x17,0x84,0x9e,0xcc,0xd9,0x0c,0x0c,0x7b,0x98,0x87,0x0b,0x93,0x17,0xc1,0x5a,0x59,0x59,0xdc,0xfb,0x84,0xc7,0x6d,0xcc,0x90,0x8c,0x4f,0xe6,0xba,0x92,0x12},
80
+ {0x63,0x39,0xbf,0x06,0xe4,0x58,0xf6,0x64,0x6d,0xf5,0xe8,0x3b,0xa7,0xc3,0xd3,0x5b,0xc2,0x63,0xb3,0x22,0x2c,0x8e,0x90,0x40,0x06,0x88,0x47,0x74,0x9c,0xa8,0xe8,0xf9},
81
+ {0x50,0x45,0xe4,0x34,0x2a,0xeb,0x52,0x1e,0xb3,0xa5,0x58,0x7e,0xc2,0x68,0xed,0x3a,0xa6,0xfa,0xf3,0x2b,0x62,0xb0,0xbc,0x41,0xa9,0xd5,0x49,0x52,0x1f,0x40,0x6f,0xc3},
82
+ {0x08,0x60,0x1d,0x83,0xcd,0xd3,0x4b,0x5f,0x7b,0x8d,0xf6,0x3e,0x7b,0x9a,0x16,0x51,0x9d,0x35,0x47,0x3d,0x0b,0x89,0xc3,0x17,0xbe,0xed,0x3d,0x3d,0x94,0x24,0xb2,0x53},
83
+ {0x84,0xe3,0x5c,0x5d,0x92,0x17,0x13,0x76,0xca,0xe5,0xc8,0x63,0x00,0x82,0x2d,0x72,0x9c,0xd3,0xa8,0x47,0x95,0x83,0xbe,0xf0,0x95,0x27,0x02,0x7d,0xba,0x5f,0x11,0x26},
84
+ {0x3c,0x5c,0xbb,0xeb,0x38,0x34,0xb7,0xa5,0xc1,0xcb,0xa9,0xaa,0x5f,0xee,0x0c,0x95,0xec,0x3f,0x17,0xa3,0x3e,0xc3,0xd8,0x04,0x7f,0xff,0x79,0x91,0x87,0xf5,0xae,0x20},
85
+ {0x40,0xbb,0xe9,0x13,0xc2,0x26,0xc3,0x4c,0x9f,0xbe,0x43,0x89,0xdd,0x72,0x89,0x84,0x25,0x7a,0x81,0x68,0x92,0xb3,0xca,0xe3,0xe4,0x31,0x91,0xdd,0x29,0x1f,0x0e,0xb5},
86
+ {0x14,0xaf,0x53,0x85,0xbc,0xbb,0x1e,0x47,0x38,0xbb,0xae,0x81,0x06,0x04,0x6e,0x6e,0x2f,0xca,0x42,0x87,0x5a,0xa5,0xc0,0x00,0xc5,0x82,0x58,0x77,0x42,0xbc,0xc7,0x48},
87
+ {0x72,0xf2,0x96,0x56,0x80,0x3c,0x2f,0x4b,0xe1,0x77,0xb1,0xb8,0xdd,0x2a,0x51,0x37,0x89,0x2b,0x08,0x0b,0x02,0x21,0x00,0xfd,0xe4,0xe9,0x6d,0x93,0xef,0x8c,0x96,0xff},
88
+ {0xd0,0x6f,0x27,0x06,0x1c,0x73,0x4d,0x78,0x25,0xb4,0x68,0x65,0xd0,0x0a,0xa9,0x00,0xe5,0xcc,0x3a,0x36,0x72,0x08,0x0e,0x52,0x71,0x71,0xe1,0x17,0x1a,0xa5,0x03,0x8a},
89
+ {0x28,0x20,0x39,0x85,0xb5,0xf2,0xd8,0x77,0x09,0x17,0x16,0x78,0x16,0x97,0x39,0xf9,0x57,0xd2,0x74,0x5f,0x4b,0xfa,0x5c,0xc9,0x1e,0x2b,0x4b,0xd9,0xbf,0x48,0x3b,0x40},
90
+ {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},
91
+ {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}
92
+ };
93
+ // clang-format on
94
+
95
+ static void copy_hash(const uint8_t src[CMT_KECCAK_LENGTH], uint8_t out[CMT_KECCAK_LENGTH]) {
96
+ memcpy(out, src, CMT_KECCAK_LENGTH);
97
+ }
98
+
99
+ static void concat_hash(const uint8_t lhs[CMT_KECCAK_LENGTH], const uint8_t rhs[CMT_KECCAK_LENGTH],
100
+ uint8_t out[CMT_KECCAK_LENGTH]) {
101
+ cmt_keccak_t c[1];
102
+ cmt_keccak_init(c);
103
+ cmt_keccak_update(c, CMT_KECCAK_LENGTH, lhs);
104
+ cmt_keccak_update(c, CMT_KECCAK_LENGTH, rhs);
105
+ cmt_keccak_final(c, out);
106
+ }
107
+
108
+ #if 0 // NOLINT
109
+ static void print_hash(uint8_t hash[CMT_KECCAK_LENGTH]) {
110
+ for (int i = 0; i < CMT_KECCAK_LENGTH; ++i) {
111
+ fprintf(stderr, "%02x", hash[i]);
112
+ }
113
+ fprintf(stderr, "\n");
114
+ }
115
+ #endif
116
+
117
+ void cmt_merkle_init(cmt_merkle_t *me) {
118
+ cmt_merkle_reset(me);
119
+ }
120
+
121
+ void cmt_merkle_reset(cmt_merkle_t *me) {
122
+ me->leaf_count = 0;
123
+ memset(me->state, 0, sizeof(me->state));
124
+ }
125
+
126
+ void cmt_merkle_fini(cmt_merkle_t *me) {
127
+ // no-op
128
+ (void) me;
129
+ }
130
+
131
+ int cmt_merkle_load(cmt_merkle_t *me, const char *filepath) {
132
+ if (!me) {
133
+ return -EINVAL;
134
+ }
135
+ size_t length = 0;
136
+ int rc = cmt_util_read_whole_file(filepath, sizeof *me, me, &length);
137
+ if (length != sizeof *me) {
138
+ return -EINVAL;
139
+ }
140
+ return rc;
141
+ }
142
+
143
+ int cmt_merkle_save(cmt_merkle_t *me, const char *filepath) {
144
+ if (!me) {
145
+ return -EINVAL;
146
+ }
147
+ return cmt_util_write_whole_file(filepath, sizeof *me, me);
148
+ }
149
+
150
+ uint64_t cmt_merkle_get_leaf_count(cmt_merkle_t *me) {
151
+ return me->leaf_count;
152
+ }
153
+
154
+ int cmt_merkle_push_back(cmt_merkle_t *me, const uint8_t hash[CMT_KECCAK_LENGTH]) {
155
+ const uint64_t max_count =
156
+ (CMT_MERKLE_TREE_HEIGHT < 8 * sizeof(uint64_t)) ? (UINT64_C(1) << CMT_MERKLE_TREE_HEIGHT) : UINT64_MAX;
157
+ if (me->leaf_count == max_count) {
158
+ return -ENOBUFS;
159
+ }
160
+ uint8_t right[CMT_KECCAK_LENGTH];
161
+ copy_hash(hash, right);
162
+ for (int i = 0; i < CMT_MERKLE_TREE_HEIGHT; ++i) {
163
+ uint64_t bit = ((uint64_t) 1) << i;
164
+ /* if we have a hash for a subtree of the current size in the state... */
165
+ if (me->leaf_count & bit) {
166
+ /* ...concat it with current running right and replace running right with it. */
167
+ concat_hash(me->state[i], right, right);
168
+ /* otherwise... */
169
+ } else {
170
+ /* ...just copy the current subtree hash to the state and we are done. */
171
+ copy_hash(right, me->state[i]);
172
+ break;
173
+ }
174
+ }
175
+ ++me->leaf_count;
176
+ return 0;
177
+ }
178
+
179
+ void cmt_merkle_get_root_hash(cmt_merkle_t *me, uint8_t root[CMT_KECCAK_LENGTH]) {
180
+ copy_hash(pristine_hash[0], root);
181
+ for (int i = 0; i < CMT_MERKLE_TREE_HEIGHT; ++i) {
182
+ uint64_t bit = ((uint64_t) 1) << i;
183
+ /* if we have a hash for a subtree of the current size in the state... */
184
+ if (me->leaf_count & bit) {
185
+ /* ...concat it with current root on the right and replace root */
186
+ concat_hash(me->state[i], root, root);
187
+ /* otherwise... */
188
+ } else {
189
+ /* ...concat root with pristine tree on the right and replace root */
190
+ concat_hash(root, pristine_hash[i], root);
191
+ }
192
+ }
193
+ }
194
+
195
+ int cmt_merkle_push_back_data(cmt_merkle_t *me, size_t length, const void *data) {
196
+ uint8_t hash[CMT_KECCAK_LENGTH];
197
+ cmt_keccak_t c[1];
198
+ cmt_keccak_init(c);
199
+ cmt_keccak_update(c, length, data);
200
+ cmt_keccak_final(c, hash);
201
+ return cmt_merkle_push_back(me, hash);
202
+ }
@@ -0,0 +1,455 @@
1
+ /* Copyright Cartesi and individual authors (see AUTHORS)
2
+ * SPDX-License-Identifier: Apache-2.0
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ #include "libcmt/rollup.h"
17
+ #include "libcmt/abi.h"
18
+ #include "libcmt/merkle.h"
19
+ #include "libcmt/util.h"
20
+
21
+ #include <errno.h>
22
+ #include <stdio.h>
23
+ #include <string.h>
24
+
25
+ // Voucher(address,uint256,bytes)
26
+ #define VOUCHER CMT_ABI_FUNSEL(0x23, 0x7a, 0x81, 0x6f)
27
+
28
+ // DelegateCallVoucher(address,bytes)
29
+ #define DELEGATE_CALL_VOUCHER CMT_ABI_FUNSEL(0x10, 0x32, 0x1e, 0x8b)
30
+
31
+ // Notice(bytes)
32
+ #define NOTICE CMT_ABI_FUNSEL(0xc2, 0x58, 0xd6, 0xe5)
33
+
34
+ // EvmAdvance(uint256,address,address,uint256,uint256,uint256,uint256,bytes)
35
+ #define EVM_ADVANCE CMT_ABI_FUNSEL(0x41, 0x5b, 0xf3, 0x63)
36
+
37
+ #define DBG(X) debug(X, #X, __FILE__, __LINE__)
38
+ static int debug(int rc, const char *expr, const char *file, int line) {
39
+ if (rc == 0) {
40
+ return 0;
41
+ }
42
+
43
+ if (cmt_util_debug_enabled()) {
44
+ (void) fprintf(stderr, "%s:%d Error %s on `%s'\n", file, line, expr, strerror(-rc));
45
+ }
46
+ return rc;
47
+ }
48
+
49
+ int cmt_rollup_init(cmt_rollup_t *me) {
50
+ if (!me) {
51
+ return -EINVAL;
52
+ }
53
+
54
+ int rc = DBG(cmt_io_init(me->io));
55
+ if (rc) {
56
+ return rc;
57
+ }
58
+
59
+ cmt_merkle_init(me->merkle);
60
+ me->finish_leaf_count = UINT64_C(-1);
61
+ me->fromhost_data = 0;
62
+ memset(me->finish_root_hash, 0, sizeof(me->finish_root_hash));
63
+ return 0;
64
+ }
65
+
66
+ void cmt_rollup_fini(cmt_rollup_t *me) {
67
+ if (!me) {
68
+ return;
69
+ }
70
+
71
+ cmt_io_fini(me->io);
72
+ cmt_merkle_fini(me->merkle);
73
+ }
74
+
75
+ int cmt_rollup_emit_voucher(cmt_rollup_t *me, const cmt_abi_address_t *address,
76
+ const cmt_abi_u256_t *value, const cmt_abi_bytes_t *payload, uint64_t *index) {
77
+ if (!me) {
78
+ return -EINVAL;
79
+ }
80
+ if (!payload || (!payload->data && payload->length)) {
81
+ return -EINVAL;
82
+ }
83
+
84
+ cmt_buf_t tx[1] = {cmt_io_get_tx(me->io)};
85
+ cmt_buf_t wr[1] = {*tx};
86
+ cmt_buf_t of[1];
87
+ cmt_buf_t frame[1];
88
+
89
+ // clang-format off
90
+ if (DBG(cmt_abi_put_funsel(wr, VOUCHER))
91
+ || DBG(cmt_abi_mark_frame(wr, frame))
92
+ || DBG(cmt_abi_put_address(wr, address))
93
+ || DBG(cmt_abi_put_uint256(wr, value))
94
+ || DBG(cmt_abi_put_bytes_s(wr, of))
95
+ || DBG(cmt_abi_put_bytes_d(wr, of, frame, payload))) {
96
+ return -ENOBUFS;
97
+ }
98
+ // clang-format on
99
+
100
+ size_t used_space = wr->begin - tx->begin;
101
+ struct cmt_io_yield req[1] = {{
102
+ .dev = HTIF_DEVICE_YIELD,
103
+ .cmd = HTIF_YIELD_CMD_AUTOMATIC,
104
+ .reason = HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT,
105
+ .data = used_space,
106
+ }};
107
+ int rc = DBG(cmt_io_yield(me->io, req));
108
+ if (rc) {
109
+ return rc;
110
+ }
111
+
112
+ uint64_t count = cmt_merkle_get_leaf_count(me->merkle);
113
+
114
+ rc = cmt_merkle_push_back_data(me->merkle, used_space, tx->begin);
115
+ if (rc) {
116
+ return rc;
117
+ }
118
+
119
+ if (index) {
120
+ *index = count;
121
+ }
122
+
123
+ return 0;
124
+ }
125
+
126
+ int cmt_rollup_emit_delegate_call_voucher(cmt_rollup_t *me,
127
+ const cmt_abi_address_t *address, const cmt_abi_bytes_t *payload, uint64_t *index) {
128
+ if (!me) {
129
+ return -EINVAL;
130
+ }
131
+ if (!payload || (!payload->data && payload->length)) {
132
+ return -EINVAL;
133
+ }
134
+
135
+ cmt_buf_t tx[1] = {cmt_io_get_tx(me->io)};
136
+ cmt_buf_t wr[1] = {*tx};
137
+ cmt_buf_t of[1];
138
+ cmt_buf_t frame[1];
139
+
140
+ // clang-format off
141
+ if (DBG(cmt_abi_put_funsel(wr, DELEGATE_CALL_VOUCHER))
142
+ || DBG(cmt_abi_mark_frame(wr, frame))
143
+ || DBG(cmt_abi_put_address(wr, address))
144
+ || DBG(cmt_abi_put_bytes_s(wr, of))
145
+ || DBG(cmt_abi_put_bytes_d(wr, of, frame, payload))) {
146
+ return -ENOBUFS;
147
+ }
148
+ // clang-format on
149
+
150
+ size_t used_space = wr->begin - tx->begin;
151
+ struct cmt_io_yield req[1] = {{
152
+ .dev = HTIF_DEVICE_YIELD,
153
+ .cmd = HTIF_YIELD_CMD_AUTOMATIC,
154
+ .reason = HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT,
155
+ .data = used_space,
156
+ }};
157
+ int rc = DBG(cmt_io_yield(me->io, req));
158
+ if (rc) {
159
+ return rc;
160
+ }
161
+
162
+ uint64_t count = cmt_merkle_get_leaf_count(me->merkle);
163
+
164
+ rc = cmt_merkle_push_back_data(me->merkle, used_space, tx->begin);
165
+ if (rc) {
166
+ return rc;
167
+ }
168
+
169
+ if (index) {
170
+ *index = count;
171
+ }
172
+
173
+ return 0;
174
+ }
175
+
176
+ int cmt_rollup_emit_notice(cmt_rollup_t *me, const cmt_abi_bytes_t *payload, uint64_t *index) {
177
+ if (!me) {
178
+ return -EINVAL;
179
+ }
180
+ if (!payload || (!payload->data && payload->length)) {
181
+ return -EINVAL;
182
+ }
183
+
184
+ cmt_buf_t tx[1] = {cmt_io_get_tx(me->io)};
185
+ cmt_buf_t wr[1] = {*tx};
186
+ cmt_buf_t of[1];
187
+ cmt_buf_t frame[1];
188
+
189
+ // clang-format off
190
+ if (DBG(cmt_abi_put_funsel(wr, NOTICE))
191
+ || DBG(cmt_abi_mark_frame(wr, frame))
192
+ || DBG(cmt_abi_put_bytes_s(wr, of))
193
+ || DBG(cmt_abi_put_bytes_d(wr, of, frame, payload))) {
194
+ return -ENOBUFS;
195
+ }
196
+ // clang-format on
197
+
198
+ size_t used_space = wr->begin - tx->begin;
199
+ struct cmt_io_yield req[1] = {{
200
+ .dev = HTIF_DEVICE_YIELD,
201
+ .cmd = HTIF_YIELD_CMD_AUTOMATIC,
202
+ .reason = HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT,
203
+ .data = used_space,
204
+ }};
205
+ int rc = DBG(cmt_io_yield(me->io, req));
206
+ if (rc) {
207
+ return rc;
208
+ }
209
+
210
+ uint64_t count = cmt_merkle_get_leaf_count(me->merkle);
211
+
212
+ rc = cmt_merkle_push_back_data(me->merkle, used_space, tx->begin);
213
+ if (rc) {
214
+ return rc;
215
+ }
216
+
217
+ if (index) {
218
+ *index = count;
219
+ }
220
+
221
+ return 0;
222
+ }
223
+
224
+ int cmt_rollup_emit_report(cmt_rollup_t *me, const cmt_abi_bytes_t *payload) {
225
+ if (!me) {
226
+ return -EINVAL;
227
+ }
228
+ if (!payload || (!payload->data && payload->length)) {
229
+ return -EINVAL;
230
+ }
231
+
232
+ cmt_buf_t tx[1] = {cmt_io_get_tx(me->io)};
233
+ cmt_buf_t wr[1] = {*tx};
234
+ if (cmt_buf_split(tx, payload->length, wr, tx)) {
235
+ return -ENOBUFS;
236
+ }
237
+
238
+ if (payload->data) {
239
+ memcpy(wr->begin, payload->data, payload->length);
240
+ }
241
+ struct cmt_io_yield req[1] = {{
242
+ .dev = HTIF_DEVICE_YIELD,
243
+ .cmd = HTIF_YIELD_CMD_AUTOMATIC,
244
+ .reason = HTIF_YIELD_AUTOMATIC_REASON_TX_REPORT,
245
+ .data = payload->length,
246
+ }};
247
+ return DBG(cmt_io_yield(me->io, req));
248
+ }
249
+
250
+ int cmt_rollup_emit_exception(cmt_rollup_t *me, const cmt_abi_bytes_t *payload) {
251
+ if (!me) {
252
+ return -EINVAL;
253
+ }
254
+ if (!payload || (!payload->data && payload->length)) {
255
+ return -EINVAL;
256
+ }
257
+
258
+ cmt_buf_t tx[1] = {cmt_io_get_tx(me->io)};
259
+ cmt_buf_t wr[1] = {*tx};
260
+ cmt_buf_t _[1];
261
+ if (cmt_buf_split(tx, payload->length, wr, _)) {
262
+ return -ENOBUFS;
263
+ }
264
+
265
+ if (payload->data) {
266
+ memcpy(wr->begin, payload->data, payload->length);
267
+ }
268
+ struct cmt_io_yield req[1] = {{
269
+ .dev = HTIF_DEVICE_YIELD,
270
+ .cmd = HTIF_YIELD_CMD_MANUAL,
271
+ .reason = HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION,
272
+ .data = payload->length,
273
+ }};
274
+ return DBG(cmt_io_yield(me->io, req));
275
+ }
276
+
277
+ static int cmt_rollup_get_rx(cmt_rollup_t *me, cmt_buf_t *lhs) {
278
+ cmt_buf_t rx[1] = {cmt_io_get_rx(me->io)};
279
+ cmt_buf_t _[1];
280
+ return cmt_buf_split(rx, me->fromhost_data, lhs, _);
281
+ }
282
+
283
+ int cmt_rollup_read_advance_state(cmt_rollup_t *me, cmt_rollup_advance_t *advance) {
284
+ if (!me) {
285
+ return -EINVAL;
286
+ }
287
+ if (!advance) {
288
+ return -EINVAL;
289
+ }
290
+
291
+ cmt_buf_t rd[1];
292
+ if (cmt_rollup_get_rx(me, rd)) {
293
+ return -ENOBUFS;
294
+ }
295
+ cmt_buf_t frame[1];
296
+ cmt_buf_t of[1];
297
+
298
+ // clang-format off
299
+ if (DBG(cmt_abi_check_funsel(rd, EVM_ADVANCE))
300
+ || DBG(cmt_abi_mark_frame(rd, frame))
301
+ || DBG(cmt_abi_get_uint(rd, sizeof(advance->chain_id), &advance->chain_id))
302
+ || DBG(cmt_abi_get_address(rd, &advance->app_contract))
303
+ || DBG(cmt_abi_get_address(rd, &advance->msg_sender))
304
+ || DBG(cmt_abi_get_uint(rd, sizeof(advance->block_number), &advance->block_number))
305
+ || DBG(cmt_abi_get_uint(rd, sizeof(advance->block_timestamp), &advance->block_timestamp))
306
+ || DBG(cmt_abi_get_uint256(rd, &advance->prev_randao))
307
+ || DBG(cmt_abi_get_uint(rd, sizeof(advance->index), &advance->index))
308
+ || DBG(cmt_abi_get_bytes_s(rd, of))
309
+ || DBG(cmt_abi_get_bytes_d(frame, of, &advance->payload.length, &advance->payload.data))) {
310
+ return -ENOBUFS;
311
+ }
312
+ // clang-format on
313
+
314
+ return 0;
315
+ }
316
+
317
+ int cmt_rollup_read_inspect_state(cmt_rollup_t *me, cmt_rollup_inspect_t *inspect) {
318
+ if (!me) {
319
+ return -EINVAL;
320
+ }
321
+ if (!inspect) {
322
+ return -EINVAL;
323
+ }
324
+
325
+ cmt_buf_t rd[1];
326
+ if (DBG(cmt_rollup_get_rx(me, rd))) {
327
+ return -ENOBUFS;
328
+ }
329
+
330
+ inspect->payload.length = cmt_buf_length(rd);
331
+ inspect->payload.data = rd->begin;
332
+ return 0;
333
+ }
334
+
335
+ static int accepted(union cmt_io_driver *io, uint32_t *n) {
336
+ struct cmt_io_yield req[1] = {{
337
+ .dev = HTIF_DEVICE_YIELD,
338
+ .cmd = HTIF_YIELD_CMD_MANUAL,
339
+ .reason = HTIF_YIELD_MANUAL_REASON_RX_ACCEPTED,
340
+ .data = *n,
341
+ }};
342
+ int rc = DBG(cmt_io_yield(io, req));
343
+ if (rc) {
344
+ return rc;
345
+ }
346
+
347
+ *n = req->data;
348
+ return req->reason;
349
+ }
350
+
351
+ static int revert(union cmt_io_driver *io) {
352
+ struct cmt_io_yield req[1] = {{
353
+ .dev = HTIF_DEVICE_YIELD,
354
+ .cmd = HTIF_YIELD_CMD_MANUAL,
355
+ .reason = HTIF_YIELD_MANUAL_REASON_RX_REJECTED,
356
+ .data = 0,
357
+ }};
358
+ return DBG(cmt_io_yield(io, req));
359
+ }
360
+
361
+ int cmt_rollup_finish(cmt_rollup_t *me, cmt_rollup_finish_t *finish) {
362
+ if (!me) {
363
+ return -EINVAL;
364
+ }
365
+ if (!finish) {
366
+ return -EINVAL;
367
+ }
368
+
369
+ if (!finish->accept_previous_request) {
370
+ return revert(me->io); /* revert should not return! */
371
+ }
372
+
373
+ uint64_t leaf_count = cmt_merkle_get_leaf_count(me->merkle);
374
+ if (me->finish_leaf_count != leaf_count) {
375
+ cmt_merkle_get_root_hash(me->merkle, me->finish_root_hash);
376
+ }
377
+ memcpy(cmt_io_get_tx(me->io).begin, me->finish_root_hash, CMT_ABI_U256_LENGTH);
378
+ me->fromhost_data = CMT_ABI_U256_LENGTH;
379
+ int reason = accepted(me->io, &me->fromhost_data);
380
+ if (reason < 0) {
381
+ return reason;
382
+ }
383
+ finish->next_request_type = reason;
384
+ finish->next_request_payload_length = me->fromhost_data;
385
+ me->finish_leaf_count = leaf_count;
386
+ return 0;
387
+ }
388
+
389
+ int cmt_gio_request(cmt_rollup_t *me, cmt_gio_t *req) {
390
+ if (!me) {
391
+ return -EINVAL;
392
+ }
393
+ if (!req) {
394
+ return -EINVAL;
395
+ }
396
+
397
+ /* Accept empty id */
398
+ if (!req->id && req->id_length) {
399
+ return -EINVAL;
400
+ }
401
+
402
+ cmt_buf_t wr[1] = {cmt_io_get_tx(me->io)};
403
+ cmt_buf_t _[1];
404
+ if (cmt_buf_split(wr, req->id_length, wr, _)) {
405
+ return -ENOBUFS;
406
+ }
407
+ if (req->id) {
408
+ memcpy(wr->begin, req->id, req->id_length);
409
+ }
410
+
411
+ struct cmt_io_yield rr[1] = {{
412
+ .dev = HTIF_DEVICE_YIELD,
413
+ .cmd = HTIF_YIELD_CMD_MANUAL,
414
+ .reason = req->domain,
415
+ .data = req->id_length,
416
+ }};
417
+
418
+ int rc = DBG(cmt_io_yield(me->io, rr));
419
+ if (rc != 0) {
420
+ return rc;
421
+ }
422
+ me->fromhost_data = rr->data;
423
+
424
+ cmt_buf_t rd[1];
425
+ if (cmt_rollup_get_rx(me, rd)) {
426
+ return -ENOBUFS;
427
+ }
428
+
429
+ req->response_data = rd->begin;
430
+ req->response_code = rr->reason;
431
+ req->response_data_length = rr->data;
432
+ return 0;
433
+ }
434
+
435
+ int cmt_rollup_progress(cmt_rollup_t *me, uint32_t progress) {
436
+ cmt_io_yield_t req[1] = {{
437
+ .dev = HTIF_DEVICE_YIELD,
438
+ .cmd = HTIF_YIELD_CMD_AUTOMATIC,
439
+ .reason = HTIF_YIELD_AUTOMATIC_REASON_PROGRESS,
440
+ .data = progress,
441
+ }};
442
+ return DBG(cmt_io_yield(me->io, req));
443
+ }
444
+
445
+ int cmt_rollup_load_merkle(cmt_rollup_t *me, const char *path) {
446
+ return DBG(cmt_merkle_load(me->merkle, path));
447
+ }
448
+
449
+ int cmt_rollup_save_merkle(cmt_rollup_t *me, const char *path) {
450
+ return DBG(cmt_merkle_save(me->merkle, path));
451
+ }
452
+
453
+ void cmt_rollup_reset_merkle(cmt_rollup_t *me) {
454
+ cmt_merkle_reset(me->merkle);
455
+ }