From 7d052a825f6f1d142a1ade02d0e20856b7b1f590 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 19 Nov 2024 11:28:17 +0800 Subject: [PATCH] Remove the legacy code and fix the batch poster (#318) * Remove the legacy code and fix the test --- Makefile | 2 +- arbitrator/Cargo.lock | 42 +--- arbitrator/jit/Cargo.toml | 2 - arbitrator/jit/src/machine.rs | 8 - arbitrator/jit/src/wavmio.rs | 51 ----- arbitrator/prover/src/host.rs | 15 -- arbitrator/prover/src/lib.rs | 82 -------- arbitrator/prover/src/machine.rs | 76 ------- arbitrator/prover/src/wavm.rs | 10 - .../test-cases/global-state-wrapper.wat | 2 - .../prover/test-cases/read-hotshot-10.wat | 16 -- .../prover/test-cases/rust/src/bin/host-io.rs | 1 - arbitrator/wasm-libraries/Cargo.lock | 4 +- arbitrator/wasm-libraries/host-io/src/lib.rs | 16 -- arbnode/batch_poster.go | 21 +- arbnode/transaction_streamer.go | 36 +--- arbos/arbostypes/incomingmessage.go | 15 -- arbos/parse_l2.go | 188 ------------------ arbos/parse_l2_test.go | 66 ------ execution/gethexec/executionengine.go | 21 +- staker/block_challenge_backend.go | 3 - staker/block_validator.go | 3 +- staker/challenge_test.go | 18 -- staker/stateless_block_validator.go | 10 +- system_tests/espresso_machine_test.go | 74 ------- system_tests/seqfeed_test.go | 1 - validator/server_api/json.go | 13 -- validator/server_arb/machine.go | 83 -------- validator/server_arb/nitro_machine.go | 62 ------ validator/server_arb/validator_spawner.go | 11 - validator/server_jit/jit_machine.go | 13 -- validator/server_jit/spawner.go | 13 -- validator/validation_entry.go | 6 - wavmio/higher.go | 9 - wavmio/raw.go | 6 - wavmio/stub.go | 10 - 36 files changed, 34 insertions(+), 975 deletions(-) delete mode 100644 arbitrator/prover/test-cases/read-hotshot-10.wat delete mode 100644 arbos/parse_l2_test.go delete mode 100644 system_tests/espresso_machine_test.go diff --git a/Makefile b/Makefile index 071735351b..3da58a79ca 100644 --- a/Makefile +++ b/Makefile @@ -188,7 +188,7 @@ test-go-deps: \ $(stylus_test_wasms) \ $(arbitrator_stylus_lib) \ $(arbitrator_generated_header) \ - $(patsubst %,$(arbitrator_cases)/%.wasm, global-state read-inboxmsg-10 global-state-wrapper const read-hotshot-10) + $(patsubst %,$(arbitrator_cases)/%.wasm, global-state read-inboxmsg-10 global-state-wrapper const) .PHONY: build-prover-header build-prover-header: $(arbitrator_generated_header) diff --git a/arbitrator/Cargo.lock b/arbitrator/Cargo.lock index 634ce6be5a..79a9117a31 100644 --- a/arbitrator/Cargo.lock +++ b/arbitrator/Cargo.lock @@ -49,12 +49,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "aliasable" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" - [[package]] name = "allocator-api2" version = "0.2.18" @@ -1086,12 +1080,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -1245,9 +1233,7 @@ dependencies = [ "caller-env", "eyre", "hex", - "lazy_static", "libc", - "ouroboros", "parking_lot", "prover", "rand", @@ -1303,9 +1289,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.161" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libfuzzer-sys" @@ -1612,30 +1598,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "ouroboros" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6a6d0919a92ba28d8109a103e0de08f89706be0eeaad1130fd1a34030dee84a" -dependencies = [ - "aliasable", - "ouroboros_macro", - "static_assertions", -] - -[[package]] -name = "ouroboros_macro" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46bc2307dc3420554ae349230dac4969c66d7c2feead3a8cab05ea0c604daca6" -dependencies = [ - "heck 0.4.1", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "parking_lot" version = "0.12.3" diff --git a/arbitrator/jit/Cargo.toml b/arbitrator/jit/Cargo.toml index 4cf6013370..fb49b871b3 100644 --- a/arbitrator/jit/Cargo.toml +++ b/arbitrator/jit/Cargo.toml @@ -21,8 +21,6 @@ hex = "0.4.3" structopt = "0.3.26" sha3 = "0.9.1" libc = "0.2.132" -ouroboros = "0.16.0" -lazy_static = "1.4" sha2 = "0.9.9" [features] diff --git a/arbitrator/jit/src/machine.rs b/arbitrator/jit/src/machine.rs index 41f3b264c6..02523f740a 100644 --- a/arbitrator/jit/src/machine.rs +++ b/arbitrator/jit/src/machine.rs @@ -83,8 +83,6 @@ pub fn create(opts: &Opts, env: WasmEnv) -> (Instance, FunctionEnv, Sto } }, "resolveTypedPreimage" => func!(wavmio::resolve_typed_preimage), - "readHotShotCommitment" => func!(wavmio::read_hotshot_commitment), - "isHotShotLive" => func!(wavmio::is_hotshot_live), }, "wasi_snapshot_preview1" => { "proc_exit" => func!(wasip1_stub::proc_exit), @@ -190,8 +188,6 @@ pub type WasmEnvMut<'a> = FunctionEnvMut<'a, WasmEnv>; pub type Inbox = BTreeMap>; pub type Preimages = BTreeMap>>; pub type ModuleAsm = Arc<[u8]>; -pub type HotShotCommitmentMap = BTreeMap; -pub type HotShotLivenessMap = BTreeMap; #[derive(Default)] pub struct WasmEnv { @@ -209,10 +205,6 @@ pub struct WasmEnv { pub module_asms: HashMap, /// The sequencer inbox's messages pub sequencer_messages: Inbox, - /// Mapping from batch positions to hotshot commitments - pub hotshot_comm_map: HotShotCommitmentMap, - /// Mapping from l1 height to hotshot liveness - pub hotshot_avail_map: HotShotLivenessMap, /// The delayed inbox's messages pub delayed_messages: Inbox, /// The purpose and connections of this process diff --git a/arbitrator/jit/src/wavmio.rs b/arbitrator/jit/src/wavmio.rs index ec33a0fe9b..0ca666d3b2 100644 --- a/arbitrator/jit/src/wavmio.rs +++ b/arbitrator/jit/src/wavmio.rs @@ -85,47 +85,6 @@ pub fn read_inbox_message( Ok(read.len() as u32) } -pub fn is_hotshot_live(mut env: WasmEnvMut, h: u64) -> Result { - let (_mem, exec) = env.jit_env(); - ready_hostio(exec)?; - - let liveness = match exec.hotshot_avail_map.get(&h) { - Some(liveness) => liveness, - None => { - return Escape::hostio(format!( - "jit machine failed to read the hotshot liveness at {}", - h - )) - } - }; - if *liveness { - Ok(1) - } else { - Ok(0) - } -} - -pub fn read_hotshot_commitment( - mut env: WasmEnvMut, - h: u64, - out_ptr: GuestPtr, -) -> Result<(), Escape> { - let (mut mem, exec) = env.jit_env(); - ready_hostio(exec)?; - - let comm = match exec.hotshot_comm_map.get(&h) { - Some(comm) => comm, - None => { - return Escape::hostio(format!( - "jit machine failed to read the hotshot commitment at {}", - h - )) - } - }; - mem.write_slice(out_ptr, comm); - Ok(()) -} - /// Reads a delayed inbox message. pub fn read_delayed_inbox_message( mut env: WasmEnvMut, @@ -302,19 +261,9 @@ fn ready_hostio(env: &mut WasmEnv) -> MaybeEscape { let position_within_message = socket::read_u64(stream)?; let last_block_hash = socket::read_bytes32(stream)?; let last_send_root = socket::read_bytes32(stream)?; - let hotshot_comm = socket::read_bytes32(stream)?; - let block_height = socket::read_u64(stream)?; - let hotshot_liveness = socket::read_u8(stream)?; env.small_globals = [inbox_position, position_within_message]; env.large_globals = [last_block_hash, last_send_root]; - if hotshot_liveness > 0 { - // HotShot is up - env.hotshot_comm_map.insert(block_height, hotshot_comm.0); - } else { - env.hotshot_avail_map - .insert(block_height, hotshot_liveness > 0); - } while socket::read_u8(stream)? == socket::ANOTHER { let position = socket::read_u64(stream)?; diff --git a/arbitrator/prover/src/host.rs b/arbitrator/prover/src/host.rs index 9ff9b33796..1d0fe658ec 100644 --- a/arbitrator/prover/src/host.rs +++ b/arbitrator/prover/src/host.rs @@ -76,8 +76,6 @@ pub enum Hostio { WavmReadSha256Preimage, WavmReadEthVersionedHashPreimage, WavmReadInboxMessage, - WavmReadHotShotCommitment, - WavmIsHotShotLive, WavmReadDelayedInboxMessage, WavmHaltAndSetFinished, WavmLinkModule, @@ -126,8 +124,6 @@ impl FromStr for Hostio { ("env", "wavm_read_eth_versioned_hash_preimage") => WavmReadEthVersionedHashPreimage, ("env", "wavm_read_inbox_message") => WavmReadInboxMessage, ("env", "wavm_read_delayed_inbox_message") => WavmReadDelayedInboxMessage, - ("env", "wavm_read_hotshot_commitment") => WavmReadHotShotCommitment, - ("env", "wavm_is_hotshot_live") => WavmIsHotShotLive, ("env", "wavm_halt_and_set_finished") => WavmHaltAndSetFinished, ("hostio", "wavm_link_module") => WavmLinkModule, ("hostio", "wavm_unlink_module") => WavmUnlinkModule, @@ -190,8 +186,6 @@ impl Hostio { WavmReadInboxMessage => func!([I64, I32, I32], [I32]), WavmReadDelayedInboxMessage => func!([I64, I32, I32], [I32]), WavmHaltAndSetFinished => func!(), - WavmReadHotShotCommitment => func!([I32, I64]), - WavmIsHotShotLive => func!([I64], [I32]), WavmLinkModule => func!([I32], [I32]), // λ(module_hash) → module WavmUnlinkModule => func!(), // λ() ProgramInkLeft => func!([I32], [I64]), // λ(module) → ink_left @@ -292,15 +286,6 @@ impl Hostio { opcode!(LocalGet, 1); opcode!(ReadPreImage, PreimageType::Sha2_256); } - WavmReadHotShotCommitment => { - opcode!(LocalGet, 0); - opcode!(LocalGet, 1); - opcode!(ReadHotShotCommitment); - } - WavmIsHotShotLive => { - opcode!(LocalGet, 0); - opcode!(IsHotShotLive); - } WavmReadEthVersionedHashPreimage => { opcode!(LocalGet, 0); opcode!(LocalGet, 1); diff --git a/arbitrator/prover/src/lib.rs b/arbitrator/prover/src/lib.rs index f203055f00..0f537478eb 100644 --- a/arbitrator/prover/src/lib.rs +++ b/arbitrator/prover/src/lib.rs @@ -33,7 +33,6 @@ use machine::{ use once_cell::sync::OnceCell; use static_assertions::const_assert_eq; use std::{ - convert::TryInto, ffi::CStr, num::NonZeroUsize, os::raw::{c_char, c_int}, @@ -208,37 +207,6 @@ pub unsafe extern "C" fn arbitrator_add_inbox_message( } } -#[no_mangle] -pub unsafe extern "C" fn arbitrator_add_hotshot_commitment( - mach: *mut Machine, - height: u64, - data: CByteArray, -) -> c_int { - let mach = &mut *mach; - let slice = slice::from_raw_parts(data.ptr, data.len); - if slice.len() != 32 { - return 3; - } - let data: Result<[u8; 32], _> = slice.try_into(); - if let Ok(comm) = data { - mach.add_hotshot_commitment(height, comm); - 0 - } else { - 1 - } -} - -#[no_mangle] -pub unsafe extern "C" fn arbitrator_add_hotshot_liveness( - mach: *mut Machine, - height: u64, - liveness: u8, -) -> c_int { - let mach = &mut *mach; - mach.add_hotshot_liveness(height, liveness > 0); - 0 -} - /// Adds a user program to the machine's known set of wasms. #[no_mangle] pub unsafe extern "C" fn arbitrator_add_user_wasm( @@ -278,56 +246,6 @@ pub unsafe extern "C" fn arbitrator_step_until_host_io( ptr::null_mut() } -#[no_mangle] -#[cfg(feature = "native")] -pub unsafe extern "C" fn arbitrator_step_until_is_hotshot_live( - mach: *mut Machine, - condition: *const u8, -) -> *mut libc::c_char { - let mach = &mut *mach; - let condition = &*(condition as *const AtomicU8); - while condition.load(atomic::Ordering::Relaxed) == 0 { - for _ in 0..1_000_000 { - if mach.is_halted() { - return ptr::null_mut(); - } - if mach.next_instruction_is_read_hotshot() { - return ptr::null_mut(); - } - match mach.step_n(1) { - Ok(()) => {} - Err(err) => return err_to_c_string(err), - } - } - } - ptr::null_mut() -} - -#[no_mangle] -#[cfg(feature = "native")] -pub unsafe extern "C" fn arbitrator_step_until_read_hotshot( - mach: *mut Machine, - condition: *const u8, -) -> *mut libc::c_char { - let mach = &mut *mach; - let condition = &*(condition as *const AtomicU8); - while condition.load(atomic::Ordering::Relaxed) == 0 { - for _ in 0..1_000_000 { - if mach.is_halted() { - return ptr::null_mut(); - } - if mach.next_instruction_is_read_hotshot() { - return ptr::null_mut(); - } - match mach.step_n(1) { - Ok(()) => {} - Err(err) => return err_to_c_string(err), - } - } - } - ptr::null_mut() -} - #[no_mangle] pub unsafe extern "C" fn arbitrator_serialize_state( mach: *const Machine, diff --git a/arbitrator/prover/src/machine.rs b/arbitrator/prover/src/machine.rs index a3ee0fd527..4ece1f7bf2 100644 --- a/arbitrator/prover/src/machine.rs +++ b/arbitrator/prover/src/machine.rs @@ -802,7 +802,6 @@ impl From for FunctionSerdeAll { // bytes32 - send_root // uint64 - inbox_position // uint64 - position_within_message -// uint64 - espresso hotshot height pub const GLOBAL_STATE_BYTES32_NUM: usize = 2; pub const GLOBAL_STATE_U64_NUM: usize = 2; @@ -987,8 +986,6 @@ pub struct Machine { pc: ProgramCounter, stdio_output: Vec, inbox_contents: HashMap<(InboxIdentifier, u64), Vec>, - hotshot_commitments: HashMap, - hotshot_liveness: HashMap, first_too_far: u64, // Not part of machine hash preimage_resolver: PreimageResolverWrapper, /// Linkable Stylus modules in compressed form. Not part of the machine hash. @@ -1562,9 +1559,7 @@ impl Machine { stylus_modules: HashMap::default(), initial_hash: Bytes32::default(), context: 0, - hotshot_commitments: Default::default(), debug_info, - hotshot_liveness: Default::default(), }; mach.initial_hash = mach.hash(); Ok(mach) @@ -1620,8 +1615,6 @@ impl Machine { stylus_modules: HashMap::default(), initial_hash: Bytes32::default(), context: 0, - hotshot_commitments: Default::default(), - hotshot_liveness: Default::default(), debug_info: false, }; mach.initial_hash = mach.hash(); @@ -1891,18 +1884,6 @@ impl Machine { .unwrap_or(true) } - pub fn next_instruction_is_read_hotshot(&self) -> bool { - self.get_next_instruction() - .map(|i| i.opcode == Opcode::ReadHotShotCommitment) - .unwrap_or(true) - } - - pub fn next_instruction_is_hotshot_live(&self) -> bool { - self.get_next_instruction() - .map(|i| i.opcode == Opcode::IsHotShotLive) - .unwrap_or(true) - } - pub fn get_pc(&self) -> Option { if self.is_halted() { return None; @@ -2489,29 +2470,6 @@ impl Machine { assert!(success, "Failed to write to previously read memory"); value_stack.push(Value::I32(len as u32)); } - Opcode::ReadHotShotCommitment => { - let height = value_stack.pop().unwrap().assume_u64(); - let ptr = value_stack.pop().unwrap().assume_u32(); - if let Some(commitment) = self.hotshot_commitments.get(&height) { - if ptr as u64 + 32 > module.memory.size() { - error!(); - } else { - let success = module.memory.store_slice_aligned(ptr.into(), commitment); - assert!(success, "Failed to write to previously read memory"); - } - } else { - error!() - } - } - Opcode::IsHotShotLive => { - let height = value_stack.pop().unwrap().assume_u64(); - if let Some(is_alive) = self.hotshot_liveness.get(&height) { - let value = if *is_alive { 1 } else { 0 }; - value_stack.push(Value::I32(value)); - } else { - error!() - } - } Opcode::ReadInboxMessage => { let offset = value_stack.pop().unwrap().assume_u32(); let ptr = value_stack.pop().unwrap().assume_u32(); @@ -3099,32 +3057,6 @@ impl Machine { } } } - ReadHotShotCommitment => { - let ptr = value_stack.get(0).unwrap().assume_u32(); - if let Some(mut idx) = usize::try_from(ptr).ok().filter(|x| x % 32 == 0) { - idx /= Memory::LEAF_SIZE; - let prev_data = module.memory.get_leaf_data(idx); - data.extend(prev_data); - data.extend(mem_merkle.prove(idx).unwrap_or_default()); - - let h = value_stack.get(1).unwrap().assume_u64(); - if let Some(commitment) = self.hotshot_commitments.get(&h) { - data.extend(commitment); - println!("read hotshot commitment proof generated. height: {:?}, commitment: {:?}", h, commitment); - } - } else { - panic!("Should never ever get here") - } - } - IsHotShotLive => { - let h = value_stack.get(0).unwrap().assume_u64(); - if let Some(avail) = self.hotshot_liveness.get(&h) { - let v: u8 = if *avail { 1 } else { 0 }; - data.push(v); - } else { - panic!("cannot find the hotshot liveness {}", h) - } - } LinkModule | UnlinkModule => { if op == LinkModule { let leaf_index = match value_stack.last() { @@ -3226,14 +3158,6 @@ impl Machine { } } - pub fn add_hotshot_commitment(&mut self, height: u64, commitment: [u8; 32]) { - self.hotshot_commitments.insert(height, commitment); - } - - pub fn add_hotshot_liveness(&mut self, height: u64, liveness: bool) { - self.hotshot_liveness.insert(height, liveness); - } - pub fn get_module_names(&self, module: usize) -> Option<&NameCustomSection> { self.modules.get(module).map(|m| &*m.names) } diff --git a/arbitrator/prover/src/wavm.rs b/arbitrator/prover/src/wavm.rs index 0273b7222e..de016452f3 100644 --- a/arbitrator/prover/src/wavm.rs +++ b/arbitrator/prover/src/wavm.rs @@ -171,11 +171,6 @@ pub enum Opcode { PopCoThread, /// switch between main and a cothread SwitchThread, - - /// Reads the HotShot commitment on the stack at an offset - ReadHotShotCommitment, - /// Gets the HotShot availability at a given L1 height - IsHotShotLive, } impl Opcode { @@ -293,9 +288,6 @@ impl Opcode { Opcode::NewCoThread => 0x8030, Opcode::PopCoThread => 0x8031, Opcode::SwitchThread => 0x8032, - - Opcode::ReadHotShotCommitment => 0x9001, - Opcode::IsHotShotLive => 0x9002, } } @@ -308,8 +300,6 @@ impl Opcode { | Opcode::SetGlobalStateU64 | Opcode::ReadPreImage | Opcode::ReadInboxMessage - | Opcode::ReadHotShotCommitment - | Opcode::IsHotShotLive ) } } diff --git a/arbitrator/prover/test-cases/global-state-wrapper.wat b/arbitrator/prover/test-cases/global-state-wrapper.wat index 47671aa210..8c7f30142e 100644 --- a/arbitrator/prover/test-cases/global-state-wrapper.wat +++ b/arbitrator/prover/test-cases/global-state-wrapper.wat @@ -4,11 +4,9 @@ (import "env" "wavm_set_globalstate_u64" (func $set (param i32) (param i64))) (import "env" "wavm_get_globalstate_u64" (func $get (param i32) (result i64))) (import "env" "wavm_read_inbox_message" (func $readinbox (param i64) (param i32) (param i32) (result i32))) -(import "env" "wavm_read_hotshot_commitment" (func $readhotshot (param i32) (param i64))) (import "env" "wavm_halt_and_set_finished" (func $halt)) (export "wrapper__set_globalstate_u64" (func $set)) (export "wrapper__get_globalstate_u64" (func $get)) (export "wrapper__read_inbox_message" (func $readinbox)) -(export "wrapper_read_hotshot_commitment" (func $readhotshot)) (export "wrapper__halt_and_set_finished" (func $halt)) diff --git a/arbitrator/prover/test-cases/read-hotshot-10.wat b/arbitrator/prover/test-cases/read-hotshot-10.wat deleted file mode 100644 index 8724c58459..0000000000 --- a/arbitrator/prover/test-cases/read-hotshot-10.wat +++ /dev/null @@ -1,16 +0,0 @@ -(import "env" "wavm_set_globalstate_u64" (func $set (param i32) (param i64))) -(import "env" "wavm_get_globalstate_u64" (func $get (param i32) (result i64))) -(import "env" "wavm_read_hotshot_commitment" (func $readhotshot (param i32) (param i64))) -(import "env" "wavm_halt_and_set_finished" (func $halt)) - -(memory 1) - -(func $entry - (i32.const 0) - (i64.const 10) - (call $readhotshot) - ;; halt - (call $halt) -) - -(start $entry) \ No newline at end of file diff --git a/arbitrator/prover/test-cases/rust/src/bin/host-io.rs b/arbitrator/prover/test-cases/rust/src/bin/host-io.rs index a6bf980ba3..679ee14486 100644 --- a/arbitrator/prover/test-cases/rust/src/bin/host-io.rs +++ b/arbitrator/prover/test-cases/rust/src/bin/host-io.rs @@ -8,7 +8,6 @@ extern "C" { pub fn wavm_read_eth_versioned_hash_preimage(ptr: *mut u8, offset: usize) -> usize; pub fn wavm_read_inbox_message(msg_num: u64, ptr: *mut u8, offset: usize) -> usize; pub fn wavm_read_delayed_inbox_message(seq_num: u64, ptr: *mut u8, offset: usize) -> usize; - pub fn wavm_read_hotshot_commitment(ptr: *mut u8, height: u64); pub fn wavm_halt_and_set_finished(); } diff --git a/arbitrator/wasm-libraries/Cargo.lock b/arbitrator/wasm-libraries/Cargo.lock index 9b605c11b9..7620ff538b 100644 --- a/arbitrator/wasm-libraries/Cargo.lock +++ b/arbitrator/wasm-libraries/Cargo.lock @@ -618,9 +618,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.161" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "lock_api" diff --git a/arbitrator/wasm-libraries/host-io/src/lib.rs b/arbitrator/wasm-libraries/host-io/src/lib.rs index e2e9934b3b..d61cf1a977 100644 --- a/arbitrator/wasm-libraries/host-io/src/lib.rs +++ b/arbitrator/wasm-libraries/host-io/src/lib.rs @@ -17,8 +17,6 @@ extern "C" { pub fn wavm_read_sha2_256_preimage(ptr: *mut u8, offset: usize) -> usize; pub fn wavm_read_eth_versioned_hash_preimage(ptr: *mut u8, offset: usize) -> usize; pub fn wavm_read_inbox_message(msg_num: u64, ptr: *mut u8, offset: usize) -> usize; - pub fn wavm_read_hotshot_commitment(ptr: *mut u8, height: u64); - pub fn wavm_is_hotshot_live(height: u64) -> u32; pub fn wavm_read_delayed_inbox_message(seq_num: u64, ptr: *mut u8, offset: usize) -> usize; } @@ -80,20 +78,6 @@ pub unsafe extern "C" fn wavmio__setGlobalStateU64(idx: u32, val: u64) { wavm_set_globalstate_u64(idx, val); } -#[no_mangle] -pub unsafe extern "C" fn wavmio__readHotShotCommitment(h: u64, out_ptr: GuestPtr) { - let mut our_buf = MemoryLeaf([0u8; 32]); - let our_ptr = our_buf.as_mut_ptr(); - assert_eq!(our_ptr as usize % 32, 0); - wavm_read_hotshot_commitment(our_ptr, h); - STATIC_MEM.write_slice(out_ptr, &our_buf.0[..32]); -} - -#[no_mangle] -pub unsafe extern "C" fn wavmio__isHotShotLive(h: u64) -> u32 { - wavm_is_hotshot_live(h) -} - /// Reads an inbox message #[no_mangle] pub unsafe extern "C" fn wavmio__readInboxMessage( diff --git a/arbnode/batch_poster.go b/arbnode/batch_poster.go index 988181150b..bd2c431057 100644 --- a/arbnode/batch_poster.go +++ b/arbnode/batch_poster.go @@ -55,6 +55,7 @@ import ( "github.com/offchainlabs/nitro/util" "github.com/offchainlabs/nitro/util/arbmath" "github.com/offchainlabs/nitro/util/blobs" + "github.com/offchainlabs/nitro/util/dbutil" "github.com/offchainlabs/nitro/util/headerreader" "github.com/offchainlabs/nitro/util/redisutil" "github.com/offchainlabs/nitro/util/stopwaiter" @@ -540,8 +541,16 @@ func AccessList(opts *AccessListOpts) types.AccessList { func (b *BatchPoster) checkEspressoValidation( msg *arbostypes.MessageWithMetadata, ) error { - - if !arbos.IsEspressoMsg(msg.Message) { + if !b.streamer.chainConfig.ArbitrumChainParams.EnableEspresso { + return nil + } + // We only submit the user transactions to hotshot. Only those messages created by + // sequencer should wait for the finality + if msg.Message.Header.Kind != arbostypes.L1MessageType_L2Message { + return nil + } + kind := msg.Message.L2msg[0] + if kind != arbos.L2MessageKind_Batch && kind != arbos.L2MessageKind_SignedTx { return nil } @@ -553,10 +562,7 @@ func (b *BatchPoster) checkEspressoValidation( return fmt.Errorf("Cannot use a nil ArbOSConfig") } if !arbOSConfig.ArbitrumChainParams.EnableEspresso { - // This case should be highly unlikely, as espresso messages are not produced while ArbitrumChainParams.EnableEspresso is false - // However, in the event that an espresso message was created, and then Enable Espresso was set to false, we should ensure - // the transaction streamer doesn't send any more messages to the espresso network. - return fmt.Errorf("Cannot process Espresso messages when Espresso is not enabled in the ArbOS chain config") + return nil } hasNotSubmitted, err := b.streamer.HasNotSubmitted(b.building.msgCount) @@ -576,6 +582,9 @@ func (b *BatchPoster) checkEspressoValidation( } lastConfirmed, err := b.streamer.getLastConfirmedPos() + if dbutil.IsErrNotFound(err) { + return fmt.Errorf("no confirmed message has been found") + } if err != nil { return err } diff --git a/arbnode/transaction_streamer.go b/arbnode/transaction_streamer.go index c938e217c9..82ba8fb864 100644 --- a/arbnode/transaction_streamer.go +++ b/arbnode/transaction_streamer.go @@ -811,36 +811,6 @@ func (s *TransactionStreamer) countDuplicateMessages( } dbMessageParsed.Message.BatchGasCost = batchGasCostBkup } - msg := nextMessage.MessageWithMeta.Message - if arbos.IsEspressoMsg(dbMessageParsed.Message) && - arbos.IsEspressoMsg(msg) && - !bytes.Equal(msg.L2msg, dbMessageParsed.Message.L2msg) { - // Check to see if the difference is the existence of block merkle proof in the new message, - // The batcher can append this on the fly (see AddEspressoBlockMerkleProof). - // If this is the case, update the database with the block merkle justification. - _, newJst, err := arbos.ParseEspressoMsg(msg) - if err != nil { - return 0, false, nil, err - - } - _, oldJst, err := arbos.ParseEspressoMsg(dbMessageParsed.Message) - if err != nil { - return 0, false, nil, err - } - if oldJst.BlockMerkleJustification == nil && newJst.BlockMerkleJustification != nil { - duplicateMessage = true - if batch != nil { - log.Info("Writing new block justification to DB") - if *batch == nil { - *batch = s.db.NewBatch() - } - if err := s.writeMessage(pos, nextMessage, *batch); err != nil { - return 0, false, nil, err - } - } - } - - } } if !duplicateMessage { @@ -1289,7 +1259,6 @@ func (s *TransactionStreamer) pollSubmittedTransactionForFinality(ctx context.Co return s.config().EspressoTxnsPollingInterval } if len(submittedTxnPos) == 0 { - log.Info("no submitted positions") return s.config().EspressoTxnsPollingInterval } submittedTxHash, err := s.getEspressoSubmittedHash() @@ -1654,14 +1623,15 @@ func (s *TransactionStreamer) submitEspressoTransactions(ctx context.Context, ig s.espressoTxnsStateInsertionMutex.Lock() defer s.espressoTxnsStateInsertionMutex.Unlock() - pendingTxnsPos = pendingTxnsPos[msgCnt-1:] batch := s.db.NewBatch() - err = s.setEspressoSubmittedPos(batch, pendingTxnsPos) + submittedPos := pendingTxnsPos[:msgCnt] + err = s.setEspressoSubmittedPos(batch, submittedPos) if err != nil { log.Error("failed to set the submitted txn pos", "err", err) return s.config().EspressoTxnsPollingInterval } + pendingTxnsPos = pendingTxnsPos[msgCnt:] err = s.setEspressoPendingTxnsPos(batch, pendingTxnsPos) if err != nil { log.Error("failed to set the pending txns", "err", err) diff --git a/arbos/arbostypes/incomingmessage.go b/arbos/arbostypes/incomingmessage.go index 6aab3d2fbd..c4c2dc037b 100644 --- a/arbos/arbostypes/incomingmessage.go +++ b/arbos/arbostypes/incomingmessage.go @@ -15,7 +15,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" - espressoTypes "github.com/EspressoSystems/espresso-sequencer-go/types" "github.com/offchainlabs/nitro/arbos/util" "github.com/offchainlabs/nitro/util/arbmath" ) @@ -35,20 +34,6 @@ const ( const MaxL2MessageSize = 256 * 1024 -type BlockMerkleJustification struct { - // Merkle proof validating the justification header. - BlockMerkleProof *espressoTypes.HotShotBlockMerkleProof - // Block merkle commitment that corresponds to a valid light client snapshot. - BlockMerkleComm *espressoTypes.TaggedBase64 -} - -type EspressoBlockJustification struct { - Header *espressoTypes.HeaderImpl - Proof *espressoTypes.NamespaceProof - VidCommon *espressoTypes.VidCommon - BlockMerkleJustification *BlockMerkleJustification -} - type L1IncomingMessageHeader struct { Kind uint8 `json:"kind"` Poster common.Address `json:"sender"` diff --git a/arbos/parse_l2.go b/arbos/parse_l2.go index 489c62d611..9d372ff803 100644 --- a/arbos/parse_l2.go +++ b/arbos/parse_l2.go @@ -3,7 +3,6 @@ package arbos import ( "bytes" "encoding/binary" - "encoding/json" "errors" "fmt" "io" @@ -15,7 +14,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/rlp" "github.com/offchainlabs/nitro/arbos/arbostypes" "github.com/offchainlabs/nitro/arbos/util" "github.com/offchainlabs/nitro/util/arbmath" @@ -23,14 +21,6 @@ import ( const ESPRESSO_TRANSACTION_SIZE_LIMIT int = 10 * 1024 -func ParseEspressoMsg(msg *arbostypes.L1IncomingMessage) ([]espressoTypes.Bytes, *arbostypes.EspressoBlockJustification, error) { - if msg.Header.Kind != arbostypes.L1MessageType_L2Message { - return nil, nil, errors.New("Parsing espresso transactions failed. Invalid L1Message type") - } - l2Msg := msg.L2msg - return parseEspressoMsg(bytes.NewReader(l2Msg)) -} - func ParseL2Transactions(msg *arbostypes.L1IncomingMessage, chainId *big.Int) (types.Transactions, error) { if len(msg.L2msg) > arbostypes.MaxL2MessageSize { // ignore the message if l2msg is too large @@ -107,8 +97,6 @@ const ( L2MessageKind_Heartbeat = 6 // deprecated L2MessageKind_SignedCompressedTx = 7 // 8 is reserved for BLS signed batch - L2MessageKind_EspressoSequencedTx = 10 - L2MessageKind_EspressoSovereignTx = 11 ) // Warning: this does not validate the day of the week or if DST is being observed @@ -185,40 +173,6 @@ func parseL2Message(rd io.Reader, poster common.Address, timestamp uint64, reque return nil, types.ErrTxTypeNotSupported } return types.Transactions{newTx}, nil - case L2MessageKind_EspressoSequencedTx: - segments := make(types.Transactions, 0) - jst := true - for { - nextMsg, err := util.BytestringFromReader(rd, arbostypes.MaxL2MessageSize) - if err != nil { - // an error here means there are no further messages in the batch - // nolint:nilerr - return segments, nil - } - if jst { - // In espresso transactions batch, the first msg is always the BlockJustification - jst = false - continue - } - newTx := new(types.Transaction) - if err := newTx.UnmarshalBinary(nextMsg); err != nil { - return nil, err - } - segments = append(segments, newTx) - } - case L2MessageKind_EspressoSovereignTx: - // Skip the first transaction(jst), then process it as a normal l2 message - _, err := util.BytestringFromReader(rd, arbostypes.MaxL2MessageSize) - if err != nil { - segments := make(types.Transactions, 0) - return segments, err - } - - result, err := parseL2Message(rd, poster, timestamp, requestId, chainId, depth) - if err != nil { - return nil, err - } - return result, nil case L2MessageKind_Heartbeat: if timestamp >= HeartbeatsDisabledAt { return nil, errors.New("heartbeat messages have been disabled") @@ -233,60 +187,6 @@ func parseL2Message(rd io.Reader, poster common.Address, timestamp uint64, reque } } -func parseEspressoMsg(rd io.Reader) ([]espressoTypes.Bytes, *arbostypes.EspressoBlockJustification, error) { - var l2KindBuf [1]byte - if _, err := rd.Read(l2KindBuf[:]); err != nil { - return nil, nil, err - } - - switch l2KindBuf[0] { - case L2MessageKind_EspressoSequencedTx: - txs := make([]espressoTypes.Bytes, 0) - var jst *arbostypes.EspressoBlockJustification - for { - nextMsg, err := util.BytestringFromReader(rd, arbostypes.MaxL2MessageSize) - if err != nil { - // an error here means there are no further messages in the batch - // nolint:nilerr - return txs, jst, nil - } - if jst == nil { - j := new(arbostypes.EspressoBlockJustification) - s := []byte{} - if err := rlp.DecodeBytes(nextMsg, &s); err != nil { - return nil, nil, err - } - if err := json.Unmarshal(s, j); err != nil { - return nil, nil, err - } - jst = j - continue - } - txs = append(txs, nextMsg) - } - case L2MessageKind_EspressoSovereignTx: - nextMsg, err := util.BytestringFromReader(rd, arbostypes.MaxL2MessageSize) - if err != nil { - return nil, nil, err - } - jst := new(arbostypes.EspressoBlockJustification) - s := []byte{} - if err := rlp.DecodeBytes(nextMsg, &s); err != nil { - return nil, nil, err - } - if err := json.Unmarshal(s, jst); err != nil { - return nil, nil, err - } - bytes, err := io.ReadAll(rd) - if err != nil { - return nil, nil, err - } - return []espressoTypes.Bytes{bytes}, jst, nil - default: - return nil, nil, errors.New("Unexpected l2 message kind") - } -} - func parseUnsignedTx(rd io.Reader, poster common.Address, requestId *common.Hash, chainId *big.Int, txKind byte) (*types.Transaction, error) { gasLimitHash, err := util.HashFromReader(rd) if err != nil { @@ -498,94 +398,6 @@ func parseBatchPostingReportMessage(rd io.Reader, chainId *big.Int, msgBatchGasC }), nil } -// RLP encoding/decoding is not supported in `espresso-sequencer-go`. So the `jst` which contains -// the `EspressoHeader` field, can not be encoded into RLP directly. And as an unfortunate workaround, -// we encode it to `json` first. -// https://github.com/EspressoSystems/espresso-sequencer-go/issues/16 -func GetEspressoJstBytes(jst *arbostypes.EspressoBlockJustification) ([]byte, error) { - var result []byte - jstJson, err := json.Marshal(jst) - if err != nil { - return nil, err - } - jstBin, err := rlp.EncodeToBytes(jstJson) - if err != nil { - return nil, err - } - sizeBuf := make([]byte, 8) - binary.BigEndian.PutUint64(sizeBuf, uint64(len(jstBin))) - - result = append(result, sizeBuf...) - result = append(result, jstBin...) - - return result, nil -} - -// messageFromEspresso serializes raw data from the espresso block into an arbitrum message, -// including malformed and invalid transactions. -// This allows validators to rebuild a block and check the espresso commitment. -func MessageFromEspresso(header *arbostypes.L1IncomingMessageHeader, txes []espressoTypes.Bytes, jst *arbostypes.EspressoBlockJustification) (arbostypes.L1IncomingMessage, error) { - var l2Message []byte - - l2Message = append(l2Message, L2MessageKind_EspressoSequencedTx) - jstBytes, err := GetEspressoJstBytes(jst) - if err != nil { - return arbostypes.L1IncomingMessage{}, err - } - - sizeBuf := make([]byte, 8) - l2Message = append(l2Message, jstBytes...) - for _, tx := range txes { - binary.BigEndian.PutUint64(sizeBuf, uint64(len(tx))) - l2Message = append(l2Message, sizeBuf...) - l2Message = append(l2Message, tx...) - } - - return arbostypes.L1IncomingMessage{ - Header: header, - L2msg: l2Message, - }, nil -} - -func MessageFromEspressoSovereignTx(tx espressoTypes.Bytes, jst *arbostypes.EspressoBlockJustification, payloadSignature []byte, header *arbostypes.L1IncomingMessageHeader) (arbostypes.L1IncomingMessage, error) { - var l2Message []byte - - l2Message = append(l2Message, L2MessageKind_EspressoSovereignTx) - jstBytes, err := GetEspressoJstBytes(jst) - if err != nil { - return arbostypes.L1IncomingMessage{}, err - } - - l2Message = append(l2Message, jstBytes...) - l2Message = append(l2Message, payloadSignature...) - l2Message = append(l2Message, tx...) - - return arbostypes.L1IncomingMessage{ - Header: header, - L2msg: l2Message, - }, nil -} - -func IsEspressoMsg(msg *arbostypes.L1IncomingMessage) bool { - return msg.Header.Kind == arbostypes.L1MessageType_L2Message && - (msg.L2msg[0] == L2MessageKind_EspressoSequencedTx || - msg.L2msg[0] == L2MessageKind_EspressoSovereignTx) -} - -func IsL2NonEspressoMsg(msg *arbostypes.L1IncomingMessage) bool { - return msg.Header.Kind == arbostypes.L1MessageType_L2Message && - msg.L2msg[0] != L2MessageKind_EspressoSequencedTx -} - -func IsL2Message(msg *arbostypes.L1IncomingMessage) bool { - return msg.Header.Kind == arbostypes.L1MessageType_L2Message -} - -func IsEspressoSovereignMsg(msg *arbostypes.L1IncomingMessage) bool { - return msg.Header.Kind == arbostypes.L1MessageType_L2Message && - msg.L2msg[0] == L2MessageKind_EspressoSovereignTx -} - func BuildHotShotPayload(msgs *[]arbostypes.L1IncomingMessage) (espressoTypes.Bytes, int) { payload := []byte{} msgCnt := 0 diff --git a/arbos/parse_l2_test.go b/arbos/parse_l2_test.go deleted file mode 100644 index 7dfd238930..0000000000 --- a/arbos/parse_l2_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package arbos - -import ( - "encoding/json" - "reflect" - "testing" - - tagged_base64 "github.com/EspressoSystems/espresso-sequencer-go/tagged-base64" - espressoTypes "github.com/EspressoSystems/espresso-sequencer-go/types" - "github.com/offchainlabs/nitro/arbos/arbostypes" -) - -func TestEspressoParsing(t *testing.T) { - expectTxes := []espressoTypes.Bytes{ - []byte{1, 2, 3}, - []byte{4}, - } - expectHeader := &arbostypes.L1IncomingMessageHeader{ - Kind: arbostypes.L1MessageType_L2Message, - BlockNumber: 1, - } - var mockProof = json.RawMessage(`{"NonExistence":{"ns_id":0}}`) - var mockChainConfig = &espressoTypes.ResolvableChainConfig0_1{ - ChainConfig: espressoTypes.EitherChainConfig0_1{ - Left: &espressoTypes.ChainConfig0_1{ - ChainId: *espressoTypes.NewU256().SetUint64(0x8a19).ToDecimal(), - MaxBlockSize: *espressoTypes.NewU256().SetUint64(10240).ToDecimal(), - BaseFee: *espressoTypes.NewU256().SetUint64(0).ToDecimal()}, - }, - } - mockCommitment, err := tagged_base64.New("payloadCommitment", []byte{1, 2, 3}) - Require(t, err) - root, err := tagged_base64.New("root", []byte{4, 5, 6}) - Require(t, err) - header := &espressoTypes.Header0_1{ - L1Head: 1, - ChainConfig: mockChainConfig, - Timestamp: 2, - Height: 3, - NsTable: &espressoTypes.NsTable{Bytes: []byte{1}}, - L1Finalized: &espressoTypes.L1BlockInfo{}, - PayloadCommitment: mockCommitment, - BuilderCommitment: mockCommitment, - BlockMerkleTreeRoot: root, - FeeMerkleTreeRoot: root, - FeeInfo: &espressoTypes.FeeInfo{}, - } - headerImpl := espressoTypes.HeaderImpl{Header: header} - expectJst := &arbostypes.EspressoBlockJustification{ - Header: &headerImpl, - Proof: &mockProof, - } - msg, err := MessageFromEspresso(expectHeader, expectTxes, expectJst) - Require(t, err) - - actualTxes, actualJst, err := ParseEspressoMsg(&msg) - Require(t, err) - - if !reflect.DeepEqual(actualTxes, expectTxes) { - Fail(t) - } - - if !reflect.DeepEqual(actualJst.Header, expectJst.Header) { - Fail(t) - } -} diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index 2675bd91e2..87a48ca6ee 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -380,19 +380,8 @@ func (s *ExecutionEngine) NextDelayedMessageNumber() (uint64, error) { return currentHeader.Nonce.Uint64(), nil } -func MessageFromTxes(header *arbostypes.L1IncomingMessageHeader, txes types.Transactions, txErrors []error, espressoSovereignSequencer bool) (*arbostypes.L1IncomingMessage, error) { +func MessageFromTxes(header *arbostypes.L1IncomingMessageHeader, txes types.Transactions, txErrors []error) (*arbostypes.L1IncomingMessage, error) { var l2Message []byte - // Set a special type if the Espresso Sovereign Sequencer is running. - if espressoSovereignSequencer { - l2Message = append(l2Message, arbos.L2MessageKind_EspressoSovereignTx) - // Set a block justification placeholder here. That would help us easily parse - // our messages from `ParseEspressoMessage`. - jstBytes, err := arbos.GetEspressoJstBytes(&arbostypes.EspressoBlockJustification{}) - if err != nil { - return nil, err - } - l2Message = append(l2Message, jstBytes...) - } if len(txes) == 1 && txErrors[0] == nil { txBytes, err := txes[0].MarshalBinary() @@ -473,7 +462,7 @@ func (s *ExecutionEngine) resequenceReorgedMessages(messages []*arbostypes.Messa } hooks := arbos.NoopSequencingHooks() hooks.DiscardInvalidTxsEarly = true - _, err = s.sequenceTransactionsWithBlockMutex(msg.Message.Header, txes, hooks, arbos.IsEspressoSovereignMsg(msg.Message)) + _, err = s.sequenceTransactionsWithBlockMutex(msg.Message.Header, txes, hooks) if err != nil { log.Error("failed to re-sequence old user message removed by reorg", "err", err) return @@ -514,7 +503,7 @@ func (s *ExecutionEngine) sequencerWrapper(sequencerFunc func() (*types.Block, e func (s *ExecutionEngine) SequenceTransactions(header *arbostypes.L1IncomingMessageHeader, txes types.Transactions, hooks *arbos.SequencingHooks, espressoSovereign bool) (*types.Block, error) { return s.sequencerWrapper(func() (*types.Block, error) { hooks.TxErrors = nil - return s.sequenceTransactionsWithBlockMutex(header, txes, hooks, espressoSovereign) + return s.sequenceTransactionsWithBlockMutex(header, txes, hooks) }) } @@ -556,7 +545,7 @@ func writeAndLog(pprof, trace *bytes.Buffer) { log.Info("Transactions sequencing took longer than 2 seconds, created pprof and trace files", "pprof", pprofFile, "traceFile", traceFile) } -func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes.L1IncomingMessageHeader, txes types.Transactions, hooks *arbos.SequencingHooks, espressoSovereign bool) (*types.Block, error) { +func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes.L1IncomingMessageHeader, txes types.Transactions, hooks *arbos.SequencingHooks) (*types.Block, error) { lastBlockHeader, err := s.getCurrentHeader() if err != nil { return nil, err @@ -604,7 +593,7 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes. return nil, nil } - msg, err := MessageFromTxes(header, txes, hooks.TxErrors, espressoSovereign) + msg, err := MessageFromTxes(header, txes, hooks.TxErrors) if err != nil { return nil, err } diff --git a/staker/block_challenge_backend.go b/staker/block_challenge_backend.go index 6c6e708ec1..0dd89865bd 100644 --- a/staker/block_challenge_backend.go +++ b/staker/block_challenge_backend.go @@ -13,7 +13,6 @@ import ( "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/log" "github.com/offchainlabs/nitro/arbutil" "github.com/offchainlabs/nitro/solgen/go/challengegen" "github.com/offchainlabs/nitro/validator" @@ -115,7 +114,6 @@ func (b *BlockChallengeBackend) FindGlobalStateFromMessageCount(count arbutil.Me return validator.GoGlobalState{}, err } if prevBatchMsgCount > count { - log.Info("prevBatchMsgCount should be smaller than count", "prevBatchMsgCount", prevBatchMsgCount, "count", count) return validator.GoGlobalState{}, errors.New("findBatchFromMessageCount returned bad batch") } } @@ -123,7 +121,6 @@ func (b *BlockChallengeBackend) FindGlobalStateFromMessageCount(count arbutil.Me if err != nil { return validator.GoGlobalState{}, err } - return validator.GoGlobalState{ BlockHash: res.BlockHash, SendRoot: res.SendRoot, diff --git a/staker/block_validator.go b/staker/block_validator.go index e5c09d3e00..e1b2c75b84 100644 --- a/staker/block_validator.go +++ b/staker/block_validator.go @@ -632,7 +632,8 @@ func (v *BlockValidator) createNextValidationEntry(ctx context.Context) (bool, e }) } entry, err := newValidationEntry( - pos, v.nextCreateStartGS, endGS, msg, v.nextCreateBatch, prevBatches, v.nextCreatePrevDelayed, chainConfig) + pos, v.nextCreateStartGS, endGS, msg, v.nextCreateBatch, prevBatches, v.nextCreatePrevDelayed, chainConfig, + ) if err != nil { return false, err } diff --git a/staker/challenge_test.go b/staker/challenge_test.go index 749571911d..33f1644c63 100644 --- a/staker/challenge_test.go +++ b/staker/challenge_test.go @@ -301,21 +301,3 @@ func TestChallengeToFailedTooFar(t *testing.T) { Require(t, machine.AddSequencerInboxMessage(10, []byte{0, 1, 2, 3})) runChallengeTest(t, machine, incorrectMachine, true, false, 11) } - -// This test is to check if the OpCode::ReadHotShotCommitment is working correctly. -// A bug found in Arbitrum and the simple fix will occur more errors. -// https://github.com/OffchainLabs/nitro/pull/2081 -// -// func TestReadHotShotOp(t *testing.T) { -// machine := createBaseMachine(t, "read-hotshot-10.wasm", []string{"global-state-wrapper.wasm"}) -// commitment := []byte{} -// for i := 0; i < 32; i++ { -// commitment = append(commitment, byte(i)) -// } -// Require(t, machine.AddHotShotCommitment(10, commitment)) -// err := machine.Step(context.Background(), 100) -// Require(t, err) -// if machine.IsErrored() || machine.IsRunning() { -// t.Fatal("fail to run the read_hotshot_op") -// } -// } diff --git a/staker/stateless_block_validator.go b/staker/stateless_block_validator.go index f19085131b..60306d712f 100644 --- a/staker/stateless_block_validator.go +++ b/staker/stateless_block_validator.go @@ -9,12 +9,7 @@ import ( "fmt" "testing" - "github.com/offchainlabs/nitro/execution" - "github.com/offchainlabs/nitro/util/rpcclient" - "github.com/offchainlabs/nitro/arbstate/daprovider" - "github.com/offchainlabs/nitro/arbutil" - "github.com/offchainlabs/nitro/validator" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" @@ -23,6 +18,10 @@ import ( "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbos/arbostypes" + "github.com/offchainlabs/nitro/arbutil" + "github.com/offchainlabs/nitro/execution" + "github.com/offchainlabs/nitro/util/rpcclient" + "github.com/offchainlabs/nitro/validator" "github.com/offchainlabs/nitro/validator/client/redis" validatorclient "github.com/offchainlabs/nitro/validator/client" @@ -436,7 +435,6 @@ func (v *StatelessBlockValidator) CreateReadyValidationEntry(ctx context.Context if err != nil { return nil, err } - if !found { return nil, fmt.Errorf("batch %d not found", startPos.BatchNumber) } diff --git a/system_tests/espresso_machine_test.go b/system_tests/espresso_machine_test.go deleted file mode 100644 index fa6b0756ea..0000000000 --- a/system_tests/espresso_machine_test.go +++ /dev/null @@ -1,74 +0,0 @@ -package arbtest - -import ( - "context" - "encoding/json" - "os" - "testing" - - "github.com/ethereum/go-ethereum/common" - "github.com/offchainlabs/nitro/validator" - "github.com/offchainlabs/nitro/validator/server_arb" - "github.com/offchainlabs/nitro/validator/server_common" - "github.com/offchainlabs/nitro/validator/server_jit" -) - -func TestEspressoArbMachine(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - locator, err := server_common.NewMachineLocator("") - if err != nil { - Fatal(t, err) - } - data, err := os.ReadFile("espresso-e2e/validation_input.json") - Require(t, err) - var input validator.ValidationInput - err = json.Unmarshal(data, &input) - Require(t, err) - - machine, err := server_arb.CreateTestArbMachine(ctx, locator, &input) - Require(t, err) - - err = machine.StepUntilHostIo(ctx) - Require(t, err) - - if machine.IsErrored() || !machine.IsRunning() { - panic("arb machine should be running") - } - - err = machine.Step(ctx, 900000000) - Require(t, err) - err = machine.Step(ctx, 900000000) - Require(t, err) - - if machine.IsRunning() { - panic("arb machine should finish all the steps") - } - if machine.IsErrored() { - panic("arb machine went wrong") - } -} - -func TestEspressoJitMachine(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - locator, err := server_common.NewMachineLocator("") - if err != nil { - Fatal(t, err) - } - data, err := os.ReadFile("espresso-e2e/validation_input.json") - Require(t, err) - var input validator.ValidationInput - err = json.Unmarshal(data, &input) - Require(t, err) - - config := &server_jit.DefaultJitSpawnerConfig - fetcher := func() *server_jit.JitSpawnerConfig { return config } - spawner, err := server_jit.NewJitSpawner(locator, fetcher, nil) - Require(t, err) - _, err = spawner.TestExecute(ctx, &input, common.Hash{}) - Require(t, err) - -} diff --git a/system_tests/seqfeed_test.go b/system_tests/seqfeed_test.go index 0b794a04b1..21f0755225 100644 --- a/system_tests/seqfeed_test.go +++ b/system_tests/seqfeed_test.go @@ -384,7 +384,6 @@ func testBlockHashComparison(t *testing.T, blockHash *common.Hash, mustMismatch &l1IncomingMsgHeader, types.Transactions{tx}, []error{nil}, - false, ) Require(t, err) diff --git a/validator/server_api/json.go b/validator/server_api/json.go index b792c36b21..6fe936e17d 100644 --- a/validator/server_api/json.go +++ b/validator/server_api/json.go @@ -10,7 +10,6 @@ import ( "fmt" "os" - espressoTypes "github.com/EspressoSystems/espresso-sequencer-go/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethdb" "github.com/offchainlabs/nitro/arbcompress" @@ -67,10 +66,6 @@ type InputJSON struct { StartState validator.GoGlobalState UserWasms map[ethdb.WasmTarget]map[common.Hash]string DebugChain bool - - BlockHeight uint64 - HotShotLiveness bool - HotShotCommitment espressoTypes.Commitment } func (i *InputJSON) WriteToFile() error { @@ -103,10 +98,6 @@ func ValidationInputToJson(entry *validator.ValidationInput) *InputJSON { PreimagesB64: jsonPreimagesMap, UserWasms: make(map[ethdb.WasmTarget]map[common.Hash]string), DebugChain: entry.DebugChain, - - HotShotCommitment: entry.HotShotCommitment, - HotShotLiveness: entry.HotShotLiveness, - BlockHeight: entry.BlockHeight, } for _, binfo := range entry.BatchInfo { encData := base64.StdEncoding.EncodeToString(binfo.Data) @@ -139,10 +130,6 @@ func ValidationInputFromJson(entry *InputJSON) (*validator.ValidationInput, erro Preimages: preimages, UserWasms: make(map[ethdb.WasmTarget]map[common.Hash][]byte), DebugChain: entry.DebugChain, - - HotShotCommitment: entry.HotShotCommitment, - HotShotLiveness: entry.HotShotLiveness, - BlockHeight: entry.BlockHeight, } delayed, err := base64.StdEncoding.DecodeString(entry.DelayedMsgB64) if err != nil { diff --git a/validator/server_arb/machine.go b/validator/server_arb/machine.go index c911286319..adca9695e2 100644 --- a/validator/server_arb/machine.go +++ b/validator/server_arb/machine.go @@ -242,46 +242,6 @@ func (m *ArbitratorMachine) StepUntilHostIo(ctx context.Context) error { return ctx.Err() } -func (m *ArbitratorMachine) StepUntilReadHotShot(ctx context.Context) error { - defer runtime.KeepAlive(m) - m.mutex.Lock() - defer m.mutex.Unlock() - if m.frozen { - return errors.New("machine frozen") - } - - conditionByte, cancel := manageConditionByte(ctx) - defer cancel() - - err := C.arbitrator_step_until_read_hotshot(m.ptr, conditionByte) - defer C.free(unsafe.Pointer(err)) - if err != nil { - return errors.New(C.GoString(err)) - } - - return ctx.Err() -} - -func (m *ArbitratorMachine) StepUntilIsHotShotLive(ctx context.Context) error { - defer runtime.KeepAlive(m) - m.mutex.Lock() - defer m.mutex.Unlock() - if m.frozen { - return errors.New("machine frozen") - } - - conditionByte, cancel := manageConditionByte(ctx) - defer cancel() - - err := C.arbitrator_step_until_is_hotshot_live(m.ptr, conditionByte) - defer C.free(unsafe.Pointer(err)) - if err != nil { - return errors.New(C.GoString(err)) - } - - return ctx.Err() -} - func (m *ArbitratorMachine) Hash() (hash common.Hash) { defer runtime.KeepAlive(m) m.mutex.Lock() @@ -352,49 +312,6 @@ func (m *ArbitratorMachine) DeserializeAndReplaceState(path string) error { } } -func (m *ArbitratorMachine) AddHotShotLiveness(height uint64, liveness bool) error { - defer runtime.KeepAlive(m) - m.mutex.Lock() - defer m.mutex.Unlock() - if m.frozen { - return errors.New("machine frozen") - } - - var livenessInt uint8 - if liveness { - livenessInt = 1 - } else { - livenessInt = 0 - } - status := C.arbitrator_add_hotshot_liveness(m.ptr, C.uint64_t(height), C.uint8_t(livenessInt)) - if status == 0 { - return nil - } - return errors.New("failed to add hotsho liveness") -} - -func (m *ArbitratorMachine) AddHotShotCommitment(height uint64, commitment []byte) error { - defer runtime.KeepAlive(m) - m.mutex.Lock() - defer m.mutex.Unlock() - if m.frozen { - return errors.New("machine frozen") - } - - cbyte := CreateCByteArray(commitment) - status := C.arbitrator_add_hotshot_commitment(m.ptr, C.uint64_t(height), cbyte) - DestroyCByteArray(cbyte) - if status == 0 { - return nil - } else if status == 1 { - return errors.New("failed to add hotshot commitment: try into failed") - } else if status == 3 { - return errors.New("failed to add hotshot commitment: len != 32") - } else { - return errors.New("failed to add hotshot commitment: unreachable") - } -} - func (m *ArbitratorMachine) AddSequencerInboxMessage(index uint64, data []byte) error { defer runtime.KeepAlive(m) m.mutex.Lock() diff --git a/validator/server_arb/nitro_machine.go b/validator/server_arb/nitro_machine.go index e4626d5232..2b2cb230b6 100644 --- a/validator/server_arb/nitro_machine.go +++ b/validator/server_arb/nitro_machine.go @@ -19,8 +19,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" - "github.com/offchainlabs/nitro/arbutil" - "github.com/offchainlabs/nitro/validator" "github.com/offchainlabs/nitro/validator/server_common" ) @@ -78,63 +76,3 @@ func createArbMachine(ctx context.Context, locator *server_common.MachineLocator result.hostIo.Freeze() return result, nil } - -func CreateTestArbMachine(ctx context.Context, locator *server_common.MachineLocator, entry *validator.ValidationInput) (*ArbitratorMachine, error) { - binPath := filepath.Join(locator.GetMachinePath(common.Hash{}), DefaultArbitratorMachineConfig.WavmBinaryPath) - cBinPath := C.CString(binPath) - defer C.free(unsafe.Pointer(cBinPath)) - log.Info("creating nitro machine", "binpath", binPath) - baseMachine := C.arbitrator_load_wavm_binary(cBinPath) - if baseMachine == nil { - return nil, errors.New("failed to load base machine") - } - mach := machineFromPointer(baseMachine) - resolver := func(ty arbutil.PreimageType, hash common.Hash) ([]byte, error) { - // Check if it's a known preimage - if preimage, ok := entry.Preimages[ty][hash]; ok { - return preimage, nil - } - return nil, errors.New("preimage not found") - } - if err := mach.SetPreimageResolver(resolver); err != nil { - return nil, err - } - err := mach.SetGlobalState(entry.StartState) - if err != nil { - log.Error("error while setting global state for proving", "err", err, "gsStart", entry.StartState) - return nil, fmt.Errorf("error while setting global state for proving: %w", err) - } - for _, batch := range entry.BatchInfo { - err = mach.AddSequencerInboxMessage(batch.Number, batch.Data) - if err != nil { - log.Error( - "error while trying to add sequencer msg for proving", - "err", err, "seq", entry.StartState.Batch, "blockNr", entry.Id, - ) - return nil, fmt.Errorf("error while trying to add sequencer msg for proving: %w", err) - } - } - if entry.HasDelayedMsg { - err = mach.AddDelayedInboxMessage(entry.DelayedMsgNr, entry.DelayedMsg) - if err != nil { - log.Error( - "error while trying to add delayed msg for proving", - "err", err, "seq", entry.DelayedMsgNr, "blockNr", entry.Id, - ) - return nil, fmt.Errorf("error while trying to add delayed msg for proving: %w", err) - } - } - err = mach.AddHotShotCommitment(entry.BlockHeight, entry.HotShotCommitment[:]) - if err != nil { - log.Error("error while setting hotshot commitment: %w", err) - return nil, fmt.Errorf("error while setting hotshot commitment: %w", err) - } - - err = mach.AddHotShotLiveness(entry.BlockHeight, entry.HotShotLiveness) - if err != nil { - log.Error("error while setting hotshot liveness: %w", err) - return nil, fmt.Errorf("error while setting hotshot liveness: %w", err) - } - - return mach, nil -} diff --git a/validator/server_arb/validator_spawner.go b/validator/server_arb/validator_spawner.go index c5bd2a2899..6f0d0cee1d 100644 --- a/validator/server_arb/validator_spawner.go +++ b/validator/server_arb/validator_spawner.go @@ -151,17 +151,6 @@ func (v *ArbitratorSpawner) loadEntryToMachine(ctx context.Context, entry *valid return fmt.Errorf("error while trying to add delayed msg for proving: %w", err) } } - err = mach.AddHotShotCommitment(entry.BlockHeight, entry.HotShotCommitment[:]) - if err != nil { - log.Error("error while setting hotshot commitment: %w", err) - return fmt.Errorf("error while setting hotshot commitment: %w", err) - } - - err = mach.AddHotShotLiveness(entry.BlockHeight, entry.HotShotLiveness) - if err != nil { - log.Error("error while setting hotshot liveness: %w", err) - return fmt.Errorf("error while setting hotshot liveness: %w", err) - } return nil } diff --git a/validator/server_jit/jit_machine.go b/validator/server_jit/jit_machine.go index b5df3f0f8c..06c451bda1 100644 --- a/validator/server_jit/jit_machine.go +++ b/validator/server_jit/jit_machine.go @@ -156,19 +156,6 @@ func (machine *JitMachine) prove( if err := writeExact(entry.StartState.SendRoot[:]); err != nil { return state, err } - if err := writeExact(entry.HotShotCommitment[:]); err != nil { - return state, err - } - if err := writeUint64(entry.BlockHeight); err != nil { - return state, err - } - var avail uint8 - if entry.HotShotLiveness { - avail = 1 - } - if err := writeUint8(avail); err != nil { - return state, err - } const successByte = 0x0 const failureByte = 0x1 diff --git a/validator/server_jit/spawner.go b/validator/server_jit/spawner.go index ec5d95becb..d77317d218 100644 --- a/validator/server_jit/spawner.go +++ b/validator/server_jit/spawner.go @@ -89,19 +89,6 @@ func (v *JitSpawner) execute( return state, err } -// Export this function for test -func (v *JitSpawner) TestExecute( - ctx context.Context, entry *validator.ValidationInput, moduleRoot common.Hash, -) (validator.GoGlobalState, error) { - machine, err := v.machineLoader.GetMachine(ctx, moduleRoot) - if err != nil { - return validator.GoGlobalState{}, fmt.Errorf("unabled to get WASM machine: %w", err) - } - - state, err := machine.prove(ctx, entry) - return state, err -} - func (s *JitSpawner) Name() string { if s.config().Cranelift { return "jit-cranelift" diff --git a/validator/validation_entry.go b/validator/validation_entry.go index f365d89049..4ec6919d3b 100644 --- a/validator/validation_entry.go +++ b/validator/validation_entry.go @@ -1,7 +1,6 @@ package validator import ( - espressoTypes "github.com/EspressoSystems/espresso-sequencer-go/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethdb" "github.com/offchainlabs/nitro/arbutil" @@ -22,9 +21,4 @@ type ValidationInput struct { DelayedMsg []byte StartState GoGlobalState DebugChain bool - - BlockHeight uint64 - // The validating hotshot commitment - HotShotCommitment espressoTypes.Commitment - HotShotLiveness bool } diff --git a/wavmio/higher.go b/wavmio/higher.go index c9ab5d2e82..0fb5516c1a 100644 --- a/wavmio/higher.go +++ b/wavmio/higher.go @@ -56,15 +56,6 @@ func ReadInboxMessage(msgNum uint64) []byte { }) } -func ReadHotShotCommitment(h uint64) (commitment [32]byte) { - readHotShotCommitment(h, unsafe.Pointer(&commitment)) - return commitment -} - -func IsHotShotLive(l1Height uint64) bool { - return isHotShotLive(l1Height) > 0 -} - func ReadDelayedInboxMessage(seqNum uint64) []byte { return readBuffer(func(offset uint32, buf unsafe.Pointer) uint32 { return readDelayedInboxMessage(seqNum, offset, buf) diff --git a/wavmio/raw.go b/wavmio/raw.go index 2977a04036..c09543f84f 100644 --- a/wavmio/raw.go +++ b/wavmio/raw.go @@ -28,9 +28,3 @@ func readDelayedInboxMessage(seqNum uint64, offset uint32, output unsafe.Pointer //go:wasmimport wavmio resolveTypedPreimage func resolveTypedPreimage(ty uint32, hash unsafe.Pointer, offset uint32, output unsafe.Pointer) uint32 - -//go:wasmimport wavmio readHotShotCommitment -func readHotShotCommitment(h uint64, output unsafe.Pointer) - -//go:wasmimport wavmio isHotShotLive -func isHotShotLive(l1Height uint64) uint32 diff --git a/wavmio/stub.go b/wavmio/stub.go index 4784a015a7..0c82506ff3 100644 --- a/wavmio/stub.go +++ b/wavmio/stub.go @@ -39,7 +39,6 @@ var ( delayedMsgs [][]byte delayedMsgFirstPos uint64 lastBlockHash common.Hash - hotShotCommitment [32]byte preimages map[common.Hash][]byte seqAdvanced uint64 ) @@ -119,15 +118,6 @@ func GetLastBlockHash() (hash common.Hash) { return lastBlockHash } -func ReadHotShotCommitment(h uint64) [32]byte { - return hotShotCommitment - -} - -func IsHotShotLive(l1Height uint64) bool { - return true -} - func ReadInboxMessage(msgNum uint64) []byte { if msgNum != seqMsgPos { panic(fmt.Sprintf("trying to read bad msg %d", msgNum))