Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the legacy code and fix the batch poster #318

Merged
merged 4 commits into from
Nov 19, 2024
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 2 additions & 40 deletions arbitrator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions arbitrator/jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 0 additions & 8 deletions arbitrator/jit/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ pub fn create(opts: &Opts, env: WasmEnv) -> (Instance, FunctionEnv<WasmEnv>, 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),
Expand Down Expand Up @@ -190,8 +188,6 @@ pub type WasmEnvMut<'a> = FunctionEnvMut<'a, WasmEnv>;
pub type Inbox = BTreeMap<u64, Vec<u8>>;
pub type Preimages = BTreeMap<PreimageType, BTreeMap<Bytes32, Vec<u8>>>;
pub type ModuleAsm = Arc<[u8]>;
pub type HotShotCommitmentMap = BTreeMap<u64, [u8; 32]>;
pub type HotShotLivenessMap = BTreeMap<u64, bool>;

#[derive(Default)]
pub struct WasmEnv {
Expand All @@ -209,10 +205,6 @@ pub struct WasmEnv {
pub module_asms: HashMap<Bytes32, ModuleAsm>,
/// 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
Expand Down
51 changes: 0 additions & 51 deletions arbitrator/jit/src/wavmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32, Escape> {
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,
Expand Down Expand Up @@ -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)?;
Expand Down
15 changes: 0 additions & 15 deletions arbitrator/prover/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ pub enum Hostio {
WavmReadSha256Preimage,
WavmReadEthVersionedHashPreimage,
WavmReadInboxMessage,
WavmReadHotShotCommitment,
WavmIsHotShotLive,
WavmReadDelayedInboxMessage,
WavmHaltAndSetFinished,
WavmLinkModule,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
82 changes: 0 additions & 82 deletions arbitrator/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading