Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into type2_merge_linda
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed Nov 7, 2024
2 parents 8db31fe + 3b1019c commit f0bb4f0
Show file tree
Hide file tree
Showing 54 changed files with 94,933 additions and 356 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
--- # Proof generation benchmarking workflow

name: Benchmark proving

on:
schedule:
- cron: "0 4 * * *"
workflow_dispatch:
branches:
- "**"

env:
BENCHMARK_WITNESS: artifacts/witness_b1000_b1019.json

jobs:
benchmark_proving:
name: Benchmark proving for representative blocks
runs-on: zero-reg
timeout-minutes: 300
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Build the project
run: |
RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld' cargo build --release
sudo sysctl kernel.perf_event_paranoid=0
- name: Download previous results
uses: dawidd6/action-download-artifact@v6
with:
workflow: benchmark.yml
workflow_conclusion: success
name: proving_benchmark
path: ./
if_no_artifact_found: ignore

- name: Run the script
run: |
echo "Benchmarking proving with $BENCHMARK_WITNESS"
./scripts/benchmark_input.sh $BENCHMARK_WITNESS | tee benchmark_output.log
MEASURED_PROVING_TIME_SEC=`cat benchmark_output.log | grep 'Proving duration:' | tail -1 | awk '{ print $3}'`
PERF_TIME=`cat output.log | grep "seconds time elapsed" | tail -1 | awk '{ print ($1)}'`
PERF_USER_TIME=`cat output.log | grep "seconds user" | tail -1 | awk '{ print ($1)}'`
PERF_SYS_TIME=`cat output.log | grep "seconds sys" | tail -1 | awk '{ print ($1)}'`
echo "RUN_ID=${{ github.run_id }} MEASURED_PROVING_TIME_SEC=$MEASURED_PROVING_TIME_SEC \
PERF_TIME=$PERF_TIME PERF_USER_TIME=$PERF_USER_TIME \
PERF_SYS_TIME=$PERF_SYS_TIME FILE=$BENCHMARK_WITNESS"
printf '%12s %-12s %-24s %-20s %-20s %-20s %-s\n' \
`date --utc +%y-%m-%d-%H:%M:%S` ${{ github.run_id }} \
$MEASURED_PROVING_TIME_SEC $PERF_TIME $PERF_USER_TIME \
$PERF_SYS_TIME $BENCHMARK_WITNESS >> proving_benchmark_results.txt
- name: Upload new results
uses: actions/upload-artifact@v4
with:
name: proving_benchmark
path: |
./proving_benchmark_results.txt
./output.log
retention-days: 90
overwrite: true
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ jobs:
CARGO_INCREMENTAL: 1
RUST_BACKTRACE: 1

run_ignored_tests:
name: Slow evm_arithmetization tests in release mode
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout sources
uses: actions/checkout@v4

- uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Set up rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Run specific ignored tests in release mode
run: |
cargo test --release \
--test empty_tables --test erc721 --test two_to_one_block -- --ignored
test_zero_bin:
name: Test zero_bin
runs-on: ubuntu-latest
Expand Down Expand Up @@ -173,4 +193,4 @@ jobs:
uses: actions/checkout@v4

- name: Run the script
run: ./scripts/prove_stdio.sh artifacts/witness_b3_b6.json
run: ./scripts/prove_stdio.sh artifacts/witness_b3_b6.json "" use_test_config
2 changes: 1 addition & 1 deletion .github/workflows/yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
yamllint
--format github
-d "{extends: default, rules: {line-length: {max: 120}, truthy: {check-keys: false}}}"
.github
.github scripts
8 changes: 3 additions & 5 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ bytes = "1.6.0"
ciborium = "0.2.2"
ciborium-io = "0.2.2"
clap = { version = "4.5.7", features = ["derive", "env"] }
compat = { path = "compat" }
alloy-compat = "0.1.0"
copyvec = "0.2.0"
criterion = "0.5.1"
dotenvy = "0.15.7"
either = { version = "1.12.0", features = ["serde"] }
Expand All @@ -70,7 +71,8 @@ num-bigint = "0.4.5"
num-traits = "0.2.19"
nunny = "0.2.1"
once_cell = "1.19.0"
paladin-core = "0.4.3"
# TODO: update when paladin is released to 0.4.4 with abort signal support
paladin-core = { git = "https://github.com/0xPolygonZero/paladin.git", branch = "main" }
parking_lot = "0.12.3"
pest = "2.7.10"
pest_derive = "2.7.10"
Expand Down Expand Up @@ -103,6 +105,7 @@ url = "2.5.2"
winnow = "0.6.13"

