@deroll/cm 0.2.0-alpha.0 → 0.2.0-alpha.2

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.
@@ -1 +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 shutdown(): void {\n // no-op\n }\n\n store(dir: string): RollupsMachine {\n this.machine.store(dir);\n return this;\n }\n}\n"],"mappings":"gkBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,iBAAAE,EAAA,gBAAAC,EAAA,qBAAAC,EAAA,oBAAAC,EAAA,aAAAC,EAAA,cAAAC,EAAA,eAAAC,EAAA,iBAAAC,EAAA,gBAAAC,GAAA,QAAAC,EAAA,sBAAAC,EAAA,8BAAAC,EAAA,qBAAAC,EAAA,YAAAC,GAAA,WAAAC,GAAA,UAAAC,GAAA,qBAAAC,GAAA,iBAAAC,GAAA,kBAAAC,GAAA,SAAAC,GAAA,YAAAC,GAAA,UAAAC,EAAA,qBAAAC,GAAA,2BAAAC,GAAA,eAAAC,GAAA,oBAAAC,KAAA,eAAAC,GAAA5B,ICAA,IAAA6B,EAAkB,sBCAlB,IAAAC,EAAkB,sBAClBC,EAAyB,cACzBC,EAAqB,gBASrB,SAASC,IAAkC,CACvC,IAAMC,KAAK,YAA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ER,CACJ,CACJ,EAAE,KAAK,IAAI,EAEX,OAAIhB,GAAS,QACF,CAAC,GAAGe,EAAU,CAAC,EAGnBA,EAAU,CACrB,CACJ,EAEMd,EAAN,cAAuCY,CAAmB,CAItD,YAAYhB,EAA+B2B,EAAsB,GAAO,CACpE,MAAM,EACN,KAAK,QAAU3B,EACf,KAAK,WAAa2B,CACtB,CAEA,kBAAmC,CAC/B,OAAI,KAAK,WAEE,KAAK,QAEL,KAAK,QAAQ,KAAK,CAEjC,CAEA,kBAAkB3B,EAA+B,CACzC,KAAK,aAIL,KAAK,QAAQ,SAAS,EAGtB,KAAK,QAAUA,EAEvB,CAEA,oBAAoBA,EAA+B,CAC3C,KAAK,YAIJA,EAAiC,SAAS,CAEnD,CAEA,UAAiB,CACb,KAAK,QAAQ,SAAS,CAC1B,CAEA,MAAMQ,EAA6B,CAC/B,YAAK,QAAQ,MAAMA,CAAG,EACf,IACX,CACJ,EAEMP,EAAN,cAAsCe,CAAmB,CAGrD,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"]}
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.js\";\nexport * from \"./remote-cartesi-machine.js\";\nexport * from \"./rollups.js\";\nexport * from \"./types.js\";\n","import koffi from \"koffi\";\nimport type {\n BreakReason,\n CartesiMachine,\n CmioYieldCommand,\n CmioYieldReason,\n Reg,\n UarchBreakReason,\n} from \"../cartesi-machine.js\";\nimport {\n Constant,\n ErrorCode,\n MachineError,\n MAX_MCYCLE,\n} from \"../cartesi-machine.js\";\nimport type {\n AccessLog,\n AccessLogType,\n MachineConfig,\n MachineRuntimeConfig,\n MemoryRangeDescription,\n Proof,\n} from \"../types.js\";\nimport { loadLibrary } from \"./lib-loader.js\";\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.js\";\nimport type {\n AccessLog,\n AccessLogType,\n MachineConfig,\n MachineRuntimeConfig,\n MemoryRangeDescription,\n Proof,\n} from \"./types.js\";\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.js\";\nimport type { CleanupCall } from \"../remote-cartesi-machine.js\";\nimport type { MachineConfig, MachineRuntimeConfig } from \"../types.js\";\nimport { NodeCartesiMachine } from \"./cartesi-machine.js\";\nimport { loadLibrary } from \"./lib-loader.js\";\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.js\";\nimport { NodeRemoteCartesiMachine } from \"./node/remote-cartesi-machine.js\";\nimport type { MachineConfig, MachineRuntimeConfig } from \"./types.js\";\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.js\";\nimport { NodeRemoteCartesiMachine } from \"./node/remote-cartesi-machine.js\";\nimport { spawn, type RemoteCartesiMachine } from \"./remote-cartesi-machine.js\";\nimport type { MachineRuntimeConfig } from \"./types.js\";\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 shutdown(): void {\n // no-op\n }\n\n store(dir: string): RollupsMachine {\n this.machine.store(dir);\n return this;\n }\n}\n"],"mappings":"8jBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,iBAAAE,EAAA,gBAAAC,EAAA,qBAAAC,EAAA,oBAAAC,EAAA,aAAAC,EAAA,cAAAC,EAAA,eAAAC,EAAA,iBAAAC,EAAA,gBAAAC,GAAA,QAAAC,EAAA,sBAAAC,EAAA,8BAAAC,EAAA,qBAAAC,EAAA,YAAAC,GAAA,WAAAC,GAAA,UAAAC,GAAA,qBAAAC,GAAA,iBAAAC,GAAA,kBAAAC,GAAA,SAAAC,GAAA,YAAAC,GAAA,UAAAC,EAAA,qBAAAC,GAAA,2BAAAC,GAAA,eAAAC,GAAA,oBAAAC,KAAA,eAAAC,GAAA5B,ICAA,IAAA6B,EAAkB,sBCAlB,IAAAC,EAAkB,sBAClBC,EAAyB,cACzBC,EAAqB,gBASrB,SAASC,IAAkC,CACvC,IAAMC,KAAK,YAAS,EACdC,EAAkB,CAAC,EAEzB,OAAQD,EAAI,CACR,IAAK,QAEG,QAAQ,IAAI,iBACZC,EAAM,KAAK,GAAG,QAAQ,IAAI,gBAAgB,MAAM,GAAG,CAAC,EAExD,MACJ,IAAK,SAEG,QAAQ,IAAI,mBACZA,EAAM,KAAK,GAAG,QAAQ,IAAI,kBAAkB,MAAM,GAAG,CAAC,E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B,OAAI,KAAK,WAEE,KAAK,QAEL,KAAK,QAAQ,KAAK,CAEjC,CAEA,kBAAkB3B,EAA+B,CACzC,KAAK,aAIL,KAAK,QAAQ,SAAS,EAGtB,KAAK,QAAUA,EAEvB,CAEA,oBAAoBA,EAA+B,CAC3C,KAAK,YAIJA,EAAiC,SAAS,CAEnD,CAEA,UAAiB,CACb,KAAK,QAAQ,SAAS,CAC1B,CAEA,MAAMQ,EAA6B,CAC/B,YAAK,QAAQ,MAAMA,CAAG,EACf,IACX,CACJ,EAEMP,EAAN,cAAsCe,CAAmB,CAC7C,QAER,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"]}