Skip to content
Merged
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
29 changes: 15 additions & 14 deletions cartesi-rollups/node/blockchain-reader/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ use alloy::{
signers::{Signer, local::PrivateKeySigner},
};
use cartesi_dave_contracts::i_dave_app_factory::IDaveAppFactory::{self, WithdrawalConfig};
use cartesi_machine::{Machine, config::runtime::RuntimeConfig};
use cartesi_rollups_contracts::i_input_box::IInputBox;
use serde::Deserialize;
use std::{
fs::{self, File},
io::{Read, Seek},
path::PathBuf,
};
use std::{fs, path::PathBuf};

type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

Expand Down Expand Up @@ -76,15 +73,19 @@ pub async fn spawn_anvil_and_provider() -> Result<(AnvilInstance, DynProvider, A
let input_box = deployment_address("InputBox");
let dave_app_factory = deployment_address("DaveAppFactory");

let initial_hash = {
// Root hash is stored in hash_tree.sht at offset 0x60 (node 1's hash in sparse tree).
// Equivalent to: xxd -seek 0x60 -l 0x20 -c 0x20 -p .../machine-image/hash_tree.sht
let mut file =
File::open(program_path.join("machine-image").join("hash_tree.sht")).unwrap();
file.seek(std::io::SeekFrom::Start(0x60)).unwrap();
let mut buffer = [0u8; 32];
file.read_exact(&mut buffer).unwrap();
buffer
// Load the stored machine through the emulator and ask it for the root
// hash, rather than reading the internal `hash_tree.sht` file directly.
// The file layout is an emulator implementation detail; going through
// `cm_load_new` + `cm_get_root_hash` is the only stable API.
let initial_hash: [u8; 32] = {
let mut machine = Machine::load(
&program_path.join("machine-image"),
&RuntimeConfig::quiet_console(),
)
.expect("failed to load stored machine");
machine
.root_hash()
.expect("failed to read machine root hash")
};

let withdrawal_config = WithdrawalConfig {
Expand Down
18 changes: 6 additions & 12 deletions cartesi-rollups/node/state-manager/src/rollups_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
use std::path::{Path, PathBuf};

use cartesi_prt_core::machine::constants::{
LOG2_BARCH_SPAN_TO_INPUT, LOG2_INPUT_SPAN_TO_EPOCH, LOG2_UARCH_SPAN_TO_BARCH,
CHECKPOINT_ADDRESS, LOG2_BARCH_SPAN_TO_INPUT, LOG2_INPUT_SPAN_TO_EPOCH,
LOG2_UARCH_SPAN_TO_BARCH,
};

use crate::{CommitmentLeaf, Proof};
use cartesi_machine::{
config::runtime::{HTIFRuntimeConfig, RuntimeConfig},
constants::{break_reason, machine::TREE_LOG2_ROOT_SIZE, pma::TX_START},
config::runtime::RuntimeConfig,
constants::{ar::TX_START, break_reason, machine::HASH_TREE_LOG2_ROOT_SIZE},
error::{MachineError, MachineResult},
machine::Machine,
types::{
Expand Down Expand Up @@ -45,8 +46,6 @@ pub const STRIDE_COUNT_IN_EPOCH: u64 = 1
<< (LOG2_INPUT_SPAN_TO_EPOCH + LOG2_BARCH_SPAN_TO_INPUT + LOG2_UARCH_SPAN_TO_BARCH
- LOG2_STRIDE);

pub const CHECKPOINT_ADDRESS: u64 = 0xfe0;

pub struct RollupsMachine {
machine: Machine,
epoch_number: u64,
Expand All @@ -59,12 +58,7 @@ impl RollupsMachine {
epoch_number: u64,
next_input_index_in_epoch: u64,
) -> MachineResult<Self> {
let runtime_config = RuntimeConfig {
htif: Some(HTIFRuntimeConfig {
no_console_putchar: Some(true),
}),
..Default::default()
};
let runtime_config = RuntimeConfig::quiet_console();
let machine = Machine::load(path, &runtime_config)?;

Ok(Self {
Expand All @@ -88,7 +82,7 @@ impl RollupsMachine {
}

pub fn outputs_proof(&mut self) -> MachineResult<(Hash, Proof)> {
let proof = self.machine.proof(TX_START, 5, TREE_LOG2_ROOT_SIZE)?;
let proof = self.machine.proof(TX_START, 5, HASH_TREE_LOG2_ROOT_SIZE)?;
let siblings = Proof::new(proof.sibling_hashes);
let output_merkle = self.machine.read_memory(TX_START, 32)?;

Expand Down
Loading
Loading