# local dependencies
compat = { path = "compat" }
evm_arithmetization = { path = "evm_arithmetization", version = "0.4.0", default-features = false }
mpt_trie = { path = "mpt_trie", version = "0.4.1" }
smt_trie = { path = "smt_trie", version = "0.1.1" }
Expand Down
91,403 changes: 91,403 additions & 0 deletions artifacts/witness_b1000_b1019.json

Large diffs are not rendered by default.

2,958 changes: 2,958 additions & 0 deletions artifacts/witness_b1033.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions evm_arithmetization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ keywords.workspace = true

[dependencies]
alloy.workspace = true
alloy-compat = "0.1.0"
alloy-compat.workspace = true
anyhow.workspace = true
bitflags.workspace = true
bitvec.workspace = true
bytes.workspace = true
ciborium.workspace = true
ciborium-io.workspace = true
copyvec = "0.2.0"
copyvec.workspace = true
either.workspace = true
env_logger.workspace = true
ethereum-types.workspace = true
Expand All @@ -37,7 +37,7 @@ log.workspace = true
mpt_trie.workspace = true
num.workspace = true
num-bigint.workspace = true
nunny = "0.2.1"
nunny.workspace = true
once_cell.workspace = true
pest.workspace = true
pest_derive.workspace = true
Expand All @@ -61,7 +61,7 @@ tiny-keccak.workspace = true
tokio.workspace = true
tower-lsp = "0.20.0"
tracing.workspace = true
u4 = "0.1.0"
u4.workspace = true
url.workspace = true
winnow.workspace = true
zk_evm_common.workspace = true
Expand Down
25 changes: 11 additions & 14 deletions evm_arithmetization/benches/fibonacci_25m_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use evm_arithmetization::testing_utils::{
beacon_roots_account_nibbles, beacon_roots_contract_from_storage,
preinitialized_state_and_storage_tries, update_beacon_roots_account_storage,
};
use evm_arithmetization::world::world::StateWorld;
use evm_arithmetization::world::StateWorld;
use evm_arithmetization::{Node, EMPTY_CONSOLIDATED_BLOCKHASH};
use hex_literal::hex;
use keccak_hash::keccak;
Expand All @@ -38,7 +38,7 @@ use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::field::types::Field;
#[cfg(feature = "cdk_erigon")]
use plonky2::field::types::PrimeField64;
use smt_trie::code::hash_bytecode_u256;
use smt_trie::code::hash_bytecode_h256;
#[cfg(feature = "cdk_erigon")]
use smt_trie::keys::{key_balance, key_code_length};
use smt_trie::utils::hashout2u;
Expand Down Expand Up @@ -88,7 +88,7 @@ fn prepare_setup() -> anyhow::Result<GenerationInputs<F>> {
];

