Skip to content

Commit

Permalink
Merge branch 'master' into Test_flatCallTracer
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi authored Oct 29, 2024
2 parents c0cbb1b + aa6d69a commit 621140f
Show file tree
Hide file tree
Showing 99 changed files with 3,597 additions and 1,660 deletions.
36 changes: 36 additions & 0 deletions .github/buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 0.2

phases:
pre_build:
commands:
- git submodule update --init
- echo Logging in to Dockerhub....
- docker login --username $DOCKERHUB_USERNAME --password $DOCKERHUB_PASSWORD
- aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $REPOSITORY_URI
- COMMIT_HASH=$(git rev-parse --short=7 HEAD || echo "latest")
- VERSION_TAG=$(git tag --points-at HEAD | sed '/-/!s/$/_/' | sort -rV | sed 's/_$//' | head -n 1 | grep ^ || git show -s --pretty=%D | sed 's/, /\n/g' | grep -v '^origin/' |grep -v '^grafted\|HEAD\|master\|main$' || echo "dev")
- NITRO_VERSION=${VERSION_TAG}-${COMMIT_HASH}
- IMAGE_TAG=${NITRO_VERSION}
- NITRO_DATETIME=$(git show -s --date=iso-strict --format=%cd)
- NITRO_MODIFIED="false"
- echo ${NITRO_VERSION} > ./.nitro-tag.txt
build:
commands:
- echo Build started on `date`
- echo Building the Docker image ${NITRO_VERSION}...
- DOCKER_BUILDKIT=1 docker build . -t nitro-node-slim --target nitro-node-slim --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED
- DOCKER_BUILDKIT=1 docker build . -t nitro-node --target nitro-node --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED
- DOCKER_BUILDKIT=1 docker build . -t nitro-node-dev --target nitro-node-dev --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED
- DOCKER_BUILDKIT=1 docker build . -t nitro-node-validator --target nitro-node-validator --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED
- docker tag nitro-node:latest $REPOSITORY_URI:$IMAGE_TAG-$ARCH_TAG
- docker tag nitro-node-slim:latest $REPOSITORY_URI:$IMAGE_TAG-slim-$ARCH_TAG
- docker tag nitro-node-dev:latest $REPOSITORY_URI:$IMAGE_TAG-dev-$ARCH_TAG
- docker tag nitro-node-validator:latest $REPOSITORY_URI:$IMAGE_TAG-validator-$ARCH_TAG
post_build:
commands:
- echo Build completed on `date`
- echo pushing to repo
- docker push $REPOSITORY_URI:$IMAGE_TAG-$ARCH_TAG
- docker push $REPOSITORY_URI:$IMAGE_TAG-slim-$ARCH_TAG
- docker push $REPOSITORY_URI:$IMAGE_TAG-dev-$ARCH_TAG
- docker push $REPOSITORY_URI:$IMAGE_TAG-validator-$ARCH_TAG
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ jobs:
run: |
echo "Running redis tests" >> full.log
TEST_REDIS=redis://localhost:6379/0 gotestsum --format short-verbose -- -p 1 -run TestRedis ./arbnode/... ./system_tests/... -coverprofile=coverage-redis.txt -covermode=atomic -coverpkg=./...
- name: create block input json file
if: matrix.test-mode == 'defaults'
run: |
gotestsum --format short-verbose -- -run TestProgramStorage$ ./system_tests/... --count 1 --recordBlockInputs.WithBaseDir="${{ github.workspace }}/target" --recordBlockInputs.WithTimestampDirEnabled=false --recordBlockInputs.WithBlockIdInFileNameEnabled=false
- name: run arbitrator prover on block input json
if: matrix.test-mode == 'defaults'
run: |
make build-prover-bin
target/bin/prover target/machines/latest/machine.wavm.br -b --json-inputs="${{ github.workspace }}/target/TestProgramStorage/block_inputs.json"
- name: run jit prover on block input json
if: matrix.test-mode == 'defaults'
run: |
make build-jit
if [ -n "$(target/bin/jit --binary target/machines/latest/replay.wasm --cranelift --json-inputs='${{ github.workspace }}/target/TestProgramStorage/block_inputs.json')" ]; then
echo "Error: Command produced output."
exit 1
fi
- name: run challenge tests
if: matrix.test-mode == 'challenge'
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ stylus_test_hostio-test_src = $(call get_stylus_test_rust,hostio-test)
stylus_test_wasms = $(stylus_test_keccak_wasm) $(stylus_test_keccak-100_wasm) $(stylus_test_fallible_wasm) $(stylus_test_storage_wasm) $(stylus_test_multicall_wasm) $(stylus_test_log_wasm) $(stylus_test_create_wasm) $(stylus_test_math_wasm) $(stylus_test_sdk-storage_wasm) $(stylus_test_erc20_wasm) $(stylus_test_read-return-data_wasm) $(stylus_test_evm-data_wasm) $(stylus_test_hostio-test_wasm) $(stylus_test_bfs:.b=.wasm)
stylus_benchmarks = $(wildcard $(stylus_dir)/*.toml $(stylus_dir)/src/*.rs) $(stylus_test_wasms)

CBROTLI_WASM_BUILD_ARGS ?=-d

# user targets

.PHONY: push
Expand Down Expand Up @@ -579,9 +581,9 @@ contracts/test/prover/proofs/%.json: $(arbitrator_cases)/%.wasm $(prover_bin)
@touch $@

.make/cbrotli-wasm: $(DEP_PREDICATE) $(ORDER_ONLY_PREDICATE) .make
test -f target/lib-wasm/libbrotlicommon-static.a || ./scripts/build-brotli.sh -w -d
test -f target/lib-wasm/libbrotlienc-static.a || ./scripts/build-brotli.sh -w -d
test -f target/lib-wasm/libbrotlidec-static.a || ./scripts/build-brotli.sh -w -d
test -f target/lib-wasm/libbrotlicommon-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS)
test -f target/lib-wasm/libbrotlienc-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS)
test -f target/lib-wasm/libbrotlidec-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS)
@touch $@

.make/wasm-lib: $(DEP_PREDICATE) arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/softfloat.a $(ORDER_ONLY_PREDICATE) .make
Expand Down
128 changes: 106 additions & 22 deletions arbitrator/arbutil/src/evm/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,103 @@ impl DataReader for VecReader {
}
}

macro_rules! derive_math {
($t:ident) => {
impl std::ops::Add for $t {
type Output = Self;

fn add(self, rhs: Self) -> Self {
Self(self.0 + rhs.0)
}
}

impl std::ops::AddAssign for $t {
fn add_assign(&mut self, rhs: Self) {
self.0 += rhs.0;
}
}

impl std::ops::Sub for $t {
type Output = Self;

fn sub(self, rhs: Self) -> Self {
Self(self.0 - rhs.0)
}
}

impl std::ops::SubAssign for $t {
fn sub_assign(&mut self, rhs: Self) {
self.0 -= rhs.0;
}
}

impl std::ops::Mul<u64> for $t {
type Output = Self;

fn mul(self, rhs: u64) -> Self {
Self(self.0 * rhs)
}
}

impl std::ops::Mul<$t> for u64 {
type Output = $t;

fn mul(self, rhs: $t) -> $t {
$t(self * rhs.0)
}
}

impl $t {
/// Equivalent to the Add trait, but const.
pub const fn add(self, rhs: Self) -> Self {
Self(self.0 + rhs.0)
}

/// Equivalent to the Sub trait, but const.
pub const fn sub(self, rhs: Self) -> Self {
Self(self.0 - rhs.0)
}

pub const fn saturating_add(self, rhs: Self) -> Self {
Self(self.0.saturating_add(rhs.0))
}

pub const fn saturating_sub(self, rhs: Self) -> Self {
Self(self.0.saturating_sub(rhs.0))
}

pub fn to_be_bytes(self) -> [u8; 8] {
self.0.to_be_bytes()
}
}
};
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
#[must_use]
pub struct Gas(pub u64);

derive_math!(Gas);

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
#[must_use]
pub struct Ink(pub u64);

derive_math!(Ink);

pub trait EvmApi<D: DataReader>: Send + 'static {
/// Reads the 32-byte value in the EVM state trie at offset `key`.
/// Returns the value and the access cost in gas.
/// Analogous to `vm.SLOAD`.
fn get_bytes32(&mut self, key: Bytes32, evm_api_gas_to_use: u64) -> (Bytes32, u64);
fn get_bytes32(&mut self, key: Bytes32, evm_api_gas_to_use: Gas) -> (Bytes32, Gas);

/// Stores the given value at the given key in Stylus VM's cache of the EVM state trie.
/// Note that the actual values only get written after calls to `set_trie_slots`.
fn cache_bytes32(&mut self, key: Bytes32, value: Bytes32) -> u64;
fn cache_bytes32(&mut self, key: Bytes32, value: Bytes32) -> Gas;

/// Persists any dirty values in the storage cache to the EVM state trie, dropping the cache entirely if requested.
/// Analogous to repeated invocations of `vm.SSTORE`.
fn flush_storage_cache(&mut self, clear: bool, gas_left: u64) -> Result<u64>;
fn flush_storage_cache(&mut self, clear: bool, gas_left: Gas) -> Result<Gas>;

/// Reads the 32-byte value in the EVM's transient state trie at offset `key`.
/// Analogous to `vm.TLOAD`.
Expand All @@ -102,10 +186,10 @@ pub trait EvmApi<D: DataReader>: Send + 'static {
&mut self,
contract: Bytes20,
calldata: &[u8],
gas_left: u64,
gas_req: u64,
gas_left: Gas,
gas_req: Gas,
value: Bytes32,
) -> (u32, u64, UserOutcomeKind);
) -> (u32, Gas, UserOutcomeKind);

/// Delegate-calls the contract at the given address.
/// Returns the EVM return data's length, the gas cost, and whether the call succeeded.
Expand All @@ -114,9 +198,9 @@ pub trait EvmApi<D: DataReader>: Send + 'static {
&mut self,
contract: Bytes20,
calldata: &[u8],
gas_left: u64,
gas_req: u64,
) -> (u32, u64, UserOutcomeKind);
gas_left: Gas,
gas_req: Gas,
) -> (u32, Gas, UserOutcomeKind);

/// Static-calls the contract at the given address.
/// Returns the EVM return data's length, the gas cost, and whether the call succeeded.
Expand All @@ -125,9 +209,9 @@ pub trait EvmApi<D: DataReader>: Send + 'static {
&mut self,
contract: Bytes20,
calldata: &[u8],
gas_left: u64,
gas_req: u64,
) -> (u32, u64, UserOutcomeKind);
gas_left: Gas,
gas_req: Gas,
) -> (u32, Gas, UserOutcomeKind);

/// Deploys a new contract using the init code provided.
/// Returns the new contract's address on success, or the error reason on failure.
Expand All @@ -137,8 +221,8 @@ pub trait EvmApi<D: DataReader>: Send + 'static {
&mut self,
code: Vec<u8>,
endowment: Bytes32,
gas: u64,
) -> (eyre::Result<Bytes20>, u32, u64);
gas: Gas,
) -> (eyre::Result<Bytes20>, u32, Gas);

/// Deploys a new contract using the init code provided, with an address determined in part by the `salt`.
/// Returns the new contract's address on success, or the error reason on failure.
Expand All @@ -149,8 +233,8 @@ pub trait EvmApi<D: DataReader>: Send + 'static {
code: Vec<u8>,
endowment: Bytes32,
salt: Bytes32,
gas: u64,
) -> (eyre::Result<Bytes20>, u32, u64);
gas: Gas,
) -> (eyre::Result<Bytes20>, u32, Gas);

/// Returns the EVM return data.
/// Analogous to `vm.RETURNDATACOPY`.
Expand All @@ -164,29 +248,29 @@ pub trait EvmApi<D: DataReader>: Send + 'static {
/// Gets the balance of the given account.
/// Returns the balance and the access cost in gas.
/// Analogous to `vm.BALANCE`.
fn account_balance(&mut self, address: Bytes20) -> (Bytes32, u64);
fn account_balance(&mut self, address: Bytes20) -> (Bytes32, Gas);

/// Returns the code and the access cost in gas.
/// Analogous to `vm.EXTCODECOPY`.
fn account_code(&mut self, address: Bytes20, gas_left: u64) -> (D, u64);
fn account_code(&mut self, address: Bytes20, gas_left: Gas) -> (D, Gas);

/// Gets the hash of the given address's code.
/// Returns the hash and the access cost in gas.
/// Analogous to `vm.EXTCODEHASH`.
fn account_codehash(&mut self, address: Bytes20) -> (Bytes32, u64);
fn account_codehash(&mut self, address: Bytes20) -> (Bytes32, Gas);

/// Determines the cost in gas of allocating additional wasm pages.
/// Note: has the side effect of updating Geth's memory usage tracker.
/// Not analogous to any EVM opcode.
fn add_pages(&mut self, pages: u16) -> u64;
fn add_pages(&mut self, pages: u16) -> Gas;

/// Captures tracing information for hostio invocations during native execution.
fn capture_hostio(
&mut self,
name: &str,
args: &[u8],
outs: &[u8],
start_ink: u64,
end_ink: u64,
start_ink: Ink,
end_ink: Ink,
);
}
49 changes: 25 additions & 24 deletions arbitrator/arbutil/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,78 @@
// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

use crate::{Bytes20, Bytes32};
use api::Gas;

pub mod api;
pub mod req;
pub mod storage;
pub mod user;

// params.SstoreSentryGasEIP2200
pub const SSTORE_SENTRY_GAS: u64 = 2300;
pub const SSTORE_SENTRY_GAS: Gas = Gas(2300);

// params.ColdAccountAccessCostEIP2929
pub const COLD_ACCOUNT_GAS: u64 = 2600;
pub const COLD_ACCOUNT_GAS: Gas = Gas(2600);

// params.ColdSloadCostEIP2929
pub const COLD_SLOAD_GAS: u64 = 2100;
pub const COLD_SLOAD_GAS: Gas = Gas(2100);

// params.WarmStorageReadCostEIP2929
pub const WARM_SLOAD_GAS: u64 = 100;
pub const WARM_SLOAD_GAS: Gas = Gas(100);

// params.WarmStorageReadCostEIP2929 (see enable1153 in jump_table.go)
pub const TLOAD_GAS: u64 = WARM_SLOAD_GAS;
pub const TSTORE_GAS: u64 = WARM_SLOAD_GAS;
pub const TLOAD_GAS: Gas = WARM_SLOAD_GAS;
pub const TSTORE_GAS: Gas = WARM_SLOAD_GAS;

// params.LogGas and params.LogDataGas
pub const LOG_TOPIC_GAS: u64 = 375;
pub const LOG_DATA_GAS: u64 = 8;
pub const LOG_TOPIC_GAS: Gas = Gas(375);
pub const LOG_DATA_GAS: Gas = Gas(8);

// params.CopyGas
pub const COPY_WORD_GAS: u64 = 3;
pub const COPY_WORD_GAS: Gas = Gas(3);

// params.Keccak256Gas
pub const KECCAK_256_GAS: u64 = 30;
pub const KECCAK_WORD_GAS: u64 = 6;
pub const KECCAK_256_GAS: Gas = Gas(30);
pub const KECCAK_WORD_GAS: Gas = Gas(6);

// vm.GasQuickStep (see gas.go)
pub const GAS_QUICK_STEP: u64 = 2;
pub const GAS_QUICK_STEP: Gas = Gas(2);

// vm.GasQuickStep (see jump_table.go)
pub const ADDRESS_GAS: u64 = GAS_QUICK_STEP;
pub const ADDRESS_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see eips.go)
pub const BASEFEE_GAS: u64 = GAS_QUICK_STEP;
pub const BASEFEE_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see eips.go)
pub const CHAINID_GAS: u64 = GAS_QUICK_STEP;
pub const CHAINID_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const COINBASE_GAS: u64 = GAS_QUICK_STEP;
pub const COINBASE_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const GASLIMIT_GAS: u64 = GAS_QUICK_STEP;
pub const GASLIMIT_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const NUMBER_GAS: u64 = GAS_QUICK_STEP;
pub const NUMBER_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const TIMESTAMP_GAS: u64 = GAS_QUICK_STEP;
pub const TIMESTAMP_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const GASLEFT_GAS: u64 = GAS_QUICK_STEP;
pub const GASLEFT_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const CALLER_GAS: u64 = GAS_QUICK_STEP;
pub const CALLER_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const CALLVALUE_GAS: u64 = GAS_QUICK_STEP;
pub const CALLVALUE_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const GASPRICE_GAS: u64 = GAS_QUICK_STEP;
pub const GASPRICE_GAS: Gas = GAS_QUICK_STEP;

// vm.GasQuickStep (see jump_table.go)
pub const ORIGIN_GAS: u64 = GAS_QUICK_STEP;
pub const ORIGIN_GAS: Gas = GAS_QUICK_STEP;

pub const ARBOS_VERSION_STYLUS_CHARGING_FIXES: u64 = 32;

Expand Down
Loading

0 comments on commit 621140f

Please sign in to comment.