Skip to content

Commit

Permalink
SDK support
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Mar 14, 2024
1 parent cc2728f commit 704ce1b
Show file tree
Hide file tree
Showing 25 changed files with 49 additions and 99 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ arbitrator/wasm-testsuite/target/
arbitrator/wasm-libraries/target/
arbitrator/tools/wasmer/target/
arbitrator/tools/wasm-tools/
arbitrator/tools/pricers/
arbitrator/tools/module_roots/
arbitrator/langs/rust/target/
arbitrator/langs/bf/target/
Expand Down
1 change: 1 addition & 0 deletions arbitrator/Cargo.lock

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

1 change: 1 addition & 0 deletions arbitrator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"arbutil",
"caller-env",
"prover",
"stylus",
"jit",
Expand Down
1 change: 1 addition & 0 deletions arbitrator/arbutil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
digest = "0.9.0"
eyre = "0.6.5"
fnv = "1.0.7"
hex = "0.4.3"
num-traits = "0.2.17"
siphasher = "0.3.10"
Expand Down
3 changes: 2 additions & 1 deletion arbitrator/arbutil/src/evm/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ impl<D: DataReader, H: RequestHandler<D>> EvmApi<D> for EvmApiRequestor<D, H> {
}

fn cache_bytes32(&mut self, key: Bytes32, value: Bytes32) -> u64 {
let cost = self.storage_cache.write_gas();
match self.storage_cache.entry(key) {
Entry::Occupied(mut key) => key.get_mut().value = value,
Entry::Vacant(slot) => drop(slot.insert(StorageWord::unknown(value))),
};
self.storage_cache.write_gas()
cost
}

fn flush_storage_cache(&mut self, clear: bool, gas_left: u64) -> Result<u64> {
Expand Down
30 changes: 19 additions & 11 deletions arbitrator/arbutil/src/evm/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// For license information, see https://github.com/nitro/blob/master/LICENSE

use crate::Bytes32;
use std::{
collections::HashMap,
ops::{Deref, DerefMut},
};
use fnv::FnvHashMap as HashMap;
use std::ops::{Deref, DerefMut};

/// Represents the EVM word at a given key.
#[derive(Debug)]
Expand Down Expand Up @@ -34,19 +32,29 @@ impl StorageWord {
#[derive(Default)]
pub struct StorageCache {
pub(crate) slots: HashMap<Bytes32, StorageWord>,
reads: usize,
writes: usize,
}

impl StorageCache {
pub const REQUIRED_ACCESS_GAS: u64 = crate::evm::COLD_SLOAD_GAS;
pub const REQUIRED_ACCESS_GAS: u64 = 10;

pub fn read_gas(&self) -> u64 {
//self.slots.len().ilog2() as u64
self.slots.len() as u64
pub fn read_gas(&mut self) -> u64 {
self.reads += 1;
match self.reads {
0..=32 => 0,
33..=128 => 2,
_ => 10,
}
}

pub fn write_gas(&self) -> u64 {
//self.slots.len().ilog2() as u64
self.slots.len() as u64
pub fn write_gas(&mut self) -> u64 {
self.writes += 1;
match self.writes {
0..=8 => 0,
9..=64 => 7,
_ => 10,
}
}
}

Expand Down
7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/create/Cargo.lock

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

1 change: 0 additions & 1 deletion arbitrator/stylus/tests/erc20/Cargo.lock

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

2 changes: 1 addition & 1 deletion arbitrator/stylus/tests/erc20/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023, Offchain Labs, Inc.
// Copyright 2023-2024, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

// Warning: this code is for testing only and has not been audited
Expand Down
7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/evm-data/Cargo.lock

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

7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/fallible/Cargo.lock

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

7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/keccak-100/Cargo.lock

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

7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/keccak/Cargo.lock

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

7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/log/Cargo.lock

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

7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/multicall/Cargo.lock

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

2 changes: 1 addition & 1 deletion arbitrator/stylus/tests/multicall/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023, Offchain Labs, Inc.
// Copyright 2023-2024, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

#![no_main]
Expand Down
7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/read-return-data/Cargo.lock

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

16 changes: 9 additions & 7 deletions arbitrator/stylus/tests/sdk-storage/Cargo.lock

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

10 changes: 4 additions & 6 deletions arbitrator/stylus/tests/sdk-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
stylus-sdk = { path = "../../../langs/rust/stylus-sdk" }
stylus-sdk = { path = "../../../langs/rust/stylus-sdk", default-features = false, features = [] }
#stylus-sdk = { path = "../../../langs/rust/stylus-sdk", default-features = false, features = ["storage-cache"] }
mini-alloc.path = "../../../langs/rust/mini-alloc"
hex = "0.4.3"
wee_alloc = "0.4.5"

Expand All @@ -16,10 +18,6 @@ panic = "abort"

# uncomment to optimize for size
# opt-level = "z"

# TODO: move to .cargo/ and add nightly to build process and CI
[unstable]
build-std = ["std", "panic_abort"]
build-std-features = ["panic_immediate_abort"]
opt-level = "s"

[workspace]
5 changes: 3 additions & 2 deletions arbitrator/stylus/tests/sdk-storage/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023, Offchain Labs, Inc.
// Copyright 2023-2024, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

#![no_main]
Expand All @@ -7,9 +7,10 @@ use stylus_sdk::{
alloy_primitives::{Address, Signed, Uint, B256, I32, U16, U256, U64, U8},
prelude::*,
};
use mini_alloc::MiniAlloc;

#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
static ALLOC: MiniAlloc = MiniAlloc::INIT;

sol_storage! {
pub struct Contract {
Expand Down
7 changes: 0 additions & 7 deletions arbitrator/stylus/tests/storage/Cargo.lock

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

Loading

0 comments on commit 704ce1b

Please sign in to comment.