let code_hash = if cfg!(feature = "cdk_erigon") {
CodeHashType::Uint(hash_bytecode_u256(code.to_vec()))
CodeHashType::Uint(hash_bytecode_h256(code.to_vec()))
} else {
CodeHashType::Hash(keccak(code))
};
Expand All @@ -99,7 +99,7 @@ fn prepare_setup() -> anyhow::Result<GenerationInputs<F>> {
Either::Right(SmtAccount {
nonce: 169.into(),
balance: U256::from_dec_str("999999999998417410153631615")?,
code_hash: hash_bytecode_u256(vec![]),
code_hash: hash_bytecode_h256(&[]),
code_length: 0.into(),
})
} else {
Expand Down Expand Up @@ -195,16 +195,13 @@ fn prepare_setup() -> anyhow::Result<GenerationInputs<F>> {
};

let mut contract_code = HashMap::new();
// TODO(Robin) Review this
if cfg!(feature = "eth_mainnet") {
let empty_code_hash = Either::Left(keccak(vec![]));
let code_hash = Either::Left(keccak(code));
contract_code.insert(empty_code_hash, vec![]);
contract_code.insert(code_hash, code.to_vec());
contract_code.insert(keccak(vec![]), vec![]);
contract_code.insert(keccak(code), code.to_vec());
} else {
let empty_code_hash = Either::Right(hash_bytecode_u256(vec![]));
let code_hash = Either::Right(hash_bytecode_u256(code.to_vec()));
contract_code.insert(empty_code_hash, vec![]);
contract_code.insert(code_hash, code.to_vec());
contract_code.insert(hash_bytecode_h256(&[]), vec![]);
contract_code.insert(hash_bytecode_h256(&code), code.to_vec());
}

let sender_account_after = if cfg!(feature = "cdk_erigon") {
Expand Down Expand Up @@ -344,7 +341,7 @@ use evm_arithmetization::generation::mpt::SmtAccount;

#[cfg(feature = "cdk_erigon")]
fn set_account(world: &mut StateWorld, addr: Address, account: &SmtAccount, code: &[u8]) {
use evm_arithmetization::world::world::World;
use evm_arithmetization::world::World;

let key = key_balance(addr);
log::debug!(
Expand All @@ -356,7 +353,7 @@ fn set_account(world: &mut StateWorld, addr: Address, account: &SmtAccount, code
if let Either::Right(ref mut smt_state) = world.state {
smt_state.update_balance(addr, |b| *b = account.get_balance());
smt_state.update_nonce(addr, |n| *n = account.get_nonce());
smt_state.set_code_hash(addr, code);
smt_state.set_code(addr, code);
let key = key_code_length(addr);
log::debug!(
"setting {:?} code length, the key is {:?}",
Expand Down
22 changes: 8 additions & 14 deletions evm_arithmetization/src/cpu/kernel/tests/account_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mpt_trie::partial_trie::{HashedPartialTrie, Node, PartialTrie};
use plonky2::field::goldilocks_field::GoldilocksField as F;
use plonky2::hash::hash_types::RichField;
use rand::{thread_rng, Rng};
use smt_trie::code::hash_bytecode_u256;
use smt_trie::code::hash_bytecode_h256;

use crate::cpu::kernel::aggregator::KERNEL;
use crate::cpu::kernel::constants::context_metadata::ContextMetadata::{self, GasLimit};
Expand All @@ -27,7 +27,7 @@ use crate::memory::segments::Segment;
use crate::util::h2u;
use crate::witness::memory::MemoryAddress;
use crate::witness::operation::CONTEXT_SCALING_FACTOR;
use crate::world::world::StateWorld;
use crate::world::StateWorld;

pub(crate) fn initialize_mpts<F: RichField>(
interpreter: &mut Interpreter<F>,
Expand Down Expand Up @@ -279,7 +279,7 @@ fn test_account(code: &[u8]) -> EitherAccount {
EitherAccount(Either::Right(SmtAccount {
nonce: U256::from(1111),
balance: U256::from(2222),
code_hash: hash_bytecode_u256(code.to_vec()),
code_hash: hash_bytecode_h256(&code).into_uint(),
code_length: code.len().into(),
}))
}
Expand Down Expand Up @@ -315,12 +315,9 @@ fn test_extcodesize() -> Result<()> {
.push(U256::from_big_endian(address.as_bytes()))
.expect("The stack should not overflow");
interpreter.generation_state.inputs.contract_code = if cfg!(feature = "eth_mainnet") {
HashMap::from([(Either::Left(keccak(&code)), code.clone())])
HashMap::from([(keccak(&code), code.clone())])
} else {
HashMap::from([(
Either::Right(hash_bytecode_u256(code.clone())),
code.clone(),
)])
HashMap::from([(hash_bytecode_h256(&code), code.clone())])
};

interpreter.run()?;
Expand Down Expand Up @@ -396,12 +393,9 @@ fn test_extcodecopy() -> Result<()> {
.push((0xDEADBEEFu64 + (1 << 32)).into())
.expect("The stack should not overflow"); // kexit_info
interpreter.generation_state.inputs.contract_code = if cfg!(feature = "eth_mainnet") {
HashMap::from([(Either::Left(keccak(&code)), code.clone())])
HashMap::from([(keccak(&code), code.clone())])
} else {
HashMap::from([(
Either::Right(hash_bytecode_u256(code.clone())),
code.clone(),
)])
HashMap::from([(hash_bytecode_h256(&code), code.clone())])
};

interpreter.run()?;
Expand Down Expand Up @@ -598,7 +592,7 @@ fn sstore() -> Result<()> {
fn sload() -> Result<()> {
use std::collections::BTreeMap;

use crate::world::{
use crate::{
tries::{StateMpt, StorageTrie},
world::Type1World,
};
Expand Down
Loading

0 comments on commit f0bb4f0

Please sign in to comment.