Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/cartesi-machine/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion machine/emulator
Submodule emulator updated 308 files
2 changes: 1 addition & 1 deletion machine/rust-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [


[workspace.package]
version = "0.19.0"
version = "0.20.0-test"
edition = "2021"

license = "Apache-2.0"
Expand Down
24 changes: 23 additions & 1 deletion machine/rust-bindings/cartesi-machine-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -197,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");
Expand Down
18 changes: 9 additions & 9 deletions machine/rust-bindings/cartesi-machine/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 23 additions & 19 deletions machine/rust-bindings/cartesi-machine/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ impl Machine {
pub fn create(config: &MachineConfig, runtime_config: &RuntimeConfig) -> Result<Self> {
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,
)
};
Expand All @@ -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,
)
};
Expand All @@ -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(())
Expand Down Expand Up @@ -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)?;

Expand All @@ -205,7 +209,7 @@ impl Machine {
pub fn memory_ranges(&mut self) -> Result<MemoryRangeDescriptions> {
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);
Expand Down
2 changes: 1 addition & 1 deletion prt/client-lua/computation/machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion prt/client-lua/cryptography/hash.lua
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion prt/measure_constants/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
9 changes: 6 additions & 3 deletions test/programs/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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")

# 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")
Expand All @@ -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
Expand All @@ -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"
Expand Down
Loading