@deroll/cm 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.
- package/LICENSE +201 -0
- package/README.md +18 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +671 -0
- package/dist/index.d.ts +671 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023 Danilo Tuler
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# node-cartesi-machine
|
|
2
|
+
|
|
3
|
+
This is a JavaScript/TypeScript library for interacting with Cartesi Machines.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
Documentation is available at [https://tuler.github.io/node-cartesi-machine/](https://tuler.github.io/node-cartesi-machine/)
|
|
8
|
+
|
|
9
|
+
## Building
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
pnpm i
|
|
13
|
+
pnpm run build
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
License under [Apache-2](./LICENSE).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var Q=Object.create;var w=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var nt=(o,n)=>{for(var e in n)w(o,e,{get:n[e],enumerable:!0})},P=(o,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of R(n))!et.call(o,i)&&i!==e&&w(o,i,{get:()=>n[i],enumerable:!(r=Z(n,i))||r.enumerable});return o};var H=(o,n,e)=>(e=o!=null?Q(tt(o)):{},P(n||!o||!o.__esModule?w(e,"default",{value:o,enumerable:!0}):e,o)),rt=o=>P(w({},"__esModule",{value:!0}),o);var Ce={};nt(Ce,{BreakReason:()=>B,CleanupCall:()=>G,CmioYieldCommand:()=>z,CmioYieldReason:()=>x,Constant:()=>A,ErrorCode:()=>M,MAX_MCYCLE:()=>k,MachineError:()=>c,PmaConstant:()=>Yt,Reg:()=>V,RollupsFatalError:()=>d,RollupsInputRejectedError:()=>v,UarchBreakReason:()=>$,connect:()=>we,create:()=>zt,empty:()=>$t,getDefaultConfig:()=>Gt,getLastError:()=>Wt,getRegAddress:()=>Kt,load:()=>Vt,rollups:()=>ge,spawn:()=>T,verifyResetUarch:()=>Rt,verifySendCmioResponse:()=>te,verifyStep:()=>Qt,verifyStepUarch:()=>Zt});module.exports=rt(Ce);var Y=H(require("koffi"),1);var D=H(require("koffi"),1),O=require("os"),b=require("path");function it(){let o=(0,O.platform)(),n=[];switch(o){case"linux":process.env.LD_LIBRARY_PATH&&n.push(...process.env.LD_LIBRARY_PATH.split(":"));break;case"darwin":process.env.DYLD_LIBRARY_PATH&&n.push(...process.env.DYLD_LIBRARY_PATH.split(":")),process.env.DYLD_FALLBACK_LIBRARY_PATH&&n.push(...process.env.DYLD_FALLBACK_LIBRARY_PATH.split(":"));break;case"win32":process.env.PATH&&n.push(...process.env.PATH.split(";"));break}return n}function ot(o){let n=(0,O.platform)();switch(n){case"darwin":return`lib${o}.dylib`;case"linux":return`lib${o}.so`;case"win32":return`${o}.dll`;default:throw new Error(`Unsupported platform: ${n}`)}}function y(o,n=[]){let e=ot(o),r=it(),i=["/usr/lib","/usr/local/lib","/opt/homebrew/lib","/opt/local/lib",".",(0,b.join)(process.cwd(),"lib"),(0,b.join)(process.cwd(),"build")],m=[...n,...r,...i];for(let s of m)try{let f=(0,b.join)(s,e);return D.default.load(f)}catch{}throw new Error(`Failed to load library '${e}'. Tried paths: ${m.join(", ")}`)}var u=y("cartesi");Y.default.opaque("cm_machine");var ct=u.func("const char* cm_get_last_error_message()"),I=u.func("int cm_get_default_config(const cm_machine* m, _Out_ const char** config)"),N=u.func("int cm_get_reg_address(const cm_machine* m, int reg, _Out_ uint64_t* val)"),st=u.func("int cm_new(_Out_ cm_machine** new_m)"),at=u.func("int cm_clone_empty(const cm_machine* m, _Out_ cm_machine** new_m)"),ut=u.func("int cm_is_empty(const cm_machine* m, _Out_ bool* yes)"),mt=u.func("void cm_delete(cm_machine* m)"),lt=u.func("int cm_create(cm_machine* m, const char* config, const char* runtime_config)"),ft=u.func("int cm_create_new(const char* config, const char* runtime_config, _Out_ cm_machine** new_m)"),ht=u.func("int cm_load(cm_machine* m, const char* dir, const char* runtime_config)"),_t=u.func("int cm_load_new(const char* dir, const char* runtime_config, _Out_ cm_machine** new_m)"),dt=u.func("int cm_store(const cm_machine* m, const char* dir)"),pt=u.func("int cm_destroy(cm_machine* m)"),yt=u.func("int cm_set_runtime_config(cm_machine* m, const char* runtime_config)"),vt=u.func("int cm_get_runtime_config(const cm_machine* m, _Out_ const char** runtime_config)"),wt=u.func("int cm_replace_memory_range(cm_machine* m, uint64_t start, uint64_t length, bool shared, const char* image_filename)"),bt=u.func("int cm_get_initial_config(const cm_machine* m, _Out_ const char** config)"),Mt=u.func("int cm_get_memory_ranges(const cm_machine* m, _Out_ const char** ranges)"),gt=u.func("int cm_get_root_hash(const cm_machine* m, _Out_ uint8_t* hash)"),Ct=u.func("int cm_get_proof(const cm_machine* m, uint64_t address, int32_t log2_size, _Out_ const char** proof)"),Ot=u.func("int cm_read_word(const cm_machine* m, uint64_t address, _Out_ uint64_t* val)"),kt=u.func("int cm_read_reg(const cm_machine* m, int reg, _Out_ uint64_t* val)"),At=u.func("int cm_write_reg(cm_machine* m, int reg, uint64_t val)"),Bt=u.func("int cm_read_memory(const cm_machine* m, uint64_t address, uint8_t* data, uint64_t length)"),xt=u.func("int cm_write_memory(cm_machine* m, uint64_t address, const uint8_t* data, uint64_t length)"),St=u.func("int cm_read_virtual_memory(const cm_machine* m, uint64_t address, uint8_t* data, uint64_t length)"),Tt=u.func("int cm_write_virtual_memory(cm_machine* m, uint64_t address, const uint8_t* data, uint64_t length)"),Ft=u.func("int cm_translate_virtual_address(const cm_machine* m, uint64_t vaddr, uint64_t* paddr)"),Lt=u.func("int cm_run(cm_machine* m, uint64_t mcycle_end, _Out_ int* break_reason)"),Xt=u.func("int cm_run_uarch(cm_machine* m, uint64_t uarch_cycle_end, _Out_ int* uarch_break_reason)"),Ut=u.func("int cm_reset_uarch(cm_machine* m)"),Pt=u.func("int cm_receive_cmio_request(const cm_machine* m, _Out_ uint8_t* cmd, _Out_ uint16_t* reason, _Inout_ uint8_t* data, _Inout_ uint64_t* length)"),Ht=u.func("int cm_send_cmio_response(cm_machine* m, uint16_t reason, const uint8_t* data, uint64_t length)"),Dt=u.func("int cm_log_step(cm_machine* m, uint64_t mcycle_count, const char* log_filename, _Out_ int* break_reason)"),It=u.func("int cm_log_step_uarch(cm_machine* m, int32_t log_type, _Out_ const char** log)"),Nt=u.func("int cm_log_reset_uarch(cm_machine* m, int32_t log_type, _Out_ const char** log)"),jt=u.func("int cm_log_send_cmio_response(cm_machine* m, uint16_t reason, const uint8_t* data, uint64_t length, int32_t log_type, _Out_ const char** log)"),j=u.func("int cm_verify_step(const cm_machine* m, const uint8_t* root_hash_before, const char* log_filename, uint64_t mcycle_count, const uint8_t* root_hash_after, _Out_ int* break_reason)"),J=u.func("int cm_verify_step_uarch(const cm_machine* m, const uint8_t* root_hash_before, const char* log, const uint8_t* root_hash_after)"),E=u.func("int cm_verify_reset_uarch(const cm_machine* m, const uint8_t* root_hash_before, const char* log, const uint8_t* root_hash_after)"),q=u.func("int cm_verify_send_cmio_response(const cm_machine* m, uint16_t reason, const uint8_t* data, uint64_t length, const uint8_t* root_hash_before, const char* log, const uint8_t* root_hash_after)"),Jt=u.func("int cm_verify_merkle_tree(cm_machine* m, _Out_ bool* result)"),Et=u.func("int cm_verify_dirty_page_maps(cm_machine* m, _Out_ bool* result)");var qt=new FinalizationRegistry(o=>{o&&mt(o)}),h=class o{constructor(n){this.machine=null;this.machine=n,qt.register(this,n)}static new(){let n=[null],e=st(n);if(e!==0)throw c.fromCode(e);return new o(n[0])}cloneEmpty(){let n=[null],e=at(this.machine,n);if(e!==0)throw c.fromCode(e);return new o(n[0])}static createNew(n,e){let r=[null],i=ft(JSON.stringify(n),e?JSON.stringify(e):null,r);if(i!==0)throw c.fromCode(i);return new o(r[0])}static loadNew(n,e){let r=[null],i=_t(n,e?JSON.stringify(e):null,r);if(i!==0)throw c.fromCode(i);return new o(r[0])}static getLastError(){return ct()}getDefaultConfig(){let n=[null],e=I(this.machine,n);if(e!==0)throw c.fromCode(e);return JSON.parse(n[0])}static getDefaultConfig(){let n=[null],e=I(null,n);if(e!==0)throw c.fromCode(e);return JSON.parse(n[0])}getRegAddress(n){let e=[0n],r=N(this.machine,n,e);if(r!==0)throw c.fromCode(r);return e[0]}static getRegAddress(n){let e=[0n],r=N(null,n,e);if(r!==0)throw c.fromCode(r);return e[0]}isEmpty(){let n=[!1],e=ut(this.machine,n);if(e!==0)throw c.fromCode(e);return n[0]}create(n,e){let r=lt(this.machine,JSON.stringify(n),e?JSON.stringify(e):null);if(r!==0)throw c.fromCode(r);return this}load(n,e){let r=ht(this.machine,n,e?JSON.stringify(e):null);if(r!==0)throw c.fromCode(r);return this}store(n){let e=dt(this.machine,n);if(e!==0)throw c.fromCode(e);return this}destroy(){let n=pt(this.machine);if(n!==0)throw c.fromCode(n)}setRuntimeConfig(n){let e=yt(this.machine,JSON.stringify(n));if(e!==0)throw c.fromCode(e)}getRuntimeConfig(){let n=[null],e=vt(this.machine,n);if(e!==0)throw c.fromCode(e);return JSON.parse(n[0])}replaceMemoryRange(n,e,r,i){let m=wt(this.machine,n,e,r,i||null);if(m!==0)throw c.fromCode(m)}getInitialConfig(){let n=[null],e=bt(this.machine,n);if(e!==0)throw c.fromCode(e);return JSON.parse(n[0])}getMemoryRanges(){let n=[null],e=Mt(this.machine,n);if(e!==0)throw c.fromCode(e);return JSON.parse(n[0])}getRootHash(){let n=Buffer.alloc(32),e=gt(this.machine,n);if(e!==0)throw c.fromCode(e);return n}getProof(n,e){let r=[null],i=Ct(this.machine,n,e,r);if(i!==0)throw c.fromCode(i);return JSON.parse(r[0])}readWord(n){let e=[0n],r=Ot(this.machine,n,e);if(r!==0)throw c.fromCode(r);return e[0]}readReg(n){let e=[0n],r=kt(this.machine,n,e);if(r!==0)throw c.fromCode(r);return e[0]}writeReg(n,e){let r=At(this.machine,n,e);if(r!==0)throw c.fromCode(r)}readMemory(n,e){let r=Buffer.alloc(Number(e)),i=Bt(this.machine,n,r,e);if(i!==0)throw c.fromCode(i);return r}writeMemory(n,e){let r=xt(this.machine,n,e,BigInt(e.length));if(r!==0)throw c.fromCode(r)}readVirtualMemory(n,e){let r=Buffer.alloc(Number(e)),i=St(this.machine,n,r,e);if(i!==0)throw c.fromCode(i);return r}writeVirtualMemory(n,e){let r=Tt(this.machine,n,e,BigInt(e.length));if(r!==0)throw c.fromCode(r)}translateVirtualAddress(n){let e=[0n],r=Ft(this.machine,n,e);if(r!==0)throw c.fromCode(r);return e[0]}run(n=k){let e=[0],r=Lt(this.machine,n,e);if(r!==0)throw c.fromCode(r);return e[0]}runUarch(n){let e=[0],r=Xt(this.machine,n,e);if(r!==0)throw c.fromCode(r);return e[0]}resetUarch(){let n=Ut(this.machine);if(n!==0)throw c.fromCode(n)}receiveCmioRequest(){let n=[0],e=[0],r=Buffer.allocUnsafe(2*1024*1024),i=[r.length],m=Pt(this.machine,n,e,r,i);if(m!==0)throw c.fromCode(m);return{cmd:n[0],reason:e[0],data:r.subarray(0,i[0])}}sendCmioResponse(n,e){let r=Ht(this.machine,n,e,BigInt(e.length));if(r!==0)throw c.fromCode(r)}logStep(n,e){let r=[0],i=Dt(this.machine,n,e,r);if(i!==0)throw c.fromCode(i);return r[0]}logStepUarch(n){let e=[null],r=0;r|=n.has_annotations?1:0,r|=n.has_large_data?2:0;let i=It(this.machine,r,e);if(i!==0)throw c.fromCode(i);return JSON.parse(e[0])}logResetUarch(n){let e=[null],r=0;r|=n.has_annotations?1:0,r|=n.has_large_data?2:0;let i=Nt(this.machine,r,e);if(i!==0)throw c.fromCode(i);return JSON.parse(e[0])}logSendCmioResponse(n,e,r){let i=[null],m=0;m|=r.has_annotations?1:0,m|=r.has_large_data?2:0;let s=jt(this.machine,n,e,BigInt(e.length),m,i);if(s!==0)throw c.fromCode(s);return i[0]}verifyStep(n,e,r,i){let m=[0],s=j(this.machine,n,e,r,i,m);if(s!==0)throw c.fromCode(s);return m[0]}static verifyStep(n,e,r,i){let m=[0],s=j(null,n,e,r,i,m);if(s!==0)throw c.fromCode(s);return m[0]}verifyStepUarch(n,e,r){let i=J(this.machine,n,JSON.stringify(e),r);if(i!==0)throw c.fromCode(i)}static verifyStepUarch(n,e,r){let i=J(null,n,JSON.stringify(e),r);if(i!==0)throw c.fromCode(i)}verifyResetUarch(n,e,r){let i=E(this.machine,n,JSON.stringify(e),r);if(i!==0)throw c.fromCode(i)}static verifyResetUarch(n,e,r){let i=E(null,n,JSON.stringify(e),r);if(i!==0)throw c.fromCode(i)}verifySendCmioResponse(n,e,r,i,m){let s=q(this.machine,n,e,BigInt(e.length),r,JSON.stringify(i),m);if(s!==0)throw c.fromCode(s)}static verifySendCmioResponse(n,e,r,i,m){let s=q(null,n,e,BigInt(e.length),r,JSON.stringify(i),m);if(s!==0)throw c.fromCode(s)}verifyMerkleTree(){let n=[!1],e=Jt(this.machine,n);if(e!==0)throw c.fromCode(e);return n[0]}verifyDirtyPageMaps(){let n=[!1],e=Et(this.machine,n);if(e!==0)throw c.fromCode(e);return n[0]}};var k=0xffffffffffffffffffn,A=(i=>(i[i.HashSize=32]="HashSize",i[i.TreeLog2WordSize=5]="TreeLog2WordSize",i[i.TreeLog2PageSize=12]="TreeLog2PageSize",i[i.TreeLog2RootSize=64]="TreeLog2RootSize",i))(A||{}),Yt={CmioRxBufferStart:0x60000000n,CmioRxBufferLog2Size:21,CmioTxBufferStart:0x60800000n,CmioTxBufferLog2Size:21,RamStart:0x80000000n},M=(a=>(a[a.Ok=0]="Ok",a[a.InvalidArgument=-1]="InvalidArgument",a[a.DomainError=-2]="DomainError",a[a.LengthError=-3]="LengthError",a[a.OutOfRange=-4]="OutOfRange",a[a.LogicError=-5]="LogicError",a[a.RuntimeError=-6]="RuntimeError",a[a.RangeError=-7]="RangeError",a[a.OverflowError=-8]="OverflowError",a[a.UnderflowError=-9]="UnderflowError",a[a.RegexError=-10]="RegexError",a[a.SystemError=-11]="SystemError",a[a.BadTypeid=-12]="BadTypeid",a[a.BadCast=-13]="BadCast",a[a.BadAnyCast=-14]="BadAnyCast",a[a.BadOptionalAccess=-15]="BadOptionalAccess",a[a.BadWeakPtr=-16]="BadWeakPtr",a[a.BadFunctionCall=-17]="BadFunctionCall",a[a.BadAlloc=-18]="BadAlloc",a[a.BadArrayNewLength=-19]="BadArrayNewLength",a[a.BadException=-20]="BadException",a[a.BadVariantAccess=-21]="BadVariantAccess",a[a.Exception=-22]="Exception",a[a.Unknown=-23]="Unknown",a))(M||{}),c=class o extends Error{constructor(n,e){let r=`Cartesi Machine Error: ${e} (code: ${n})`;super(r),this.name="MachineError",this.code=n,this.description=e,Error.captureStackTrace&&Error.captureStackTrace(this,o)}static fromCode(n){let e=h.getLastError();return new o(n,e)}},B=(s=>(s[s.Failed=0]="Failed",s[s.Halted=1]="Halted",s[s.YieldedManually=2]="YieldedManually",s[s.YieldedAutomatically=3]="YieldedAutomatically",s[s.YieldedSoftly=4]="YieldedSoftly",s[s.ReachedTargetMcycle=5]="ReachedTargetMcycle",s))(B||{}),$=(r=>(r[r.ReachedTargetCycle=0]="ReachedTargetCycle",r[r.UarchHalted=1]="UarchHalted",r[r.Failed=2]="Failed",r))($||{}),z=(e=>(e[e.Automatic=0]="Automatic",e[e.Manual=1]="Manual",e))(z||{}),x=(l=>(l[l.AutomaticProgress=1]="AutomaticProgress",l[l.AutomaticTxOutput=2]="AutomaticTxOutput",l[l.AutomaticTxReport=4]="AutomaticTxReport",l[l.ManualRxAccepted=1]="ManualRxAccepted",l[l.ManualRxRejected=2]="ManualRxRejected",l[l.ManualTxException=4]="ManualTxException",l[l.AdvanceState=0]="AdvanceState",l[l.InspectState=1]="InspectState",l))(x||{}),V=(t=>(t[t.X0=0]="X0",t[t.X1=1]="X1",t[t.X2=2]="X2",t[t.X3=3]="X3",t[t.X4=4]="X4",t[t.X5=5]="X5",t[t.X6=6]="X6",t[t.X7=7]="X7",t[t.X8=8]="X8",t[t.X9=9]="X9",t[t.X10=10]="X10",t[t.X11=11]="X11",t[t.X12=12]="X12",t[t.X13=13]="X13",t[t.X14=14]="X14",t[t.X15=15]="X15",t[t.X16=16]="X16",t[t.X17=17]="X17",t[t.X18=18]="X18",t[t.X19=19]="X19",t[t.X20=20]="X20",t[t.X21=21]="X21",t[t.X22=22]="X22",t[t.X23=23]="X23",t[t.X24=24]="X24",t[t.X25=25]="X25",t[t.X26=26]="X26",t[t.X27=27]="X27",t[t.X28=28]="X28",t[t.X29=29]="X29",t[t.X30=30]="X30",t[t.X31=31]="X31",t[t.F0=32]="F0",t[t.F1=33]="F1",t[t.F2=34]="F2",t[t.F3=35]="F3",t[t.F4=36]="F4",t[t.F5=37]="F5",t[t.F6=38]="F6",t[t.F7=39]="F7",t[t.F8=40]="F8",t[t.F9=41]="F9",t[t.F10=42]="F10",t[t.F11=43]="F11",t[t.F12=44]="F12",t[t.F13=45]="F13",t[t.F14=46]="F14",t[t.F15=47]="F15",t[t.F16=48]="F16",t[t.F17=49]="F17",t[t.F18=50]="F18",t[t.F19=51]="F19",t[t.F20=52]="F20",t[t.F21=53]="F21",t[t.F22=54]="F22",t[t.F23=55]="F23",t[t.F24=56]="F24",t[t.F25=57]="F25",t[t.F26=58]="F26",t[t.F27=59]="F27",t[t.F28=60]="F28",t[t.F29=61]="F29",t[t.F30=62]="F30",t[t.F31=63]="F31",t[t.Pc=64]="Pc",t[t.Fcsr=65]="Fcsr",t[t.Mvendorid=66]="Mvendorid",t[t.Marchid=67]="Marchid",t[t.Mimpid=68]="Mimpid",t[t.Mcycle=69]="Mcycle",t[t.Icycleinstret=70]="Icycleinstret",t[t.Mstatus=71]="Mstatus",t[t.Mtvec=72]="Mtvec",t[t.Mscratch=73]="Mscratch",t[t.Mepc=74]="Mepc",t[t.Mcause=75]="Mcause",t[t.Mtval=76]="Mtval",t[t.Misa=77]="Misa",t[t.Mie=78]="Mie",t[t.Mip=79]="Mip",t[t.Medeleg=80]="Medeleg",t[t.Mideleg=81]="Mideleg",t[t.Mcounteren=82]="Mcounteren",t[t.Menvcfg=83]="Menvcfg",t[t.Stvec=84]="Stvec",t[t.Sscratch=85]="Sscratch",t[t.Sepc=86]="Sepc",t[t.Scause=87]="Scause",t[t.Stval=88]="Stval",t[t.Satp=89]="Satp",t[t.Scounteren=90]="Scounteren",t[t.Senvcfg=91]="Senvcfg",t[t.Ilrsc=92]="Ilrsc",t[t.Iprv=93]="Iprv",t[t.IflagsX=94]="IflagsX",t[t.IflagsY=95]="IflagsY",t[t.IflagsH=96]="IflagsH",t[t.Iunrep=97]="Iunrep",t[t.ClintMtimecmp=98]="ClintMtimecmp",t[t.PlicGirqpend=99]="PlicGirqpend",t[t.PlicGirqsrvd=100]="PlicGirqsrvd",t[t.HtifToHost=101]="HtifToHost",t[t.HtifFromHost=102]="HtifFromHost",t[t.HtifIhalt=103]="HtifIhalt",t[t.HtifIconsole=104]="HtifIconsole",t[t.HtifIyield=105]="HtifIyield",t[t.UarchX0=106]="UarchX0",t[t.UarchX1=107]="UarchX1",t[t.UarchX2=108]="UarchX2",t[t.UarchX3=109]="UarchX3",t[t.UarchX4=110]="UarchX4",t[t.UarchX5=111]="UarchX5",t[t.UarchX6=112]="UarchX6",t[t.UarchX7=113]="UarchX7",t[t.UarchX8=114]="UarchX8",t[t.UarchX9=115]="UarchX9",t[t.UarchX10=116]="UarchX10",t[t.UarchX11=117]="UarchX11",t[t.UarchX12=118]="UarchX12",t[t.UarchX13=119]="UarchX13",t[t.UarchX14=120]="UarchX14",t[t.UarchX15=121]="UarchX15",t[t.UarchX16=122]="UarchX16",t[t.UarchX17=123]="UarchX17",t[t.UarchX18=124]="UarchX18",t[t.UarchX19=125]="UarchX19",t[t.UarchX20=126]="UarchX20",t[t.UarchX21=127]="UarchX21",t[t.UarchX22=128]="UarchX22",t[t.UarchX23=129]="UarchX23",t[t.UarchX24=130]="UarchX24",t[t.UarchX25=131]="UarchX25",t[t.UarchX26=132]="UarchX26",t[t.UarchX27=133]="UarchX27",t[t.UarchX28=134]="UarchX28",t[t.UarchX29=135]="UarchX29",t[t.UarchX30=136]="UarchX30",t[t.UarchX31=137]="UarchX31",t[t.UarchPc=138]="UarchPc",t[t.UarchCycle=139]="UarchCycle",t[t.UarchHaltFlag=140]="UarchHaltFlag",t[t.HtifToHostDev=141]="HtifToHostDev",t[t.HtifToHostCmd=142]="HtifToHostCmd",t[t.HtifToHostReason=143]="HtifToHostReason",t[t.HtifToHostData=144]="HtifToHostData",t[t.HtifFromHostDev=145]="HtifFromHostDev",t[t.HtifFromHostCmd=146]="HtifFromHostCmd",t[t.HtifFromHostReason=147]="HtifFromHostReason",t[t.HtifFromHostData=148]="HtifFromHostData",t[t.Unknown_=149]="Unknown_",t[t.First_=150]="First_",t[t.Last_=151]="Last_",t))(V||{});function $t(){return h.new()}function zt(o,n){return h.createNew(o,n)}function Vt(o,n){return h.loadNew(o,n)}function Wt(){return h.getLastError()}function Gt(){return h.getDefaultConfig()}function Kt(o){return h.getRegAddress(o)}function Qt(o,n,e,r){return h.verifyStep(o,n,e,r)}function Zt(o,n,e){h.verifyStepUarch(o,n,e)}function Rt(o,n,e){h.verifyResetUarch(o,n,e)}function te(o,n,e,r,i){h.verifySendCmioResponse(o,n,e,r,i)}var _=y("cartesi_jsonrpc"),ee=y("c"),ne=_.func("int cm_jsonrpc_spawn_server(const char *address, int64_t spawn_timeout_ms, _Out_ cm_machine **new_m, _Out_ const char **bound_address, _Out_ uint32_t *pid)"),re=_.func("int cm_jsonrpc_connect_server(const char *address, int64_t connect_timeout_ms, _Out_ cm_machine **new_m)"),ie=_.func("int cm_jsonrpc_fork_server(const cm_machine *m, _Out_ cm_machine **forked_m, _Out_ const char **address, _Out_ uint32_t *pid)"),oe=_.func("int cm_jsonrpc_shutdown_server(cm_machine *m)"),ce=_.func("int cm_jsonrpc_rebind_server(cm_machine *m, const char *address, _Out_ const char **address_bound)"),se=_.func("int cm_jsonrpc_get_server_version(const cm_machine *m, _Out_ const char **version)"),ae=_.func("int cm_jsonrpc_emancipate_server(cm_machine *m)"),ue=_.func("int cm_jsonrpc_set_timeout(cm_machine *m, int64_t ms)"),me=_.func("int cm_jsonrpc_get_timeout(cm_machine *m, _Out_ int64_t *ms)"),le=_.func("int cm_jsonrpc_set_cleanup_call(cm_machine *m, int call)"),fe=_.func("int cm_jsonrpc_get_cleanup_call(cm_machine *m, _Out_ int *call)"),he=_.func("int cm_jsonrpc_get_server_address(cm_machine *m, _Out_ const char **address)"),_e=_.func("int cm_jsonrpc_delay_next_request(cm_machine *m, uint64_t ms)"),S=ee.func("int fcntl(int fd, int cmd, int arg)"),de=1,W=2,pe=1;function ye(o){let n=S(o,de,0);if(n===-1)throw new Error(`Failed to get flags for fd ${o}`);let e=n&~pe;if(S(o,W,e)===-1)throw new Error(`Failed to set flags for fd ${o}`);return n}function ve(o,n){if(S(o,W,n)===-1)throw new Error(`Failed to set flags for fd ${o}`)}var p=class o extends h{constructor(){super(...arguments);this.serverAddress=null;this.serverPid=null}static spawn(e="127.0.0.1:0",r=-1){let i=ye(1);try{let m=[null],s=[null],f=[null],l=ne(e,r,m,s,f);if(l!==0)throw c.fromCode(l);if(s[0]===null||f[0]===null)throw new Error("Failed to get output parameters from spawn server");let C=new o(m[0]);return C.serverAddress=s[0],C.serverPid=f[0],C}finally{ve(1,i)}}static connect(e,r=-1){let i=[null],m=re(e,r,i);if(m!==0)throw c.fromCode(m);let s=new o(i[0]);return s.serverAddress=e,s}fork(){let e=[null],r=[null],i=[null],m=ie(this.machine,e,r,i);if(m!==0)throw c.fromCode(m);if(r[0]===null||i[0]===null)throw new Error("Failed to get output parameters from fork server");let s=new o(e[0]);return s.serverAddress=r[0],s.serverPid=i[0],s}shutdown(){let e=oe(this.machine);if(e!==0)throw c.fromCode(e)}rebind(e){let r=[null],i=ce(this.machine,e,r);if(i!==0)throw c.fromCode(i);if(r[0]===null)throw new Error("Failed to get bound address from rebind server");return this.serverAddress=r[0],r[0]}getServerVersion(){let e=[null],r=se(this.machine,e);if(r!==0)throw c.fromCode(r);if(e[0]===null)throw new Error("Failed to get server version");return e[0]}emancipate(){let e=ae(this.machine);if(e!==0)throw c.fromCode(e)}setTimeout(e){let r=ue(this.machine,e);if(r!==0)throw c.fromCode(r)}getTimeout(){let e=[null],r=me(this.machine,e);if(r!==0)throw c.fromCode(r);if(e[0]===null)throw new Error("Failed to get timeout");return e[0]}setCleanupCall(e){let r=le(this.machine,e);if(r!==0)throw c.fromCode(r);return this}getCleanupCall(){let e=[null],r=fe(this.machine,e);if(r!==0)throw c.fromCode(r);if(e[0]===null)throw new Error("Failed to get cleanup call");return e[0]}getServerAddress(){let e=[null],r=he(this.machine,e);if(r!==0)throw c.fromCode(r);if(e[0]===null)throw new Error("Failed to get server address");return e[0]}delayNextRequest(e){let r=_e(this.machine,e);if(r!==0)throw c.fromCode(r)}getBoundAddress(){return this.serverAddress}getServerPid(){return this.serverPid}load(e,r){return super.load(e,r),this}cloneEmpty(){return super.cloneEmpty(),this}create(e,r){return super.create(e,r),this}store(e){return super.store(e),this}};var G=(r=>(r[r.Nothing=0]="Nothing",r[r.Destroy=1]="Destroy",r[r.Shutdown=2]="Shutdown",r))(G||{});function T(o="127.0.0.1:0",n=-1){return p.spawn(o,n)}function we(o,n=-1){return p.connect(o,n)}var d=class extends Error{constructor(n){super(n),this.name="RollupsFatalError"}},v=class extends Error{constructor(){super("Input rejected"),this.name="RollupsInputRejectedError"}};function be(o){return new U(o)}function K(o,n){return new X(o,n?.noRollback??!1)}var F="127.0.0.1:0",L=-1;function Me(o,n){let{runtimeConfig:e}=n??{address:F,timeout:L,runtimeConfig:void 0},r=n?.address??F,i=n?.timeout??L,m=T(r,i).load(o,e);return K(m,n)}function ge(o,n){return n=n??{noRollback:!1,address:F,timeout:L},typeof o=="string"?Me(o,n):o instanceof p?K(o,n):be(o)}var g=class{advance(n,e){let r=function*(){let i=this.startTransaction();for(i.sendCmioResponse(0,n);;){let m=i.run();switch(m){case 2:{let{reason:s,data:f}=i.receiveCmioRequest();switch(s){case 1:return this.commitTransaction(i),f;case 2:throw this.rollbackTransaction(i),new v;case 4:{this.rollbackTransaction(i);let l=f.toString("utf-8");throw new d(l)}default:throw this.rollbackTransaction(i),new d(`Unexpected yield reason: ${s}`)}}case 3:{let{reason:s,data:f}=i.receiveCmioRequest();switch(s){case 1:{try{yield{type:"progress",data:f.readUInt32LE()}}catch{}break}case 2:{yield{type:"output",data:f};break}case 4:{yield{type:"report",data:f};break}}continue}default:throw this.rollbackTransaction(i),new d(`Unexpected break reason: ${m}`)}}}.bind(this);if(e?.collect){let i=[],m=[],s=r();for(;;){let f=s.next();if(f.done)return{outputs:i,reports:m,outputsMerkleRoot:f.value};switch(f.value.type){case"output":i.push(f.value.data);break;case"report":m.push(f.value.data);break;case"progress":break}}}return r()}inspect(n,e){let r=function*(){let i=this.startTransaction();for(i.sendCmioResponse(1,n);;){let m=i.run();switch(m){case 2:{let{reason:s,data:f}=i.receiveCmioRequest();switch(s){case 1:{this.rollbackTransaction(i);return}case 2:throw this.rollbackTransaction(i),new v;case 4:{this.rollbackTransaction(i);let l=f.toString("utf-8");throw new d(l)}default:throw this.rollbackTransaction(i),new d(`Unexpected yield reason: ${s}`)}}case 3:{let{reason:s,data:f}=i.receiveCmioRequest();switch(s){case 1:break;case 2:break;case 4:{yield f;break}}continue}default:throw this.rollbackTransaction(i),new d(`Unexpected break reason: ${m}`)}}}.bind(this);return e?.collect?[...r()]:r()}},X=class extends g{constructor(n,e=!1){super(),this.machine=n,this.noRollback=e}startTransaction(){return this.noRollback?this.machine:this.machine.fork()}commitTransaction(n){this.noRollback||(this.machine.shutdown(),this.machine=n)}rollbackTransaction(n){this.noRollback||n.shutdown()}shutdown(){this.machine.shutdown()}store(n){return this.machine.store(n),this}},U=class extends g{constructor(n){super(),this.machine=n}startTransaction(){return this.machine}commitTransaction(n){this.machine=n}rollbackTransaction(n){this.machine=n}shutdown(){}store(n){return this.machine.store(n),this}};0&&(module.exports={BreakReason,CleanupCall,CmioYieldCommand,CmioYieldReason,Constant,ErrorCode,MAX_MCYCLE,MachineError,PmaConstant,Reg,RollupsFatalError,RollupsInputRejectedError,UarchBreakReason,connect,create,empty,getDefaultConfig,getLastError,getRegAddress,load,rollups,spawn,verifyResetUarch,verifySendCmioResponse,verifyStep,verifyStepUarch});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/node/cartesi-machine.ts","../src/node/lib-loader.ts","../src/cartesi-machine.ts","../src/node/remote-cartesi-machine.ts","../src/remote-cartesi-machine.ts","../src/rollups.ts"],"sourcesContent":["export * from \"./cartesi-machine\";\nexport * from \"./remote-cartesi-machine\";\nexport * from \"./rollups\";\nexport * from \"./types\";\n","import koffi from \"koffi\";\nimport type {\n BreakReason,\n CartesiMachine,\n CmioYieldCommand,\n CmioYieldReason,\n Reg,\n UarchBreakReason,\n} from \"../cartesi-machine\";\nimport {\n Constant,\n ErrorCode,\n MachineError,\n MAX_MCYCLE,\n} from \"../cartesi-machine\";\nimport type {\n AccessLog,\n AccessLogType,\n MachineConfig,\n MachineRuntimeConfig,\n MemoryRangeDescription,\n Proof,\n} from \"../types\";\nimport { loadLibrary } from \"./lib-loader\";\n\n// Load the Cartesi Machine library\nconst lib = loadLibrary(\"cartesi\");\n\n// -----------------------------------------------------------------------------\n// Opaque types\n// -----------------------------------------------------------------------------\n\n/// Machine object handle (opaque type)\nkoffi.opaque(\"cm_machine\");\n\n// -----------------------------------------------------------------------------\n// Function signatures\n// -----------------------------------------------------------------------------\n\n/// Returns the error message set by the very last C API call\nconst cm_get_last_error_message = lib.func(\n \"const char* cm_get_last_error_message()\",\n);\n\n/// Obtains a JSON object with the default machine config as a string\nconst cm_get_default_config = lib.func(\n \"int cm_get_default_config(const cm_machine* m, _Out_ const char** config)\",\n);\n\n/// Gets the address of any x, f, or control state register\nconst cm_get_reg_address = lib.func(\n \"int cm_get_reg_address(const cm_machine* m, int reg, _Out_ uint64_t* val)\",\n);\n\n/// Creates a new local machine object\nconst cm_new = lib.func(\"int cm_new(_Out_ cm_machine** new_m)\");\n\n/// Clones an empty machine object from an existing one\nconst cm_clone_empty = lib.func(\n \"int cm_clone_empty(const cm_machine* m, _Out_ cm_machine** new_m)\",\n);\n\n/// Checks if an object is empty (does not hold a machine instance)\nconst cm_is_empty = lib.func(\n \"int cm_is_empty(const cm_machine* m, _Out_ bool* yes)\",\n);\n\n/// Deletes a machine object\nconst cm_delete = lib.func(\"void cm_delete(cm_machine* m)\");\n\n/// Creates a new machine instance from configuration\nconst cm_create = lib.func(\n \"int cm_create(cm_machine* m, const char* config, const char* runtime_config)\",\n);\n\n/// Combines cm_new() and cm_create() for convenience\nconst cm_create_new = lib.func(\n \"int cm_create_new(const char* config, const char* runtime_config, _Out_ cm_machine** new_m)\",\n);\n\n/// Loads a new machine instance from a previously stored directory\nconst cm_load = lib.func(\n \"int cm_load(cm_machine* m, const char* dir, const char* runtime_config)\",\n);\n\n/// Combines cm_new() and cm_load() for convenience\nconst cm_load_new = lib.func(\n \"int cm_load_new(const char* dir, const char* runtime_config, _Out_ cm_machine** new_m)\",\n);\n\n/// Stores a machine instance to a directory, serializing its entire state\nconst cm_store = lib.func(\"int cm_store(const cm_machine* m, const char* dir)\");\n\n/// Destroy a machine instance and remove it from the object\nconst cm_destroy = lib.func(\"int cm_destroy(cm_machine* m)\");\n\n/// Changes the machine runtime configuration\nconst cm_set_runtime_config = lib.func(\n \"int cm_set_runtime_config(cm_machine* m, const char* runtime_config)\",\n);\n\n/// Gets the machine runtime configuration\nconst cm_get_runtime_config = lib.func(\n \"int cm_get_runtime_config(const cm_machine* m, _Out_ const char** runtime_config)\",\n);\n\n/// Replaces a memory range\nconst cm_replace_memory_range = lib.func(\n \"int cm_replace_memory_range(cm_machine* m, uint64_t start, uint64_t length, bool shared, const char* image_filename)\",\n);\n\n/// Returns a JSON object with the machine config used to initialize the machine\nconst cm_get_initial_config = lib.func(\n \"int cm_get_initial_config(const cm_machine* m, _Out_ const char** config)\",\n);\n\n/// Returns a list with all memory ranges in the machine\nconst cm_get_memory_ranges = lib.func(\n \"int cm_get_memory_ranges(const cm_machine* m, _Out_ const char** ranges)\",\n);\n\n/// Obtains the root hash of the Merkle tree\nconst cm_get_root_hash = lib.func(\n \"int cm_get_root_hash(const cm_machine* m, _Out_ uint8_t* hash)\",\n);\n\n/// Obtains the proof for a node in the machine state Merkle tree\nconst cm_get_proof = lib.func(\n \"int cm_get_proof(const cm_machine* m, uint64_t address, int32_t log2_size, _Out_ const char** proof)\",\n);\n\n/// Reads the value of a word in the machine state, by its physical address\nconst cm_read_word = lib.func(\n \"int cm_read_word(const cm_machine* m, uint64_t address, _Out_ uint64_t* val)\",\n);\n\n/// Reads the value of a register\nconst cm_read_reg = lib.func(\n \"int cm_read_reg(const cm_machine* m, int reg, _Out_ uint64_t* val)\",\n);\n\n/// Writes the value of a register\nconst cm_write_reg = lib.func(\n \"int cm_write_reg(cm_machine* m, int reg, uint64_t val)\",\n);\n\n/// Reads a chunk of data from a machine memory range, by its physical address\nconst cm_read_memory = lib.func(\n \"int cm_read_memory(const cm_machine* m, uint64_t address, uint8_t* data, uint64_t length)\",\n);\n\n/// Writes a chunk of data to a machine memory range, by its physical address\nconst cm_write_memory = lib.func(\n \"int cm_write_memory(cm_machine* m, uint64_t address, const uint8_t* data, uint64_t length)\",\n);\n\n/// Reads a chunk of data from a machine memory range, by its virtual address\nconst cm_read_virtual_memory = lib.func(\n \"int cm_read_virtual_memory(const cm_machine* m, uint64_t address, uint8_t* data, uint64_t length)\",\n);\n\n/// Writes a chunk of data to a machine memory range, by its virtual address\nconst cm_write_virtual_memory = lib.func(\n \"int cm_write_virtual_memory(cm_machine* m, uint64_t address, const uint8_t* data, uint64_t length)\",\n);\n\n/// Translates a virtual memory address to its corresponding physical memory address\nconst cm_translate_virtual_address = lib.func(\n \"int cm_translate_virtual_address(const cm_machine* m, uint64_t vaddr, uint64_t* paddr)\",\n);\n\n/// Runs the machine until CM_REG_MCYCLE reaches mcycle_end, the machine yields, or halts\nconst cm_run = lib.func(\n \"int cm_run(cm_machine* m, uint64_t mcycle_end, _Out_ int* break_reason)\",\n);\n\n/// Runs the machine microarchitecture until CM_REG_UARCH_CYCLE reaches uarch_cycle_end or it halts\nconst cm_run_uarch = lib.func(\n \"int cm_run_uarch(cm_machine* m, uint64_t uarch_cycle_end, _Out_ int* uarch_break_reason)\",\n);\n\n/// Resets the entire microarchitecture state to pristine values\nconst cm_reset_uarch = lib.func(\"int cm_reset_uarch(cm_machine* m)\");\n\n/// Receives a cmio request\nconst cm_receive_cmio_request = lib.func(\n \"int cm_receive_cmio_request(const cm_machine* m, _Out_ uint8_t* cmd, _Out_ uint16_t* reason, _Inout_ uint8_t* data, _Inout_ uint64_t* length)\",\n);\n\n/// Sends a cmio response\nconst cm_send_cmio_response = lib.func(\n \"int cm_send_cmio_response(cm_machine* m, uint16_t reason, const uint8_t* data, uint64_t length)\",\n);\n\n/// Runs the machine for the given mcycle count and generates a log of accessed pages and proof data\nconst cm_log_step = lib.func(\n \"int cm_log_step(cm_machine* m, uint64_t mcycle_count, const char* log_filename, _Out_ int* break_reason)\",\n);\n\n/// Runs the machine in the microarchitecture for one micro cycle logging all accesses to the state\nconst cm_log_step_uarch = lib.func(\n \"int cm_log_step_uarch(cm_machine* m, int32_t log_type, _Out_ const char** log)\",\n);\n\n/// Resets the entire microarchitecture state to pristine values logging all accesses to the state\nconst cm_log_reset_uarch = lib.func(\n \"int cm_log_reset_uarch(cm_machine* m, int32_t log_type, _Out_ const char** log)\",\n);\n\n/// Sends a cmio response logging all accesses to the state\nconst cm_log_send_cmio_response = lib.func(\n \"int cm_log_send_cmio_response(cm_machine* m, uint16_t reason, const uint8_t* data, uint64_t length, int32_t log_type, _Out_ const char** log)\",\n);\n\n/// Checks the validity of a step log file\nconst cm_verify_step = lib.func(\n \"int cm_verify_step(const cm_machine* m, const uint8_t* root_hash_before, const char* log_filename, uint64_t mcycle_count, const uint8_t* root_hash_after, _Out_ int* break_reason)\",\n);\n\n/// Checks the validity of a state transition produced by cm_log_step_uarch\nconst cm_verify_step_uarch = lib.func(\n \"int cm_verify_step_uarch(const cm_machine* m, const uint8_t* root_hash_before, const char* log, const uint8_t* root_hash_after)\",\n);\n\n/// Checks the validity of a state transition produced by cm_log_reset_uarch\nconst cm_verify_reset_uarch = lib.func(\n \"int cm_verify_reset_uarch(const cm_machine* m, const uint8_t* root_hash_before, const char* log, const uint8_t* root_hash_after)\",\n);\n\n/// Checks the validity of a state transition produced by cm_log_send_cmio_response\nconst cm_verify_send_cmio_response = lib.func(\n \"int cm_verify_send_cmio_response(const cm_machine* m, uint16_t reason, const uint8_t* data, uint64_t length, const uint8_t* root_hash_before, const char* log, const uint8_t* root_hash_after)\",\n);\n\n/// Verifies integrity of Merkle tree against current machine state\nconst cm_verify_merkle_tree = lib.func(\n \"int cm_verify_merkle_tree(cm_machine* m, _Out_ bool* result)\",\n);\n\n/// Verifies integrity of dirty page maps\nconst cm_verify_dirty_page_maps = lib.func(\n \"int cm_verify_dirty_page_maps(cm_machine* m, _Out_ bool* result)\",\n);\n\n/// Access log types\nenum AccessLogTypeEnum {\n Annotations = 1, ///< Includes annotations\n LargeData = 2, ///< Includes data larger than 8 bytes\n}\n\n// -----------------------------------------------------------------------------\n// High-level wrapper class\n// -----------------------------------------------------------------------------\n\n/**\n * High-level wrapper for the Cartesi Machine C API\n */\nconst machineFinalizer = new FinalizationRegistry((machineHandle: any) => {\n if (machineHandle) {\n cm_delete(machineHandle);\n }\n});\n\nexport class NodeCartesiMachine {\n protected machine: any = null;\n\n /**\n * Creates a new local machine object\n */\n static new(): CartesiMachine {\n const machine = [null];\n const result = cm_new(machine);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return new NodeCartesiMachine(machine[0]);\n }\n\n /**\n * Clones an empty machine object from an existing one\n */\n cloneEmpty(): CartesiMachine {\n // Cast to NodeCartesiMachine to access .machine (safe in this context)\n const machine = [null];\n const result = cm_clone_empty(this.machine, machine);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return new NodeCartesiMachine(machine[0]);\n }\n\n /**\n * Creates a new machine with configuration\n */\n static createNew(\n config: MachineConfig,\n runtimeConfig?: MachineRuntimeConfig,\n ): CartesiMachine {\n const machine = [null];\n const result = cm_create_new(\n JSON.stringify(config),\n runtimeConfig ? JSON.stringify(runtimeConfig) : null,\n machine,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return new NodeCartesiMachine(machine[0]);\n }\n\n /**\n * Loads a machine from a directory\n */\n static loadNew(\n dir: string,\n runtimeConfig?: MachineRuntimeConfig,\n ): CartesiMachine {\n const machine = [null];\n const result = cm_load_new(\n dir,\n runtimeConfig ? JSON.stringify(runtimeConfig) : null,\n machine,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return new NodeCartesiMachine(machine[0]);\n }\n\n constructor(machine: any) {\n this.machine = machine;\n machineFinalizer.register(this, machine);\n }\n\n /**\n * Gets the last error message\n */\n static getLastError(): string {\n return cm_get_last_error_message();\n }\n\n /**\n * Gets the default configuration\n */\n getDefaultConfig(): MachineConfig {\n const config: [string | null] = [null];\n const result = cm_get_default_config(this.machine, config);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return JSON.parse(config[0] as string) as MachineConfig;\n }\n\n /**\n * Gets the default configuration\n */\n static getDefaultConfig(): MachineConfig {\n const config: [string | null] = [null];\n const result = cm_get_default_config(null, config);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return JSON.parse(config[0] as string) as MachineConfig;\n }\n\n /**\n * Gets the address of a register\n */\n getRegAddress(reg: Reg): bigint {\n const address = [0n];\n const result = cm_get_reg_address(this.machine, reg, address);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return address[0];\n }\n\n /**\n * Gets the address of a register\n */\n static getRegAddress(reg: Reg): bigint {\n const address = [0n];\n const result = cm_get_reg_address(null, reg, address);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return address[0];\n }\n\n /**\n * Checks if the machine is empty\n */\n isEmpty(): boolean {\n const empty = [false];\n const result = cm_is_empty(this.machine, empty);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return empty[0];\n }\n\n /**\n * Creates a new machine instance from configuration\n */\n create(\n config: MachineConfig,\n runtimeConfig?: MachineRuntimeConfig,\n ): CartesiMachine {\n const result = cm_create(\n this.machine,\n JSON.stringify(config),\n runtimeConfig ? JSON.stringify(runtimeConfig) : null,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return this;\n }\n\n /**\n * Loads a machine instance from a directory\n */\n load(dir: string, runtimeConfig?: MachineRuntimeConfig): CartesiMachine {\n const result = cm_load(\n this.machine,\n dir,\n runtimeConfig ? JSON.stringify(runtimeConfig) : null,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return this;\n }\n\n /**\n * Stores the machine instance to a directory\n */\n store(dir: string): CartesiMachine {\n const result = cm_store(this.machine, dir);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return this;\n }\n\n /**\n * Destroys the machine instance\n */\n destroy(): void {\n const result = cm_destroy(this.machine);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Sets the runtime configuration\n */\n setRuntimeConfig(runtimeConfig: MachineRuntimeConfig): void {\n const result = cm_set_runtime_config(\n this.machine,\n JSON.stringify(runtimeConfig),\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Gets the runtime configuration\n */\n getRuntimeConfig(): MachineRuntimeConfig {\n const config: [string | null] = [null];\n const result = cm_get_runtime_config(this.machine, config);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return JSON.parse(config[0] as string) as MachineRuntimeConfig;\n }\n\n /**\n * Replaces a memory range\n */\n replaceMemoryRange(\n start: bigint,\n length: bigint,\n shared: boolean,\n imageFilename?: string,\n ): void {\n const result = cm_replace_memory_range(\n this.machine,\n start,\n length,\n shared,\n imageFilename || null,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Gets the initial configuration\n */\n getInitialConfig(): MachineConfig {\n const config: [string | null] = [null];\n const result = cm_get_initial_config(this.machine, config);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return JSON.parse(config[0] as string) as MachineConfig;\n }\n\n /**\n * Gets memory ranges\n */\n getMemoryRanges(): MemoryRangeDescription[] {\n const ranges: [string | null] = [null];\n const result = cm_get_memory_ranges(this.machine, ranges);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return JSON.parse(ranges[0] as string) as MemoryRangeDescription[];\n }\n\n /**\n * Gets the root hash\n */\n getRootHash(): Buffer {\n const hash = Buffer.alloc(Constant.HashSize);\n const result = cm_get_root_hash(this.machine, hash);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return hash;\n }\n\n /**\n * Gets a proof for a node in the Merkle tree\n */\n getProof(address: bigint, log2Size: number): Proof {\n const proof: [string | null] = [null];\n const result = cm_get_proof(this.machine, address, log2Size, proof);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return JSON.parse(proof[0] as string) as Proof;\n }\n\n /**\n * Reads a word from memory\n */\n readWord(address: bigint): bigint {\n const value = [0n];\n const result = cm_read_word(this.machine, address, value);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return value[0];\n }\n\n /**\n * Reads a register\n */\n readReg(reg: Reg): bigint {\n const value = [0n];\n const result = cm_read_reg(this.machine, reg, value);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return value[0];\n }\n\n /**\n * Writes a register\n */\n writeReg(reg: Reg, value: bigint): void {\n const result = cm_write_reg(this.machine, reg, value);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Reads memory\n */\n readMemory(address: bigint, length: bigint): Buffer {\n const data = Buffer.alloc(Number(length));\n const result = cm_read_memory(this.machine, address, data, length);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return data;\n }\n\n /**\n * Writes memory\n */\n writeMemory(address: bigint, data: Buffer): void {\n const result = cm_write_memory(\n this.machine,\n address,\n data,\n BigInt(data.length),\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Reads virtual memory\n */\n readVirtualMemory(address: bigint, length: bigint): Buffer {\n const data = Buffer.alloc(Number(length));\n const result = cm_read_virtual_memory(\n this.machine,\n address,\n data,\n length,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return data;\n }\n\n /**\n * Writes virtual memory\n */\n writeVirtualMemory(address: bigint, data: Buffer): void {\n const result = cm_write_virtual_memory(\n this.machine,\n address,\n data,\n BigInt(data.length),\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Translates a virtual address to physical address\n */\n translateVirtualAddress(vaddr: bigint): bigint {\n const paddr = [0n];\n const result = cm_translate_virtual_address(this.machine, vaddr, paddr);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return paddr[0];\n }\n\n /**\n * Runs the machine\n */\n run(mcycleEnd: bigint = MAX_MCYCLE): BreakReason {\n const breakReason = [0];\n const result = cm_run(this.machine, mcycleEnd, breakReason);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return breakReason[0];\n }\n\n /**\n * Runs the microarchitecture\n */\n runUarch(uarchCycleEnd: bigint): UarchBreakReason {\n const breakReason = [0];\n const result = cm_run_uarch(this.machine, uarchCycleEnd, breakReason);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return breakReason[0];\n }\n\n /**\n * Resets the microarchitecture\n */\n resetUarch(): void {\n const result = cm_reset_uarch(this.machine);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Receives a CMIO request\n */\n receiveCmioRequest(): {\n cmd: CmioYieldCommand;\n reason: CmioYieldReason;\n data: Buffer;\n } {\n const cmd = [0];\n const reason = [0];\n const data = Buffer.allocUnsafe(2 * 1024 * 1024); // 2MB buffer\n const length = [data.length];\n\n const result = cm_receive_cmio_request(\n this.machine,\n cmd,\n reason,\n data,\n length,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n\n return {\n cmd: cmd[0],\n reason: reason[0],\n data: data.subarray(0, length[0]),\n };\n }\n\n /**\n * Sends a CMIO response\n */\n sendCmioResponse(reason: CmioYieldReason, data: Buffer): void {\n const result = cm_send_cmio_response(\n this.machine,\n reason,\n data,\n BigInt(data.length),\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Logs a step\n */\n logStep(mcycleCount: bigint, logFilename: string): BreakReason {\n const breakReason = [0];\n const result = cm_log_step(\n this.machine,\n mcycleCount,\n logFilename,\n breakReason,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return breakReason[0];\n }\n\n /**\n * Logs a uarch step\n */\n logStepUarch(logType: AccessLogType): AccessLog {\n const log: [string | null] = [null];\n let type = 0;\n type |= logType.has_annotations ? AccessLogTypeEnum.Annotations : 0;\n type |= logType.has_large_data ? AccessLogTypeEnum.LargeData : 0;\n\n const result = cm_log_step_uarch(this.machine, type, log);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return JSON.parse(log[0] as string) as AccessLog;\n }\n\n /**\n * Logs uarch reset\n */\n logResetUarch(logType: AccessLogType): AccessLog {\n const log: [string | null] = [null];\n let type = 0;\n type |= logType.has_annotations ? AccessLogTypeEnum.Annotations : 0;\n type |= logType.has_large_data ? AccessLogTypeEnum.LargeData : 0;\n\n const result = cm_log_reset_uarch(this.machine, type, log);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return JSON.parse(log[0] as string) as AccessLog;\n }\n\n /**\n * Logs CMIO response\n */\n logSendCmioResponse(\n reason: CmioYieldReason,\n data: Buffer,\n logType: AccessLogType,\n ): string {\n const log: [string | null] = [null];\n let type = 0;\n type |= logType.has_annotations ? AccessLogTypeEnum.Annotations : 0;\n type |= logType.has_large_data ? AccessLogTypeEnum.LargeData : 0;\n\n const result = cm_log_send_cmio_response(\n this.machine,\n reason,\n data,\n BigInt(data.length),\n type,\n log,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return log[0] as string;\n }\n\n /**\n * Verifies a step\n */\n verifyStep(\n rootHashBefore: Buffer,\n logFilename: string,\n mcycleCount: bigint,\n rootHashAfter: Buffer,\n ): BreakReason {\n const breakReason = [0];\n const result = cm_verify_step(\n this.machine,\n rootHashBefore,\n logFilename,\n mcycleCount,\n rootHashAfter,\n breakReason,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return breakReason[0];\n }\n\n /**\n * Verifies a step\n */\n static verifyStep(\n rootHashBefore: Buffer,\n logFilename: string,\n mcycleCount: bigint,\n rootHashAfter: Buffer,\n ): BreakReason {\n const breakReason = [0];\n const result = cm_verify_step(\n null,\n rootHashBefore,\n logFilename,\n mcycleCount,\n rootHashAfter,\n breakReason,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return breakReason[0];\n }\n\n /**\n * Verifies a uarch step\n */\n verifyStepUarch(\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n ): void {\n const result = cm_verify_step_uarch(\n this.machine,\n rootHashBefore,\n JSON.stringify(log),\n rootHashAfter,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Verifies a uarch step\n */\n static verifyStepUarch(\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n ): void {\n const result = cm_verify_step_uarch(\n null,\n rootHashBefore,\n JSON.stringify(log),\n rootHashAfter,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Verifies uarch reset\n */\n verifyResetUarch(\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n ): void {\n const result = cm_verify_reset_uarch(\n this.machine,\n rootHashBefore,\n JSON.stringify(log),\n rootHashAfter,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Verifies uarch reset\n */\n static verifyResetUarch(\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n ): void {\n const result = cm_verify_reset_uarch(\n null,\n rootHashBefore,\n JSON.stringify(log),\n rootHashAfter,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Verifies CMIO response\n */\n verifySendCmioResponse(\n reason: CmioYieldReason,\n data: Buffer,\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n ): void {\n const result = cm_verify_send_cmio_response(\n this.machine,\n reason,\n data,\n BigInt(data.length),\n rootHashBefore,\n JSON.stringify(log),\n rootHashAfter,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Verifies CMIO response\n */\n static verifySendCmioResponse(\n reason: CmioYieldReason,\n data: Buffer,\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n ): void {\n const result = cm_verify_send_cmio_response(\n null,\n reason,\n data,\n BigInt(data.length),\n rootHashBefore,\n JSON.stringify(log),\n rootHashAfter,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n /**\n * Verifies Merkle tree integrity\n */\n verifyMerkleTree(): boolean {\n const result = [false];\n const error = cm_verify_merkle_tree(this.machine, result);\n if (error !== ErrorCode.Ok) {\n throw MachineError.fromCode(error);\n }\n return result[0];\n }\n\n /**\n * Verifies dirty page maps integrity\n */\n verifyDirtyPageMaps(): boolean {\n const result = [false];\n const error = cm_verify_dirty_page_maps(this.machine, result);\n if (error !== ErrorCode.Ok) {\n throw MachineError.fromCode(error);\n }\n return result[0];\n }\n}\n","import koffi from \"koffi\";\nimport { platform } from \"node:os\";\nimport { join } from \"node:path\";\n\n// -----------------------------------------------------------------------------\n// Cross-platform library loading\n// -----------------------------------------------------------------------------\n\n/**\n * Get platform-specific library search paths from environment variables\n */\nfunction getLibrarySearchPaths(): string[] {\n const os = platform();\n const paths: string[] = [];\n\n switch (os) {\n case \"linux\":\n // Linux: LD_LIBRARY_PATH\n if (process.env.LD_LIBRARY_PATH) {\n paths.push(...process.env.LD_LIBRARY_PATH.split(\":\"));\n }\n break;\n case \"darwin\":\n // macOS: DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH\n if (process.env.DYLD_LIBRARY_PATH) {\n paths.push(...process.env.DYLD_LIBRARY_PATH.split(\":\"));\n }\n if (process.env.DYLD_FALLBACK_LIBRARY_PATH) {\n paths.push(\n ...process.env.DYLD_FALLBACK_LIBRARY_PATH.split(\":\"),\n );\n }\n break;\n case \"win32\":\n // Windows: PATH (libraries are typically in PATH)\n if (process.env.PATH) {\n paths.push(...process.env.PATH.split(\";\"));\n }\n break;\n }\n\n return paths;\n}\n\n/**\n * Get the appropriate library filename for the current platform\n */\nexport function getLibraryFilename(baseName: string): string {\n const os = platform();\n switch (os) {\n case \"darwin\":\n return `lib${baseName}.dylib`;\n case \"linux\":\n return `lib${baseName}.so`;\n case \"win32\":\n return `${baseName}.dll`;\n default:\n throw new Error(`Unsupported platform: ${os}`);\n }\n}\n\n/**\n * Load a library with cross-platform support and customizable search paths\n * @param baseName Base name of the library (e.g., \"cartesi\", \"cartesi_jsonrpc\")\n * @param searchPaths Array of directories to search for the library\n * @returns Loaded library object\n */\nexport function loadLibrary(baseName: string, searchPaths: string[] = []): any {\n const filename = getLibraryFilename(baseName);\n\n // Get paths from environment variables\n const envPaths = getLibrarySearchPaths();\n\n // Default search paths based on platform\n const defaultPaths = [\n // System library paths\n \"/usr/lib\",\n \"/usr/local/lib\",\n \"/opt/homebrew/lib\", // macOS Homebrew\n \"/opt/local/lib\", // macOS MacPorts\n // Current directory\n \".\",\n // Relative to current working directory\n join(process.cwd(), \"lib\"),\n join(process.cwd(), \"build\"),\n ];\n\n // Priority order: custom search paths -> environment paths -> default paths\n const allPaths = [...searchPaths, ...envPaths, ...defaultPaths];\n\n // Try to load from each path\n for (const path of allPaths) {\n try {\n const fullPath = join(path, filename);\n return koffi.load(fullPath);\n } catch (_error) {}\n }\n\n // If we get here, none of the paths worked\n throw new Error(\n `Failed to load library '${filename}'. Tried paths: ${allPaths.join(\", \")}`,\n );\n}\n","import { NodeCartesiMachine } from \"./node/cartesi-machine\";\nimport type {\n AccessLog,\n AccessLogType,\n MachineConfig,\n MachineRuntimeConfig,\n MemoryRangeDescription,\n Proof,\n} from \"./types\";\n\n// -----------------------------------------------------------------------------\n// Constants and enums\n// -----------------------------------------------------------------------------\n\n/**\n * The maximum value for mcycle\n */\nexport const MAX_MCYCLE = 0xffffffffffffffffffn;\n\n/// Constants\nexport enum Constant {\n HashSize = 32,\n TreeLog2WordSize = 5,\n TreeLog2PageSize = 12,\n TreeLog2RootSize = 64,\n}\n\n/// Physical memory addresses\nexport const PmaConstant = {\n CmioRxBufferStart: 0x60000000n,\n CmioRxBufferLog2Size: 21,\n CmioTxBufferStart: 0x60800000n,\n CmioTxBufferLog2Size: 21,\n RamStart: 0x80000000n,\n} as const;\n\n/// Error codes returned from the C API\nexport enum ErrorCode {\n Ok = 0,\n InvalidArgument = -1,\n DomainError = -2,\n LengthError = -3,\n OutOfRange = -4,\n LogicError = -5,\n RuntimeError = -6,\n RangeError = -7,\n OverflowError = -8,\n UnderflowError = -9,\n RegexError = -10,\n SystemError = -11,\n BadTypeid = -12,\n BadCast = -13,\n BadAnyCast = -14,\n BadOptionalAccess = -15,\n BadWeakPtr = -16,\n BadFunctionCall = -17,\n BadAlloc = -18,\n BadArrayNewLength = -19,\n BadException = -20,\n BadVariantAccess = -21,\n Exception = -22,\n Unknown = -23,\n}\n\n/**\n * Custom error class for Cartesi Machine operations\n * Contains both the error code and a human-readable description\n */\nexport class MachineError extends Error {\n public readonly code: ErrorCode;\n public readonly description: string;\n\n constructor(code: ErrorCode, description: string) {\n const message = `Cartesi Machine Error: ${description} (code: ${code})`;\n\n super(message);\n\n this.name = \"MachineError\";\n this.code = code;\n this.description = description;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, MachineError);\n }\n }\n\n /**\n * Creates a MachineError from an error code, automatically fetching the description\n */\n static fromCode(code: ErrorCode): MachineError {\n const description = NodeCartesiMachine.getLastError();\n return new MachineError(code, description);\n }\n}\n\n/// Reasons for the machine to break from call to cm_run\nexport enum BreakReason {\n Failed,\n Halted,\n YieldedManually,\n YieldedAutomatically,\n YieldedSoftly,\n ReachedTargetMcycle,\n}\n\n/// Reasons for the machine to break from call to cm_run_uarch\nexport enum UarchBreakReason {\n ReachedTargetCycle,\n UarchHalted,\n Failed,\n}\n\n/// Yield device commands\nexport enum CmioYieldCommand {\n Automatic,\n Manual,\n}\n\n/// Yield reasons\nexport enum CmioYieldReason {\n AutomaticProgress = 1, ///< Progress is available\n AutomaticTxOutput = 2, ///< Output is available in tx buffer\n AutomaticTxReport = 4, ///< Report is available in tx buffer\n ManualRxAccepted = 1, ///< Input in rx buffer was accepted\n ManualRxRejected = 2, ///< Input in rx buffer was rejected\n ManualTxException = 4, ///< Exception happened\n AdvanceState = 0, ///< Input in rx buffer is an advance state\n InspectState = 1, ///< Input in rx buffer is an inspect state\n}\n\n/// Machine x, f, and control and status registers\nexport enum Reg {\n // Processor x registers\n X0,\n X1,\n X2,\n X3,\n X4,\n X5,\n X6,\n X7,\n X8,\n X9,\n X10,\n X11,\n X12,\n X13,\n X14,\n X15,\n X16,\n X17,\n X18,\n X19,\n X20,\n X21,\n X22,\n X23,\n X24,\n X25,\n X26,\n X27,\n X28,\n X29,\n X30,\n X31,\n // Processor f registers\n F0,\n F1,\n F2,\n F3,\n F4,\n F5,\n F6,\n F7,\n F8,\n F9,\n F10,\n F11,\n F12,\n F13,\n F14,\n F15,\n F16,\n F17,\n F18,\n F19,\n F20,\n F21,\n F22,\n F23,\n F24,\n F25,\n F26,\n F27,\n F28,\n F29,\n F30,\n F31,\n // Processor CSRs\n Pc,\n Fcsr,\n Mvendorid,\n Marchid,\n Mimpid,\n Mcycle,\n Icycleinstret,\n Mstatus,\n Mtvec,\n Mscratch,\n Mepc,\n Mcause,\n Mtval,\n Misa,\n Mie,\n Mip,\n Medeleg,\n Mideleg,\n Mcounteren,\n Menvcfg,\n Stvec,\n Sscratch,\n Sepc,\n Scause,\n Stval,\n Satp,\n Scounteren,\n Senvcfg,\n Ilrsc,\n Iprv,\n IflagsX,\n IflagsY,\n IflagsH,\n Iunrep,\n // Device registers\n ClintMtimecmp,\n PlicGirqpend,\n PlicGirqsrvd,\n HtifToHost,\n HtifFromHost,\n HtifIhalt,\n HtifIconsole,\n HtifIyield,\n // Microarchitecture registers\n UarchX0,\n UarchX1,\n UarchX2,\n UarchX3,\n UarchX4,\n UarchX5,\n UarchX6,\n UarchX7,\n UarchX8,\n UarchX9,\n UarchX10,\n UarchX11,\n UarchX12,\n UarchX13,\n UarchX14,\n UarchX15,\n UarchX16,\n UarchX17,\n UarchX18,\n UarchX19,\n UarchX20,\n UarchX21,\n UarchX22,\n UarchX23,\n UarchX24,\n UarchX25,\n UarchX26,\n UarchX27,\n UarchX28,\n UarchX29,\n UarchX30,\n UarchX31,\n UarchPc,\n UarchCycle,\n UarchHaltFlag,\n // Views of registers\n HtifToHostDev,\n HtifToHostCmd,\n HtifToHostReason,\n HtifToHostData,\n HtifFromHostDev,\n HtifFromHostCmd,\n HtifFromHostReason,\n HtifFromHostData,\n // Enumeration helpers\n Unknown_,\n First_,\n Last_,\n}\n\nexport interface CartesiMachine {\n isEmpty(): boolean;\n create(\n config: MachineConfig,\n runtimeConfig?: MachineRuntimeConfig,\n ): CartesiMachine;\n load(dir: string, runtimeConfig?: MachineRuntimeConfig): CartesiMachine;\n cloneEmpty(): CartesiMachine;\n store(dir: string): CartesiMachine;\n destroy(): void;\n getDefaultConfig(): MachineConfig;\n setRuntimeConfig(runtimeConfig: MachineRuntimeConfig): void;\n getRuntimeConfig(): MachineRuntimeConfig;\n replaceMemoryRange(\n start: bigint,\n length: bigint,\n shared: boolean,\n imageFilename?: string,\n ): void;\n getInitialConfig(): MachineConfig;\n getMemoryRanges(): MemoryRangeDescription[];\n getRegAddress(reg: Reg): bigint;\n getRootHash(): Buffer;\n getProof(address: bigint, log2Size: number): Proof;\n readWord(address: bigint): bigint;\n readReg(reg: Reg): bigint;\n writeReg(reg: Reg, value: bigint): void;\n readMemory(address: bigint, length: bigint): Buffer;\n writeMemory(address: bigint, data: Buffer): void;\n readVirtualMemory(address: bigint, length: bigint): Buffer;\n writeVirtualMemory(address: bigint, data: Buffer): void;\n translateVirtualAddress(vaddr: bigint): bigint;\n run(mcycleEnd?: bigint): BreakReason;\n runUarch(uarchCycleEnd: bigint): UarchBreakReason;\n resetUarch(): void;\n receiveCmioRequest(): {\n cmd: CmioYieldCommand;\n reason: CmioYieldReason;\n data: Buffer;\n };\n sendCmioResponse(reason: CmioYieldReason, data: Buffer): void;\n logStep(mcycleCount: bigint, logFilename: string): BreakReason;\n logStepUarch(logType: AccessLogType): AccessLog;\n logResetUarch(logType: AccessLogType): AccessLog;\n logSendCmioResponse(\n reason: CmioYieldReason,\n data: Buffer,\n logType: AccessLogType,\n ): string;\n verifyStep(\n rootHashBefore: Buffer,\n logFilename: string,\n mcycleCount: bigint,\n rootHashAfter: Buffer,\n ): BreakReason;\n verifyStepUarch(\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n ): void;\n verifyResetUarch(\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n ): void;\n verifyMerkleTree(): boolean;\n verifyDirtyPageMaps(): boolean;\n}\n\nexport function empty(): CartesiMachine {\n return NodeCartesiMachine.new();\n}\n\nexport function create(\n config: MachineConfig,\n runtimeConfig?: MachineRuntimeConfig,\n): CartesiMachine {\n return NodeCartesiMachine.createNew(config, runtimeConfig);\n}\n\nexport function load(\n dir: string,\n runtimeConfig?: MachineRuntimeConfig,\n): CartesiMachine {\n return NodeCartesiMachine.loadNew(dir, runtimeConfig);\n}\n\nexport function getLastError(): string {\n return NodeCartesiMachine.getLastError();\n}\n\nexport function getDefaultConfig(): MachineConfig {\n return NodeCartesiMachine.getDefaultConfig();\n}\n\nexport function getRegAddress(reg: Reg): bigint {\n return NodeCartesiMachine.getRegAddress(reg);\n}\n\nexport function verifyStep(\n rootHashBefore: Buffer,\n logFilename: string,\n mcycleCount: bigint,\n rootHashAfter: Buffer,\n): BreakReason {\n return NodeCartesiMachine.verifyStep(\n rootHashBefore,\n logFilename,\n mcycleCount,\n rootHashAfter,\n );\n}\n\nexport function verifyStepUarch(\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n) {\n NodeCartesiMachine.verifyStepUarch(rootHashBefore, log, rootHashAfter);\n}\n\nexport function verifyResetUarch(\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n): void {\n NodeCartesiMachine.verifyResetUarch(rootHashBefore, log, rootHashAfter);\n}\n\nexport function verifySendCmioResponse(\n reason: CmioYieldReason,\n data: Buffer,\n rootHashBefore: Buffer,\n log: AccessLog,\n rootHashAfter: Buffer,\n) {\n NodeCartesiMachine.verifySendCmioResponse(\n reason,\n data,\n rootHashBefore,\n log,\n rootHashAfter,\n );\n}\n","import { ErrorCode, MachineError } from \"../cartesi-machine\";\nimport type { CleanupCall } from \"../remote-cartesi-machine\";\nimport type { MachineConfig, MachineRuntimeConfig } from \"../types\";\nimport { NodeCartesiMachine } from \"./cartesi-machine\";\nimport { loadLibrary } from \"./lib-loader\";\n\n// Load the Cartesi Machine JSON-RPC library\nconst lib = loadLibrary(\"cartesi_jsonrpc\");\nconst libc = loadLibrary(\"c\");\n\nconst cm_jsonrpc_spawn_server = lib.func(\n \"int cm_jsonrpc_spawn_server(const char *address, int64_t spawn_timeout_ms, _Out_ cm_machine **new_m, _Out_ const char **bound_address, _Out_ uint32_t *pid)\",\n);\nconst cm_jsonrpc_connect_server = lib.func(\n \"int cm_jsonrpc_connect_server(const char *address, int64_t connect_timeout_ms, _Out_ cm_machine **new_m)\",\n);\nconst cm_jsonrpc_fork_server = lib.func(\n \"int cm_jsonrpc_fork_server(const cm_machine *m, _Out_ cm_machine **forked_m, _Out_ const char **address, _Out_ uint32_t *pid)\",\n);\nconst cm_jsonrpc_shutdown_server = lib.func(\n \"int cm_jsonrpc_shutdown_server(cm_machine *m)\",\n);\nconst cm_jsonrpc_rebind_server = lib.func(\n \"int cm_jsonrpc_rebind_server(cm_machine *m, const char *address, _Out_ const char **address_bound)\",\n);\nconst cm_jsonrpc_get_server_version = lib.func(\n \"int cm_jsonrpc_get_server_version(const cm_machine *m, _Out_ const char **version)\",\n);\nconst cm_jsonrpc_emancipate_server = lib.func(\n \"int cm_jsonrpc_emancipate_server(cm_machine *m)\",\n);\nconst cm_jsonrpc_set_timeout = lib.func(\n \"int cm_jsonrpc_set_timeout(cm_machine *m, int64_t ms)\",\n);\nconst cm_jsonrpc_get_timeout = lib.func(\n \"int cm_jsonrpc_get_timeout(cm_machine *m, _Out_ int64_t *ms)\",\n);\nconst cm_jsonrpc_set_cleanup_call = lib.func(\n \"int cm_jsonrpc_set_cleanup_call(cm_machine *m, int call)\",\n);\nconst cm_jsonrpc_get_cleanup_call = lib.func(\n \"int cm_jsonrpc_get_cleanup_call(cm_machine *m, _Out_ int *call)\",\n);\nconst cm_jsonrpc_get_server_address = lib.func(\n \"int cm_jsonrpc_get_server_address(cm_machine *m, _Out_ const char **address)\",\n);\nconst cm_jsonrpc_delay_next_request = lib.func(\n \"int cm_jsonrpc_delay_next_request(cm_machine *m, uint64_t ms)\",\n);\n\nconst fcntl = libc.func(\"int fcntl(int fd, int cmd, int arg)\");\n\nconst F_GETFD = 1; // Get file descriptor flags\nconst F_SETFD = 2; // Set file descriptor flags\nconst FD_CLOEXEC = 1; // Close-on-exec flag\n\nfunction clearCloexec(fd: number): number {\n // Get current flags\n const flags = fcntl(fd, F_GETFD, 0);\n if (flags === -1) {\n throw new Error(`Failed to get flags for fd ${fd}`);\n }\n\n // Clear the FD_CLOEXEC bit\n const newFlags = flags & ~FD_CLOEXEC;\n\n // Set the new flags\n const result = fcntl(fd, F_SETFD, newFlags);\n if (result === -1) {\n throw new Error(`Failed to set flags for fd ${fd}`);\n }\n\n return flags;\n}\n\nfunction setCloexec(fd: number, value: number): void {\n // Set the flags value\n const result = fcntl(fd, F_SETFD, value);\n if (result === -1) {\n throw new Error(`Failed to set flags for fd ${fd}`);\n }\n}\n\nexport class NodeRemoteCartesiMachine extends NodeCartesiMachine {\n private serverAddress: string | null = null;\n private serverPid: number | null = null;\n\n static spawn(\n address: string = \"127.0.0.1:0\",\n spawnTimeoutMs: number = -1,\n ): NodeRemoteCartesiMachine {\n // Disable close-on-exec for stdout\n const flags = clearCloexec(1);\n try {\n const newMachinePtr: [any] = [null];\n const boundAddressPtr: [string | null] = [null];\n const pidPtr: [number | null] = [null];\n const result = cm_jsonrpc_spawn_server(\n address,\n spawnTimeoutMs,\n newMachinePtr,\n boundAddressPtr,\n pidPtr,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n if (boundAddressPtr[0] === null || pidPtr[0] === null) {\n throw new Error(\n \"Failed to get output parameters from spawn server\",\n );\n }\n const instance = new NodeRemoteCartesiMachine(newMachinePtr[0]);\n instance.serverAddress = boundAddressPtr[0];\n instance.serverPid = pidPtr[0];\n return instance;\n } finally {\n setCloexec(1, flags);\n }\n }\n\n static connect(\n address: string,\n connectTimeoutMs: number = -1,\n ): NodeRemoteCartesiMachine {\n const newMachinePtr: [any] = [null];\n const result = cm_jsonrpc_connect_server(\n address,\n connectTimeoutMs,\n newMachinePtr,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n const instance = new NodeRemoteCartesiMachine(newMachinePtr[0]);\n instance.serverAddress = address;\n return instance;\n }\n\n fork(): NodeRemoteCartesiMachine {\n const forkedMachinePtr: [any] = [null];\n const addressPtr: [string | null] = [null];\n const pidPtr: [number | null] = [null];\n const result = cm_jsonrpc_fork_server(\n this.machine,\n forkedMachinePtr,\n addressPtr,\n pidPtr,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n if (addressPtr[0] === null || pidPtr[0] === null) {\n throw new Error(\"Failed to get output parameters from fork server\");\n }\n const instance = new NodeRemoteCartesiMachine(forkedMachinePtr[0]);\n instance.serverAddress = addressPtr[0];\n instance.serverPid = pidPtr[0];\n return instance;\n }\n\n shutdown(): void {\n const result = cm_jsonrpc_shutdown_server(this.machine);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n rebind(address: string): string {\n const addressBoundPtr: [string | null] = [null];\n const result = cm_jsonrpc_rebind_server(\n this.machine,\n address,\n addressBoundPtr,\n );\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n if (addressBoundPtr[0] === null) {\n throw new Error(\"Failed to get bound address from rebind server\");\n }\n this.serverAddress = addressBoundPtr[0];\n return addressBoundPtr[0];\n }\n\n getServerVersion(): string {\n const versionPtr: [string | null] = [null];\n const result = cm_jsonrpc_get_server_version(this.machine, versionPtr);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n if (versionPtr[0] === null) {\n throw new Error(\"Failed to get server version\");\n }\n return versionPtr[0];\n }\n\n emancipate(): void {\n const result = cm_jsonrpc_emancipate_server(this.machine);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n setTimeout(ms: number): void {\n const result = cm_jsonrpc_set_timeout(this.machine, ms);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n getTimeout(): number {\n const msPtr: [number | null] = [null];\n const result = cm_jsonrpc_get_timeout(this.machine, msPtr);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n if (msPtr[0] === null) {\n throw new Error(\"Failed to get timeout\");\n }\n return msPtr[0];\n }\n\n setCleanupCall(call: CleanupCall): NodeRemoteCartesiMachine {\n const result = cm_jsonrpc_set_cleanup_call(this.machine, call);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n return this;\n }\n\n getCleanupCall(): CleanupCall {\n const callPtr: [number | null] = [null];\n const result = cm_jsonrpc_get_cleanup_call(this.machine, callPtr);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n if (callPtr[0] === null) {\n throw new Error(\"Failed to get cleanup call\");\n }\n return callPtr[0];\n }\n\n getServerAddress(): string {\n const addressPtr: [string | null] = [null];\n const result = cm_jsonrpc_get_server_address(this.machine, addressPtr);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n if (addressPtr[0] === null) {\n throw new Error(\"Failed to get server address\");\n }\n return addressPtr[0];\n }\n\n delayNextRequest(ms: number): void {\n const result = cm_jsonrpc_delay_next_request(this.machine, ms);\n if (result !== ErrorCode.Ok) {\n throw MachineError.fromCode(result);\n }\n }\n\n getBoundAddress(): string | null {\n return this.serverAddress;\n }\n\n getServerPid(): number | null {\n return this.serverPid;\n }\n\n load(\n dir: string,\n runtimeConfig?: MachineRuntimeConfig,\n ): NodeRemoteCartesiMachine {\n super.load(dir, runtimeConfig);\n return this;\n }\n\n cloneEmpty(): NodeRemoteCartesiMachine {\n super.cloneEmpty();\n return this;\n }\n\n create(\n config: MachineConfig,\n runtimeConfig?: MachineRuntimeConfig,\n ): NodeRemoteCartesiMachine {\n super.create(config, runtimeConfig);\n return this;\n }\n\n store(dir: string): NodeRemoteCartesiMachine {\n super.store(dir);\n return this;\n }\n}\n","import type { CartesiMachine } from \"./cartesi-machine\";\nimport { NodeRemoteCartesiMachine } from \"./node/remote-cartesi-machine\";\nimport type { MachineConfig, MachineRuntimeConfig } from \"./types\";\n\n// -----------------------------------------------------------------------------\n// Type definitions\n// -----------------------------------------------------------------------------\n\nexport enum CleanupCall {\n Nothing = 0, // CM_JSONRPC_NOTHING\n Destroy = 1, // CM_JSONRPC_DESTROY\n Shutdown = 2, // CM_JSONRPC_SHUTDOWN\n}\n\n// -----------------------------------------------------------------------------\n// High-level TypeScript wrapper classes\n// -----------------------------------------------------------------------------\n\nexport interface RemoteCartesiMachine extends CartesiMachine {\n getServerAddress(): string;\n getServerPid(): number | null;\n shutdown(): void;\n rebind(address: string): string;\n emancipate(): void;\n setTimeout(ms: number): void;\n getTimeout(): number;\n setCleanupCall(call: CleanupCall): RemoteCartesiMachine;\n getCleanupCall(): CleanupCall;\n getServerVersion(): string;\n delayNextRequest(ms: number): void;\n getBoundAddress(): string | null;\n fork(): RemoteCartesiMachine;\n load(\n dir: string,\n runtimeConfig?: MachineRuntimeConfig,\n ): RemoteCartesiMachine;\n cloneEmpty(): RemoteCartesiMachine;\n create(\n config: MachineConfig,\n runtimeConfig?: MachineRuntimeConfig,\n ): RemoteCartesiMachine;\n store(dir: string): RemoteCartesiMachine;\n}\n\n// -----------------------------------------------------------------------------\n// Utility functions\n// -----------------------------------------------------------------------------\n\nexport function spawn(\n address: string = \"127.0.0.1:0\",\n timeout: number = -1,\n): RemoteCartesiMachine {\n return NodeRemoteCartesiMachine.spawn(address, timeout);\n}\n\nexport function connect(\n address: string,\n timeout: number = -1,\n): RemoteCartesiMachine {\n return NodeRemoteCartesiMachine.connect(address, timeout);\n}\n","import {\n BreakReason,\n CmioYieldReason,\n type CartesiMachine,\n} from \"./cartesi-machine\";\nimport { NodeRemoteCartesiMachine } from \"./node/remote-cartesi-machine\";\nimport { spawn, type RemoteCartesiMachine } from \"./remote-cartesi-machine\";\nimport type { MachineRuntimeConfig } from \"./types\";\n\n/**\n * Custom error class to signal the rollup has entered an invalid state\n */\nexport class RollupsFatalError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"RollupsFatalError\";\n }\n}\n\n/**\n * Custom error class to signal an input was rejected\n */\nexport class RollupsInputRejectedError extends Error {\n constructor() {\n super(\"Input rejected\");\n this.name = \"RollupsInputRejectedError\";\n }\n}\n\n/**\n * Advance requests can yield either an output or a report, indicated by the type field.\n * The data field contains the output or report data.\n */\nexport type AdvanceYield =\n | { type: \"output\"; data: Buffer }\n | { type: \"report\"; data: Buffer }\n | { type: \"progress\"; data: number };\n\nexport type AdvanceReturn = Buffer;\n\nexport type AdvanceResult = {\n outputs: Buffer[];\n reports: Buffer[];\n outputsMerkleRoot: Buffer;\n};\n\nexport interface RollupsMachine {\n advance(input: Buffer): IterableIterator<AdvanceYield, AdvanceReturn>;\n advance(input: Buffer, options: { collect: true }): AdvanceResult;\n inspect(query: Buffer): IterableIterator<Buffer>;\n inspect(query: Buffer, options: { collect: true }): Buffer[];\n shutdown(): void;\n store(dir: string): RollupsMachine;\n}\n\n/**\n * Create a rollups machine from a local machine.\n * @param machine - The local machine.\n * @returns A rollups machine.\n */\nfunction rollupsFromLocal(machine: CartesiMachine): RollupsMachine {\n return new LocalRollupsMachineImpl(machine);\n}\n\n/**\n * Create a rollups machine from a remote machine.\n * @param machine - The remote machine.\n * @returns A rollups machine.\n */\nfunction rollupsFromRemote(\n machine: RemoteCartesiMachine,\n options?: { noRollback?: boolean },\n): RollupsMachine {\n return new RemoteRollupsMachineImpl(machine, options?.noRollback ?? false);\n}\n\nconst DEFAULT_ADDRESS = \"127.0.0.1:0\";\nconst DEFAULT_TIMEOUT = -1;\n\n/**\n * Create a rollups machine from a store directory.\n * @param dir - The directory containing the store.\n * @param runtimeConfig - The runtime configuration.\n * @param address - The address of the remote machine.\n * @param timeout - The timeout for the remote machine.\n * @description This function spawns a new machine, and loads the stored snapshot on it.\n * @returns A rollups machine.\n */\nfunction rollupsFromStore(\n dir: string,\n options?: {\n noRollback?: boolean;\n runtimeConfig?: MachineRuntimeConfig;\n address?: string;\n timeout?: number;\n },\n): RollupsMachine {\n const { runtimeConfig } = options ?? {\n address: DEFAULT_ADDRESS,\n timeout: DEFAULT_TIMEOUT,\n runtimeConfig: undefined,\n };\n const address = options?.address ?? DEFAULT_ADDRESS;\n const timeout = options?.timeout ?? DEFAULT_TIMEOUT;\n const machine = spawn(address, timeout).load(dir, runtimeConfig);\n return rollupsFromRemote(machine, options);\n}\n\n/**\n * Create a rollups machine from a remote machine.\n * @param machine - The remote machine.\n * @returns A rollups machine.\n */\nexport function rollups(\n machine: RemoteCartesiMachine,\n options?: { noRollback: boolean },\n): RollupsMachine;\n\n/**\n * Create a rollups machine from a local machine.\n * @param machine - The local machine.\n * @returns A rollups machine.\n */\nexport function rollups(machine: CartesiMachine): RollupsMachine;\n\n/**\n * Create a rollups machine from a store directory.\n * @param dir - The directory containing the store.\n * @param runtimeConfig - The runtime configuration.\n * @param address - The address of the remote machine.\n * @param timeout - The timeout for the remote machine.\n * @description This function spawns a new machine, and loads the stored snapshot on it.\n * @returns A rollups machine.\n */\nexport function rollups(\n dir: string,\n options?: {\n noRollback?: boolean;\n runtimeConfig?: MachineRuntimeConfig;\n address?: string;\n timeout?: number;\n },\n): RollupsMachine;\n\nexport function rollups(\n arg1: RemoteCartesiMachine | CartesiMachine | string,\n options?: {\n noRollback?: boolean;\n runtimeConfig?: MachineRuntimeConfig;\n address?: string;\n timeout?: number;\n },\n): RollupsMachine {\n options = options ?? {\n noRollback: false,\n address: DEFAULT_ADDRESS,\n timeout: DEFAULT_TIMEOUT,\n };\n\n if (typeof arg1 === \"string\") {\n return rollupsFromStore(arg1, options);\n } else if (arg1 instanceof NodeRemoteCartesiMachine) {\n return rollupsFromRemote(arg1, options);\n } else {\n return rollupsFromLocal(arg1);\n }\n}\n\nabstract class RollupsMachineImpl implements RollupsMachine {\n abstract shutdown(): void;\n abstract store(dir: string): RollupsMachine;\n\n abstract startTransaction(): CartesiMachine;\n abstract commitTransaction(machine: CartesiMachine): void;\n abstract rollbackTransaction(machine: CartesiMachine): void;\n\n advance(input: Buffer, options?: { collect: true }): any {\n const generator = function* (\n this: RollupsMachineImpl,\n ): IterableIterator<AdvanceYield, AdvanceReturn> {\n // start a machine \"transaction\"\n const machine = this.startTransaction();\n\n // write input\n machine.sendCmioResponse(CmioYieldReason.AdvanceState, input);\n\n while (true) {\n // run machine until it yields or halts\n const breakReason = machine.run();\n\n switch (breakReason) {\n case BreakReason.YieldedManually: {\n const { reason, data } = machine.receiveCmioRequest();\n switch (reason) {\n case CmioYieldReason.ManualRxAccepted: {\n // input was accepted\n // shutdown the backup fork if it exists\n this.commitTransaction(machine);\n return data;\n }\n case CmioYieldReason.ManualRxRejected: {\n // input was rejected\n this.rollbackTransaction(machine);\n throw new RollupsInputRejectedError();\n }\n case CmioYieldReason.ManualTxException: {\n // exception\n this.rollbackTransaction(machine);\n\n const description = data.toString(\"utf-8\"); // XXX: is this correct?\n throw new RollupsFatalError(description);\n }\n default: {\n this.rollbackTransaction(machine);\n throw new RollupsFatalError(\n `Unexpected yield reason: ${reason}`,\n );\n }\n }\n }\n case BreakReason.YieldedAutomatically: {\n const { reason, data } = machine.receiveCmioRequest();\n switch (reason) {\n case CmioYieldReason.AutomaticProgress: {\n try {\n const progress = data.readUInt32LE();\n yield {\n type: \"progress\",\n data: progress,\n };\n } catch {\n // just ignore the progress in case cannot read it\n }\n break;\n }\n case CmioYieldReason.AutomaticTxOutput: {\n yield { type: \"output\", data };\n break;\n }\n case CmioYieldReason.AutomaticTxReport: {\n yield { type: \"report\", data };\n break;\n }\n }\n continue; // run again\n }\n default: {\n this.rollbackTransaction(machine);\n throw new RollupsFatalError(\n `Unexpected break reason: ${breakReason}`,\n );\n }\n }\n }\n }.bind(this);\n\n if (options?.collect) {\n const outputs: Buffer[] = [];\n const reports: Buffer[] = [];\n const rollups = generator();\n while (true) {\n const event = rollups.next();\n if (event.done) {\n return { outputs, reports, outputsMerkleRoot: event.value };\n }\n switch (event.value.type) {\n case \"output\":\n outputs.push(event.value.data);\n break;\n case \"report\":\n reports.push(event.value.data);\n break;\n case \"progress\":\n break;\n }\n }\n }\n\n return generator();\n }\n\n inspect(query: Buffer, options?: { collect: true }): any {\n const generator = function* (\n this: RollupsMachineImpl,\n ): IterableIterator<Buffer> {\n const machine = this.startTransaction();\n\n // write query\n machine.sendCmioResponse(CmioYieldReason.InspectState, query);\n\n while (true) {\n // run machine until it yields or halts\n const breakReason = machine.run();\n\n switch (breakReason) {\n case BreakReason.YieldedManually: {\n const { reason, data } = machine.receiveCmioRequest();\n switch (reason) {\n case CmioYieldReason.ManualRxAccepted: {\n // input was accepted\n this.rollbackTransaction(machine);\n return;\n }\n case CmioYieldReason.ManualRxRejected: {\n // input was rejected\n this.rollbackTransaction(machine);\n throw new RollupsInputRejectedError();\n }\n case CmioYieldReason.ManualTxException: {\n // exception\n this.rollbackTransaction(machine);\n const description = data.toString(\"utf-8\"); // XXX: is this correct?\n throw new RollupsFatalError(description);\n }\n default: {\n this.rollbackTransaction(machine);\n throw new RollupsFatalError(\n `Unexpected yield reason: ${reason}`,\n );\n }\n }\n }\n case BreakReason.YieldedAutomatically: {\n const { reason, data } = machine.receiveCmioRequest();\n switch (reason) {\n case CmioYieldReason.AutomaticProgress: {\n // ignore progress\n break;\n }\n case CmioYieldReason.AutomaticTxOutput: {\n // ignore output\n break;\n }\n case CmioYieldReason.AutomaticTxReport: {\n // yield report\n yield data;\n break;\n }\n }\n continue; // run again\n }\n default: {\n this.rollbackTransaction(machine);\n throw new RollupsFatalError(\n `Unexpected break reason: ${breakReason}`,\n );\n }\n }\n }\n }.bind(this);\n\n if (options?.collect) {\n return [...generator()];\n }\n\n return generator();\n }\n}\n\nclass RemoteRollupsMachineImpl extends RollupsMachineImpl {\n private machine: RemoteCartesiMachine;\n private noRollback: boolean;\n\n constructor(machine: RemoteCartesiMachine, noRollback: boolean = false) {\n super();\n this.machine = machine;\n this.noRollback = noRollback;\n }\n\n startTransaction(): CartesiMachine {\n if (this.noRollback) {\n // do not fork\n return this.machine;\n } else {\n return this.machine.fork();\n }\n }\n\n commitTransaction(machine: CartesiMachine): void {\n if (this.noRollback) {\n // do nothing\n } else {\n // shut down current machine\n this.machine.shutdown();\n\n // replace by fork\n this.machine = machine as RemoteCartesiMachine;\n }\n }\n\n rollbackTransaction(machine: CartesiMachine): void {\n if (this.noRollback) {\n // do nothing\n } else {\n // shutdown fork\n (machine as RemoteCartesiMachine).shutdown();\n }\n }\n\n shutdown(): void {\n this.machine.shutdown();\n }\n\n store(dir: string): RollupsMachine {\n this.machine.store(dir);\n return this;\n }\n}\n\nclass LocalRollupsMachineImpl extends RollupsMachineImpl {\n private machine: CartesiMachine;\n\n constructor(machine: CartesiMachine) {\n super();\n this.machine = machine;\n }\n\n startTransaction(): CartesiMachine {\n return this.machine;\n }\n\n commitTransaction(machine: CartesiMachine): void {\n this.machine = machine;\n }\n\n rollbackTransaction(machine: CartesiMachine): void {\n this.machine = machine;\n }\n\n shutd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YAAYhB,EAAyB,CACjC,MAAM,EACN,KAAK,QAAUA,CACnB,CAEA,kBAAmC,CAC/B,OAAO,KAAK,OAChB,CAEA,kBAAkBA,EAA+B,CAC7C,KAAK,QAAUA,CACnB,CAEA,oBAAoBA,EAA+B,CAC/C,KAAK,QAAUA,CACnB,CAEA,UAAiB,CAEjB,CAEA,MAAMQ,EAA6B,CAC/B,YAAK,QAAQ,MAAMA,CAAG,EACf,IACX,CACJ","names":["index_exports","__export","BreakReason","CleanupCall","CmioYieldCommand","CmioYieldReason","Constant","ErrorCode","MAX_MCYCLE","MachineError","PmaConstant","Reg","RollupsFatalError","RollupsInputRejectedError","UarchBreakReason","connect","create","empty","getDefaultConfig","getLastError","getRegAddress","load","rollups","spawn","verifyResetUarch","verifySendCmioResponse","verifyStep","verifyStepUarch","__toCommonJS","import_koffi","import_koffi","import_node_os","import_node_path","getLibrarySearchPaths","os","paths","getLibraryFilename","baseName","loadLibrary","searchPaths","filename","envPaths","defaultPaths","allPaths","path","fullPath","koffi","lib","loadLibrary","koffi","cm_get_last_error_message","cm_get_default_config","cm_get_reg_address","cm_new","cm_clone_empty","cm_is_empty","cm_delete","cm_create","cm_create_new","cm_load","cm_load_new","cm_store","cm_destroy","cm_set_runtime_config","cm_get_runtime_config","cm_replace_memory_range","cm_get_initial_config","cm_get_memory_ranges","cm_get_root_hash","cm_get_proof","cm_read_word","cm_read_reg","cm_write_reg","cm_read_memory","cm_write_memory","cm_read_virtual_memory","cm_write_virtual_memory","cm_translate_virtual_address","cm_run","cm_run_uarch","cm_reset_uarch","cm_receive_cmio_request","cm_send_cmio_response","cm_log_step","cm_log_step_uarch","cm_log_reset_uarch","cm_log_send_cmio_response","cm_verify_step","cm_verify_step_uarch","cm_verify_reset_uarch","cm_verify_send_cmio_response","cm_verify_merkle_tree","cm_verify_dirty_page_maps","machineFinalizer","machineHandle","cm_delete","NodeCartesiMachine","_NodeCartesiMachine","machine","result","cm_new","MachineError","cm_clone_empty","config","runtimeConfig","cm_create_new","dir","cm_load_new","cm_get_last_error_message","cm_get_default_config","reg","address","cm_get_reg_address","empty","cm_is_empty","cm_create","cm_load","cm_store","cm_destroy","cm_set_runtime_config","cm_get_runtime_config","start","length","shared","imageFilename","cm_replace_memory_range","cm_get_initial_config","ranges","cm_get_memory_ranges","hash","cm_get_root_hash","log2Size","proof","cm_get_proof","value","cm_read_word","cm_read_reg","cm_write_reg","data","cm_read_memory","cm_write_memory","cm_read_virtual_memory","cm_write_virtual_memory","vaddr","paddr","cm_translate_virtual_address","mcycleEnd","MAX_MCYCLE","breakReason","cm_run","uarchCycleEnd","cm_run_uarch","cm_reset_uarch","cmd","reason","cm_receive_cmio_request","cm_send_cmio_response","mcycleCount","logFilename","cm_log_step","logType","log","type","cm_log_step_uarch","cm_log_reset_uarch","cm_log_send_cmio_response","rootHashBefore","rootHashAfter","cm_verify_step","cm_verify_step_uarch","cm_verify_reset_uarch","cm_verify_send_cmio_response","error","cm_verify_merkle_tree","cm_verify_dirty_page_maps","MAX_MCYCLE","Constant","PmaConstant","ErrorCode","MachineError","_MachineError","code","description","message","NodeCartesiMachine","BreakReason","UarchBreakReason","CmioYieldCommand","CmioYieldReason","Reg","empty","create","config","runtimeConfig","load","dir","getLastError","getDefaultConfig","getRegAddress","reg","verifyStep","rootHashBefore","logFilename","mcycleCount","rootHashAfter","verifyStepUarch","log","verifyResetUarch","verifySendCmioResponse","reason","data","lib","loadLibrary","libc","cm_jsonrpc_spawn_server","cm_jsonrpc_connect_server","cm_jsonrpc_fork_server","cm_jsonrpc_shutdown_server","cm_jsonrpc_rebind_server","cm_jsonrpc_get_server_version","cm_jsonrpc_emancipate_server","cm_jsonrpc_set_timeout","cm_jsonrpc_get_timeout","cm_jsonrpc_set_cleanup_call","cm_jsonrpc_get_cleanup_call","cm_jsonrpc_get_server_address","cm_jsonrpc_delay_next_request","fcntl","F_GETFD","F_SETFD","FD_CLOEXEC","clearCloexec","fd","flags","newFlags","setCloexec","value","NodeRemoteCartesiMachine","_NodeRemoteCartesiMachine","NodeCartesiMachine","address","spawnTimeoutMs","newMachinePtr","boundAddressPtr","pidPtr","result","MachineError","instance","connectTimeoutMs","forkedMachinePtr","addressPtr","addressBoundPtr","versionPtr","ms","msPtr","call","callPtr","dir","runtimeConfig","config","CleanupCall","spawn","address","timeout","NodeRemoteCartesiMachine","connect","RollupsFatalError","message","RollupsInputRejectedError","rollupsFromLocal","machine","LocalRollupsMachineImpl","rollupsFromRemote","options","RemoteRollupsMachineImpl","DEFAULT_ADDRESS","DEFAULT_TIMEOUT","rollupsFromStore","dir","runtimeConfig","address","timeout","spawn","rollups","arg1","NodeRemoteCartesiMachine","RollupsMachineImpl","input","generator","breakReason","reason","data","description","outputs","reports","event","query","noRollback"]}
|