From 54d6fb4935673a200b9eed69b7f754d18a7586ce Mon Sep 17 00:00:00 2001 From: Zehui Zheng Date: Tue, 13 Jan 2026 17:48:55 -0800 Subject: [PATCH 1/5] chore: update machine emulator submodule --- machine/emulator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine/emulator b/machine/emulator index ce402f96..83e8d769 160000 --- a/machine/emulator +++ b/machine/emulator @@ -1 +1 @@ -Subproject commit ce402f96d6757c8f4b2f08cba861cd80ab6bf834 +Subproject commit 83e8d7695515f9ca59993f1bd669131f730f560f From e70a777c33e76ddd5fc8d724c46f5fd05726a86e Mon Sep 17 00:00:00 2001 From: Zehui Zheng Date: Mon, 19 Jan 2026 11:41:33 -0800 Subject: [PATCH 2/5] feat: refactor rust-bindings for emulator update --- machine/emulator | 2 +- .../cartesi-machine/src/constants.rs | 18 ++++---- .../cartesi-machine/src/machine.rs | 42 ++++++++++--------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/machine/emulator b/machine/emulator index 83e8d769..ec1487c9 160000 --- a/machine/emulator +++ b/machine/emulator @@ -1 +1 @@ -Subproject commit 83e8d7695515f9ca59993f1bd669131f730f560f +Subproject commit ec1487c9b39eaf5db2ea45c0a8057fa85ace8e2d diff --git a/machine/rust-bindings/cartesi-machine/src/constants.rs b/machine/rust-bindings/cartesi-machine/src/constants.rs index 9e8088af..fef0a375 100644 --- a/machine/rust-bindings/cartesi-machine/src/constants.rs +++ b/machine/rust-bindings/cartesi-machine/src/constants.rs @@ -6,19 +6,19 @@ pub mod machine { use cartesi_machine_sys::*; // pub const CYCLE_MAX: u64 = CM_MCYCLE_MAX as u64; - pub const HASH_SIZE: u32 = CM_HASH_SIZE; - pub const TREE_LOG2_WORD_SIZE: u32 = CM_TREE_LOG2_WORD_SIZE; - pub const TREE_LOG2_PAGE_SIZE: u32 = CM_TREE_LOG2_PAGE_SIZE; - pub const TREE_LOG2_ROOT_SIZE: u32 = CM_TREE_LOG2_ROOT_SIZE; + pub const HASH_SIZE: u32 = CM_HASH_SIZE as u32; + pub const TREE_LOG2_WORD_SIZE: u32 = CM_HASH_TREE_LOG2_WORD_SIZE as u32; + pub const TREE_LOG2_PAGE_SIZE: u32 = CM_HASH_TREE_LOG2_PAGE_SIZE as u32; + pub const TREE_LOG2_ROOT_SIZE: u32 = CM_HASH_TREE_LOG2_ROOT_SIZE as u32; } pub mod pma { use cartesi_machine_sys::*; - pub const RX_START: u64 = CM_PMA_CMIO_RX_BUFFER_START as u64; - pub const RX_LOG2_SIZE: u64 = CM_PMA_CMIO_RX_BUFFER_LOG2_SIZE as u64; - pub const TX_START: u64 = CM_PMA_CMIO_TX_BUFFER_START as u64; - pub const TX_LOG2_SIZE: u64 = CM_PMA_CMIO_TX_BUFFER_LOG2_SIZE as u64; - pub const RAM_START: u64 = CM_PMA_RAM_START as u64; + pub const RX_START: u64 = CM_AR_CMIO_RX_BUFFER_START as u64; + pub const RX_LOG2_SIZE: u64 = CM_AR_CMIO_RX_BUFFER_LOG2_SIZE as u64; + pub const TX_START: u64 = CM_AR_CMIO_TX_BUFFER_START as u64; + pub const TX_LOG2_SIZE: u64 = CM_AR_CMIO_TX_BUFFER_LOG2_SIZE as u64; + pub const RAM_START: u64 = CM_AR_RAM_START as u64; } pub mod break_reason { diff --git a/machine/rust-bindings/cartesi-machine/src/machine.rs b/machine/rust-bindings/cartesi-machine/src/machine.rs index 371ccb07..b718130b 100644 --- a/machine/rust-bindings/cartesi-machine/src/machine.rs +++ b/machine/rust-bindings/cartesi-machine/src/machine.rs @@ -92,12 +92,14 @@ impl Machine { pub fn create(config: &MachineConfig, runtime_config: &RuntimeConfig) -> Result { let config_json = serialize_to_json!(&config); let runtime_config_json = serialize_to_json!(&runtime_config); + let dir_cstr = CString::new("").unwrap(); // in-memory machine let mut machine: *mut cartesi_machine_sys::cm_machine = ptr::null_mut(); let err_code = unsafe { cartesi_machine_sys::cm_create_new( config_json.as_ptr(), runtime_config_json.as_ptr(), + dir_cstr.as_ptr(), &mut machine, ) }; @@ -116,6 +118,7 @@ impl Machine { cartesi_machine_sys::cm_load_new( dir_cstr.as_ptr(), runtime_config_json.as_ptr(), + cartesi_machine_sys::CM_SHARING_CONFIG, &mut machine, ) }; @@ -127,7 +130,13 @@ impl Machine { /// Stores a machine instance to a directory, serializing its entire state. pub fn store(&mut self, dir: &Path) -> Result<()> { let dir_cstr = path_to_cstring(dir); - let err_code = unsafe { cartesi_machine_sys::cm_store(self.machine, dir_cstr.as_ptr()) }; + let err_code = unsafe { + cartesi_machine_sys::cm_store( + self.machine, + dir_cstr.as_ptr(), + cartesi_machine_sys::CM_SHARING_CONFIG, + ) + }; check_err!(err_code)?; Ok(()) @@ -164,25 +173,20 @@ impl Machine { shared: bool, image_path: Option<&Path>, ) -> Result<()> { - let image_cstr = match image_path { - Some(path) => path_to_cstring(path), - None => CString::new("").unwrap(), - }; - - let image_ptr = if image_path.is_some() { - image_cstr.as_ptr() - } else { - ptr::null() - }; + let range_config = serde_json::json!({ + "start": start, + "length": length, + "read_only": false, + "backing_store": { + "data_filename": image_path.map(|p| p.to_string_lossy().to_string()).unwrap_or_default(), + "shared": shared + } + }); + + let range_json = serialize_to_json!(&range_config); let err_code = unsafe { - cartesi_machine_sys::cm_replace_memory_range( - self.machine, - start, - length, - shared, - image_ptr, - ) + cartesi_machine_sys::cm_replace_memory_range(self.machine, range_json.as_ptr()) }; check_err!(err_code)?; @@ -205,7 +209,7 @@ impl Machine { pub fn memory_ranges(&mut self) -> Result { let mut ranges_ptr: *const c_char = ptr::null(); let err_code = - unsafe { cartesi_machine_sys::cm_get_memory_ranges(self.machine, &mut ranges_ptr) }; + unsafe { cartesi_machine_sys::cm_get_address_ranges(self.machine, &mut ranges_ptr) }; check_err!(err_code)?; let ranges = parse_json_from_cstring!(ranges_ptr); From 92fa349226bff416cb84c51f8e58c18fc4a45000 Mon Sep 17 00:00:00 2001 From: Zehui Zheng Date: Mon, 19 Jan 2026 15:22:29 -0800 Subject: [PATCH 3/5] fix: link OpenMP --- .../cartesi-machine-sys/build.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/machine/rust-bindings/cartesi-machine-sys/build.rs b/machine/rust-bindings/cartesi-machine-sys/build.rs index 527c6543..e04c3998 100644 --- a/machine/rust-bindings/cartesi-machine-sys/build.rs +++ b/machine/rust-bindings/cartesi-machine-sys/build.rs @@ -39,6 +39,28 @@ fn main() { } } + // OpenMP linker configuration (cross-platform) + if cfg!(target_os = "macos") { + // macOS: Try Homebrew first, then MacPorts + let homebrew_libomp = PathBuf::from("/opt/homebrew/opt/libomp"); + if homebrew_libomp.exists() { + println!("cargo:rustc-link-search={}/lib", homebrew_libomp.display()); + println!("cargo:rustc-link-lib=omp"); + } else { + let macports_libomp = PathBuf::from("/opt/local/lib/libomp"); + if macports_libomp.exists() { + println!("cargo:rustc-link-search=/opt/local/lib/libomp"); + println!("cargo:rustc-link-lib=gomp"); + } else { + // Fallback: let system linker find it + println!("cargo:rustc-link-lib=omp"); + } + } + } else { + // Linux and other Unix-like systems: libgomp comes with GCC + println!("cargo:rustc-link-lib=gomp"); + } + // // Generate bindings // From 95a245af19d9a01e2bcfc6d37c35cd594b0fadfd Mon Sep 17 00:00:00 2001 From: Zehui Zheng Date: Mon, 19 Jan 2026 15:53:57 -0800 Subject: [PATCH 4/5] fix: ci --- .github/actions/cartesi-machine/action.yml | 2 +- .github/workflows/build.yml | 4 ++-- machine/emulator | 2 +- machine/rust-bindings/Cargo.toml | 2 +- machine/rust-bindings/cartesi-machine-sys/build.rs | 2 +- prt/client-lua/computation/machine.lua | 2 +- prt/client-lua/cryptography/hash.lua | 3 ++- prt/measure_constants/Dockerfile | 2 +- test/programs/justfile | 9 ++++++--- 9 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/actions/cartesi-machine/action.yml b/.github/actions/cartesi-machine/action.yml index 8df8a10c..1071a82b 100644 --- a/.github/actions/cartesi-machine/action.yml +++ b/.github/actions/cartesi-machine/action.yml @@ -4,7 +4,7 @@ inputs: version: description: 'Version of Cartesi Machine to install' required: false - default: 0.19.0 + default: 0.20.0-test suffix-version: description: 'Suffix of Cartesi Machine to install' required: false diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2f9b4e8..111930a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: - name: Install Cartesi Machine uses: ./.github/actions/cartesi-machine with: - version: 0.19.0 + version: 0.20.0-test suffix-version: "" - name: Setup env @@ -71,7 +71,7 @@ jobs: - name: Install Cartesi Machine uses: ./.github/actions/cartesi-machine with: - version: 0.19.0 + version: 0.20.0-test - name: Download PRT contracts working-directory: ./prt/contracts run: | diff --git a/machine/emulator b/machine/emulator index ec1487c9..83e8d769 160000 --- a/machine/emulator +++ b/machine/emulator @@ -1 +1 @@ -Subproject commit ec1487c9b39eaf5db2ea45c0a8057fa85ace8e2d +Subproject commit 83e8d7695515f9ca59993f1bd669131f730f560f diff --git a/machine/rust-bindings/Cargo.toml b/machine/rust-bindings/Cargo.toml index 91400111..b10455a6 100644 --- a/machine/rust-bindings/Cargo.toml +++ b/machine/rust-bindings/Cargo.toml @@ -8,7 +8,7 @@ members = [ [workspace.package] -version = "0.19.0" +version = "0.20.0-test" edition = "2021" license = "Apache-2.0" diff --git a/machine/rust-bindings/cartesi-machine-sys/build.rs b/machine/rust-bindings/cartesi-machine-sys/build.rs index e04c3998..75748ffe 100644 --- a/machine/rust-bindings/cartesi-machine-sys/build.rs +++ b/machine/rust-bindings/cartesi-machine-sys/build.rs @@ -219,7 +219,7 @@ mod build_cm { process::{Command, Stdio}, }; - const VERSION_STRING: &str = "v0.19.0"; + const VERSION_STRING: &str = "v0.20.0-test"; pub fn download(machine_dir_path: &Path) { let patch_file = machine_dir_path.join("add-generated-files.diff"); diff --git a/prt/client-lua/computation/machine.lua b/prt/client-lua/computation/machine.lua index e292f87e..655d883a 100644 --- a/prt/client-lua/computation/machine.lua +++ b/prt/client-lua/computation/machine.lua @@ -334,7 +334,7 @@ function Machine:prove_read_leaf(address) return data end -local keccak = require "cartesi".keccak +local keccak = cartesi.keccak256 function Machine:prove_write_leaf(address) -- always write aligned 32 bytes (one leaf) diff --git a/prt/client-lua/cryptography/hash.lua b/prt/client-lua/cryptography/hash.lua index 30638be4..e334a9a9 100644 --- a/prt/client-lua/cryptography/hash.lua +++ b/prt/client-lua/cryptography/hash.lua @@ -1,4 +1,5 @@ -local keccak = require "cartesi".keccak +local cartesi = require "cartesi" +local keccak = cartesi.keccak256 local conversion = require "utils.conversion" local interned_hashes = {} diff --git a/prt/measure_constants/Dockerfile b/prt/measure_constants/Dockerfile index 09eace3f..028c896b 100644 --- a/prt/measure_constants/Dockerfile +++ b/prt/measure_constants/Dockerfile @@ -1,4 +1,4 @@ -FROM cartesi/machine-emulator:0.19.0 +FROM cartesi/machine-emulator:0.20.0-test USER root RUN apt-get update && \ diff --git a/test/programs/justfile b/test/programs/justfile index c5acdb2d..296e7457 100644 --- a/test/programs/justfile +++ b/test/programs/justfile @@ -17,7 +17,7 @@ clean-program prog: # yield build-yield: clean-yield cartesi-machine --ram-image=./linux.bin \ - --flash-drive=label:root,filename:./rootfs.ext2 \ + --flash-drive=label:root,data_filename:./rootfs.ext2 \ --no-rollback --store=./yield/machine-image \ -- "while true; do yield manual rx-accepted; yield manual rx-rejected; done" clean-yield: (clean-program "yield") @@ -25,7 +25,7 @@ clean-yield: (clean-program "yield") # echo build-echo: clean-echo cartesi-machine --ram-image=./linux.bin \ - --flash-drive=label:root,filename:./rootfs.ext2 \ + --flash-drive=label:root,data_filename:./rootfs.ext2 \ --no-rollback --store=./echo/machine-image \ -- "ioctl-echo-loop --vouchers=1 --notices=1 --reports=1 --verbose=1 --reject=2" clean-echo: (clean-program "echo") @@ -34,6 +34,9 @@ clean-echo: (clean-program "echo") build-honeypot-snapshot: clean-honeypot-snapshot clean-honeypot-project git clone https://github.com/cartesi/honeypot.git honeypot/project git -C honeypot/project reset --hard 34d00721a527eeb7ed8cce2a13a142e3d8de9aad # v3.0.0 + sed -i 's/,filename:/,data_filename:/g' honeypot/project/Makefile + sed -i 's/--append-bootargs=ro/--append-bootargs=rw/g' honeypot/project/Makefile + sed -i 's/label:state,length:4096,user:dapp/label:state,length:4096,user:dapp,mke2fs:false,mount:false/g' honeypot/project/Makefile mkdir -p honeypot/project/config/devnet ./honeypot/generate-devnet-honeypot-config.sh > honeypot/project/config/devnet/honeypot-config.hpp make -C honeypot/project snapshot HONEYPOT_CONFIG=devnet @@ -45,7 +48,7 @@ clean-honeypot-project: # compute build-compute: clean-compute cartesi-machine --ram-image=./linux.bin \ - --flash-drive=label:root,filename:./rootfs.ext2 \ + --flash-drive=label:root,data_filename:./rootfs.ext2 \ --no-rollback --store=./compute/machine-image \ --max-mcycle=0 \ -- "while dd if=/dev/zero bs=1M count=64 2>/dev/null | md5sum >/dev/null; do :; done" From 77e3314c02190dbdc6c23be29ba5861ed9f5c69c Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Fri, 6 Feb 2026 13:19:25 -0300 Subject: [PATCH 5/5] fix: tweaks --- .../contracts/src/DaveConsensus.sol | 2 +- .../contracts/test/DaveConsensus.t.sol | 2 +- justfile | 23 +++++++++---------- machine/step | 2 +- prt/tests/rollups/justfile | 2 +- test/programs/justfile | 8 +++---- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cartesi-rollups/contracts/src/DaveConsensus.sol b/cartesi-rollups/contracts/src/DaveConsensus.sol index 5b7a687d..c3976d19 100644 --- a/cartesi-rollups/contracts/src/DaveConsensus.sol +++ b/cartesi-rollups/contracts/src/DaveConsensus.sol @@ -221,7 +221,7 @@ contract DaveConsensus is IDaveConsensus, ERC165 { require(proof.length == Memory.LOG2_MAX_SIZE, InvalidOutputsMerkleRootProofSize(proof.length)); bytes32 allegedStateHash = proof.merkleRootAfterReplacement( - EmulatorConstants.PMA_CMIO_TX_BUFFER_START >> EmulatorConstants.TREE_LOG2_WORD_SIZE, + EmulatorConstants.AR_CMIO_TX_BUFFER_START >> EmulatorConstants.HASH_TREE_LOG2_WORD_SIZE, keccak256(abi.encode(outputsMerkleRoot)) ); diff --git a/cartesi-rollups/contracts/test/DaveConsensus.t.sol b/cartesi-rollups/contracts/test/DaveConsensus.t.sol index da91e095..4e40f1ba 100644 --- a/cartesi-rollups/contracts/test/DaveConsensus.t.sol +++ b/cartesi-rollups/contracts/test/DaveConsensus.t.sol @@ -601,7 +601,7 @@ contract DaveConsensusTest is Test { bytes32 root = new LibMerkle32Wrapper() .merkleRootAfterReplacement( - siblings, EmulatorConstants.PMA_CMIO_TX_BUFFER_START >> EmulatorConstants.TREE_LOG2_WORD_SIZE, leaf + siblings, EmulatorConstants.AR_CMIO_TX_BUFFER_START >> EmulatorConstants.TREE_LOG2_WORD_SIZE, leaf ); assertEq(current, root); diff --git a/justfile b/justfile index 5918c637..4c251252 100644 --- a/justfile +++ b/justfile @@ -1,22 +1,21 @@ update-submodules: git submodule update --recursive --init -apply-generated-files-diff VERSION="v0.19.0": - cd machine/emulator && \ - wget https://github.com/cartesi/machine-emulator/releases/download/{{VERSION}}/add-generated-files.diff && \ - git apply add-generated-files.diff - -bundle-boost: - make -C machine/emulator bundle-boost - clean-emulator: - make -C machine/emulator clean depclean distclean + make -C machine/emulator clean # don't clean the patch file clean-contracts: clean-consensus-contracts clean-prt-contracts clean-bindings clean-deployments - make -C machine/emulator clean depclean distclean + make -C machine/emulator clean # wtf? this is cleaning the emulator, not contracts -setup: update-submodules clean-emulator clean-contracts bundle-boost apply-generated-files-diff - make -C machine/emulator # Requires docker, necessary for machine bindings +# setup the emulator locally. +# ```sh +# export PATH=$PATH:$PWD/usr/bin +# ``` +setup: update-submodules clean-emulator clean-contracts + make -C machine/emulator bundle-boost + make -C machine/emulator uarch-with-toolchain # Requires docker, necessary for machine bindings + make -C machine/emulator -j$(nproc) all + make -C machine/emulator install DESTDIR=$PWD/ PREFIX=usr/ # Run this once after cloning, if using a docker environment setup-docker: setup build-docker-image diff --git a/machine/step b/machine/step index e8050ddf..3807f441 160000 --- a/machine/step +++ b/machine/step @@ -1 +1 @@ -Subproject commit e8050ddfdb986d6014bebdfc1d33e16cb3b2528a +Subproject commit 3807f4418cc4dde73d30ed7ef0deba91d7035508 diff --git a/prt/tests/rollups/justfile b/prt/tests/rollups/justfile index 260ed98c..5aa45d93 100644 --- a/prt/tests/rollups/justfile +++ b/prt/tests/rollups/justfile @@ -10,7 +10,7 @@ test PROGRAM SCRIPT: ANVIL_LOAD_PATH=`realpath {{ANVIL_LOAD_PATH}}` \ ANVIL_DUMP_PATH="anvil_{{PROGRAM}}_{{SCRIPT}}.json" \ TEMPLATE_MACHINE=`realpath ../../../test/programs/{{PROGRAM}}/machine-image` \ - TEMPLATE_MACHINE_HASH=0x`xxd -p -c32 ../../../test/programs/{{PROGRAM}}/machine-image/hash` \ + TEMPLATE_MACHINE_HASH=0x`xxd -seek 0x60 -l 0x20 -c 0x20 -p ../../../test/programs/{{PROGRAM}}/machine-image/hash_tree.sht` \ DAVE_APP_FACTORY=`jq -r .address {{DEPLOYMENTS_DIR}}/DaveAppFactory.json` \ INPUT_BOX=`jq -r .address {{DEPLOYMENTS_DIR}}/InputBox.json` \ ERC20_PORTAL=`jq -r .address {{DEPLOYMENTS_DIR}}/ERC20Portal.json` \ diff --git a/test/programs/justfile b/test/programs/justfile index 296e7457..6f30ba3a 100644 --- a/test/programs/justfile +++ b/test/programs/justfile @@ -1,7 +1,7 @@ download-deps: clean-deps wget https://github.com/cartesi/image-kernel/releases/download/v0.20.0/linux-6.5.13-ctsi-1-v0.20.0.bin \ -O ./linux.bin - wget https://github.com/cartesi/machine-emulator-tools/releases/download/v0.17.1/rootfs-tools.ext2 \ + wget https://github.com/cartesi/machine-emulator-tools/releases/download/v0.17.2/rootfs-tools.ext2 \ -O ./rootfs.ext2 clean-deps: @@ -16,7 +16,7 @@ clean-program prog: # yield build-yield: clean-yield - cartesi-machine --ram-image=./linux.bin \ + cartesi-machine --ram-image=./linux.bin --final-hash \ --flash-drive=label:root,data_filename:./rootfs.ext2 \ --no-rollback --store=./yield/machine-image \ -- "while true; do yield manual rx-accepted; yield manual rx-rejected; done" @@ -24,7 +24,7 @@ clean-yield: (clean-program "yield") # echo build-echo: clean-echo - cartesi-machine --ram-image=./linux.bin \ + cartesi-machine --ram-image=./linux.bin --final-hash \ --flash-drive=label:root,data_filename:./rootfs.ext2 \ --no-rollback --store=./echo/machine-image \ -- "ioctl-echo-loop --vouchers=1 --notices=1 --reports=1 --verbose=1 --reject=2" @@ -47,7 +47,7 @@ clean-honeypot-project: # compute build-compute: clean-compute - cartesi-machine --ram-image=./linux.bin \ + cartesi-machine --ram-image=./linux.bin --final-hash \ --flash-drive=label:root,data_filename:./rootfs.ext2 \ --no-rollback --store=./compute/machine-image \ --max-mcycle=0 \