forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GuestPtr, speed up read/write, docstrings, debug prints, wrap macro, …
…other tweaks
- Loading branch information
1 parent
a186fc3
commit 5170ae3
Showing
45 changed files
with
1,222 additions
and
942 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
arbitrator/callerenv/Cargo.toml → arbitrator/caller-env/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
[package] | ||
name = "callerenv" | ||
name = "caller-env" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
num_enum = { version = "0.7.2", default-features = false } | ||
rand_pcg = { version = "0.3.1", default-features = false } | ||
rand = { version = "0.8.4", default-features = false } | ||
wasmer = { path = "../tools/wasmer/lib/api", optional = true } | ||
|
||
[features] | ||
static_caller = [] | ||
wasmer_traits = ["dep:wasmer"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2024, Offchain Labs, Inc. | ||
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE | ||
|
||
use core::ops::{Add, AddAssign, Deref, DerefMut}; | ||
|
||
/// Represents a pointer to a Guest WASM's memory. | ||
#[derive(Clone, Copy, Eq, PartialEq)] | ||
#[repr(transparent)] | ||
pub struct GuestPtr(pub u32); | ||
|
||
impl Add<u32> for GuestPtr { | ||
type Output = Self; | ||
|
||
fn add(self, rhs: u32) -> Self::Output { | ||
Self(self.0 + rhs) | ||
} | ||
} | ||
|
||
impl AddAssign<u32> for GuestPtr { | ||
fn add_assign(&mut self, rhs: u32) { | ||
*self = *self + rhs; | ||
} | ||
} | ||
|
||
impl From<GuestPtr> for u32 { | ||
fn from(value: GuestPtr) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl From<GuestPtr> for u64 { | ||
fn from(value: GuestPtr) -> Self { | ||
value.0.into() | ||
} | ||
} | ||
|
||
impl Deref for GuestPtr { | ||
type Target = u32; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl DerefMut for GuestPtr { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2021-2024, Offchain Labs, Inc. | ||
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE | ||
|
||
#![no_std] | ||
|
||
extern crate alloc; | ||
|
||
use alloc::vec::Vec; | ||
use rand_pcg::Pcg32; | ||
|
||
pub use brotli::BrotliStatus; | ||
pub use guest_ptr::GuestPtr; | ||
pub use wasip1_stub::Errno; | ||
|
||
#[cfg(feature = "static_caller")] | ||
pub mod static_caller; | ||
|
||
#[cfg(feature = "wasmer_traits")] | ||
pub mod wasmer_traits; | ||
|
||
pub mod brotli; | ||
mod guest_ptr; | ||
pub mod wasip1_stub; | ||
|
||
/// Initializes a deterministic, psuedo-random number generator with a fixed seed. | ||
pub fn create_pcg() -> Pcg32 { | ||
const PCG_INIT_STATE: u64 = 0xcafef00dd15ea5e5; | ||
const PCG_INIT_STREAM: u64 = 0xa02bdbf7bb3c0a7; | ||
Pcg32::new(PCG_INIT_STATE, PCG_INIT_STREAM) | ||
} | ||
|
||
/// Access Guest memory. | ||
pub trait MemAccess { | ||
fn read_u8(&self, ptr: GuestPtr) -> u8; | ||
|
||
fn read_u16(&self, ptr: GuestPtr) -> u16; | ||
|
||
fn read_u32(&self, ptr: GuestPtr) -> u32; | ||
|
||
fn read_u64(&self, ptr: GuestPtr) -> u64; | ||
|
||
fn write_u8(&mut self, ptr: GuestPtr, x: u8); | ||
|
||
fn write_u16(&mut self, ptr: GuestPtr, x: u16); | ||
|
||
fn write_u32(&mut self, ptr: GuestPtr, x: u32); | ||
|
||
fn write_u64(&mut self, ptr: GuestPtr, x: u64); | ||
|
||
fn read_slice(&self, ptr: GuestPtr, len: usize) -> Vec<u8>; | ||
|
||
fn read_fixed<const N: usize>(&self, ptr: GuestPtr) -> [u8; N]; | ||
|
||
fn write_slice(&mut self, ptr: GuestPtr, data: &[u8]); | ||
} | ||
|
||
/// Update the Host environment. | ||
pub trait ExecEnv { | ||
fn advance_time(&mut self, ns: u64); | ||
|
||
fn get_time(&self) -> u64; | ||
|
||
fn next_rand_u32(&mut self) -> u32; | ||
|
||
fn print_string(&mut self, message: &[u8]); | ||
} |
Oops, something went wrong.