Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirhemo committed Sep 10, 2024
2 parents 2b6bd90 + 52d24ee commit f17c080
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 137 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

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

34 changes: 19 additions & 15 deletions book/onchain-verification/contract-addresses.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# Contract Addresses

When using SP1, we recommend using our deployed verifiers. Each contract is a [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol) which can automatically route your SP1 proof to the correct verifier based on the prover version. Whenever a new prover version is deployed, the gateway contract will be updated to support it with [addRoute()](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol#L65). In the case that a prover version has an issue, the gateway contract will stop supporting it with [freezeRoute()](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol#L71).

| Chain ID | Chain | Gateway |
| -------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| 1 | Mainnet | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 11155111 | Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 17000 | Holesky | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://holesky.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 42161 | Arbitrum One | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://arbiscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 421614 | Arbitrum Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.arbiscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 534351 | Scroll Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.scrollscan.com/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 534352 | Scroll | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://scrollscan.com/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 8453 | Base | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://basescan.org/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 84532 | Base Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.basescan.org/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |

**Currently officially supported version of SP1 is v1.1.0.** If you'd like official support for a verifier on a different chain, please ask in the [SP1 Telegram](https://t.me/+AzG4ws-kD24yMGYx).
To verify SP1 proofs on-chain, we recommend using our deployed verifier gateways. For the chains listed below, an [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol) can automatically route your SP1 proof to the correct verifier based on the SP1 version.

| Chain ID | Chain | Gateway |
| -------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| 1 | Mainnet | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 11155111 | Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 17000 | Holesky | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://holesky.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 42161 | Arbitrum One | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://arbiscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 421614 | Arbitrum Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.arbiscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 8453 | Base | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://basescan.org/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 84532 | Base Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.basescan.org/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 10 | Optimism | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://optimistic.etherscan.io/address/0x3b6041173b80e77f038f3f2c0f9744f04837185e) |
| 11155420 | Optimism Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](hhttps://sepolia-optimism.etherscan.io/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 534351 | Scroll Sepolia | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://sepolia.scrollscan.com/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |
| 534352 | Scroll | [0x3B6041173B80E77f038f3F2C0f9744f04837185e](https://scrollscan.com/address/0x3B6041173B80E77f038f3F2C0f9744f04837185e) |

A complete reference for all of the SP1Verifier contract addresses can be also be found in the [SP1 Contracts Repo](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/deployments).

Whenever a verifier for a new SP1 version is deployed, the gateway contract will be updated to support it with [addRoute()](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol#L65). If a verifier for an SP1 version has an issue, the route will be frozen with [freezeRoute()](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/ISP1VerifierGateway.sol#L71).

## ISP1Verifier Interface

Expand Down
1 change: 1 addition & 0 deletions crates/core/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ hex = "0.4.3"
bytemuck = "1.16.3"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
vec_map = { version = "0.8.2", features = ["serde"] }
enum-map = { version = "2.7.3", features = ["serde"] }

[dev-dependencies]
sp1-zkvm = { workspace = true }
Expand Down
20 changes: 8 additions & 12 deletions crates/core/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,23 +696,19 @@ impl<'a> Executor<'a> {
if self.executor_mode == ExecutorMode::Trace {
self.memory_accesses = MemoryAccessRecord::default();
}
let lookup_id = if self.executor_mode == ExecutorMode::Simple {
LookupId::default()
} else {
let lookup_id = if self.executor_mode == ExecutorMode::Trace {
create_alu_lookup_id()
};
let syscall_lookup_id = if self.executor_mode == ExecutorMode::Simple {
LookupId::default()
} else {
LookupId::default()
};
let syscall_lookup_id = if self.executor_mode == ExecutorMode::Trace {
create_alu_lookup_id()
} else {
LookupId::default()
};

if self.print_report && !self.unconstrained {
self.report
.opcode_counts
.entry(instruction.opcode)
.and_modify(|c| *c += 1)
.or_insert(1);
self.report.opcode_counts[instruction.opcode] += 1;
}

match instruction.opcode {
Expand Down Expand Up @@ -930,7 +926,7 @@ impl<'a> Executor<'a> {
let syscall = SyscallCode::from_u32(syscall_id);

if self.print_report && !self.unconstrained {
self.report.syscall_counts.entry(syscall).and_modify(|c| *c += 1).or_insert(1);
self.report.syscall_counts[syscall] += 1;
}

// `hint_slice` is allowed in unconstrained mode since it is used to write the hint.
Expand Down
5 changes: 4 additions & 1 deletion crates/core/executor/src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::fmt::Display;

use enum_map::Enum;
use p3_field::Field;
use serde::{Deserialize, Serialize};

Expand All @@ -20,7 +21,9 @@ use serde::{Deserialize, Serialize};
/// Refer to the "RV32I Reference Card" [here](https://github.com/johnwinans/rvalp/releases) for
/// more details.
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord, Enum,
)]
pub enum Opcode {
/// rd ← rs1 + rs2, pc ← pc + 4
ADD = 0,
Expand Down
27 changes: 12 additions & 15 deletions crates/core/executor/src/report.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use std::{
collections::{hash_map::Entry, HashMap},
fmt::{Display, Formatter, Result as FmtResult},
hash::Hash,
ops::{Add, AddAssign},
};

use enum_map::{EnumArray, EnumMap};
use hashbrown::HashMap;

use crate::{events::sorted_table_lines, syscalls::SyscallCode, Opcode};

/// An execution report.
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct ExecutionReport {
/// The opcode counts.
pub opcode_counts: HashMap<Opcode, u64>,
pub opcode_counts: Box<EnumMap<Opcode, u64>>,
/// The syscall counts.
pub syscall_counts: HashMap<SyscallCode, u64>,
pub syscall_counts: Box<EnumMap<SyscallCode, u64>>,
/// The cycle tracker counts.
pub cycle_tracker: HashMap<String, u64>,
/// The unique memory address counts.
Expand All @@ -35,24 +36,20 @@ impl ExecutionReport {
}

/// Combines two `HashMap`s together. If a key is in both maps, the values are added together.
fn hashmap_add_assign<K, V>(lhs: &mut HashMap<K, V>, rhs: HashMap<K, V>)
fn counts_add_assign<K, V>(lhs: &mut EnumMap<K, V>, rhs: EnumMap<K, V>)
where
K: Eq + Hash,
K: EnumArray<V>,
V: AddAssign,
{
for (k, v) in rhs {
// Can't use `.and_modify(...).or_insert(...)` because we want to use `v` in both places.
match lhs.entry(k) {
Entry::Occupied(e) => *e.into_mut() += v,
Entry::Vacant(e) => drop(e.insert(v)),
}
lhs[k] += v;
}
}

impl AddAssign for ExecutionReport {
fn add_assign(&mut self, rhs: Self) {
hashmap_add_assign(&mut self.opcode_counts, rhs.opcode_counts);
hashmap_add_assign(&mut self.syscall_counts, rhs.syscall_counts);
counts_add_assign(&mut self.opcode_counts, *rhs.opcode_counts);
counts_add_assign(&mut self.syscall_counts, *rhs.syscall_counts);
self.touched_memory_addresses += rhs.touched_memory_addresses;
}
}
Expand All @@ -69,12 +66,12 @@ impl Add for ExecutionReport {
impl Display for ExecutionReport {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
writeln!(f, "opcode counts ({} total instructions):", self.total_instruction_count())?;
for line in sorted_table_lines(&self.opcode_counts) {
for line in sorted_table_lines(self.opcode_counts.as_ref()) {
writeln!(f, " {line}")?;
}

writeln!(f, "syscall counts ({} total syscall instructions):", self.total_syscall_count())?;
for line in sorted_table_lines(&self.syscall_counts) {
for line in sorted_table_lines(self.syscall_counts.as_ref()) {
writeln!(f, " {line}")?;
}

Expand Down
3 changes: 2 additions & 1 deletion crates/core/executor/src/syscalls/code.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use enum_map::Enum;
use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;

Expand All @@ -18,7 +19,7 @@ use strum_macros::EnumIter;
/// memory accesses is bounded.
/// - Byte 3: Currently unused.
#[derive(
Debug, Copy, Clone, PartialEq, Eq, Hash, EnumIter, Ord, PartialOrd, Serialize, Deserialize,
Debug, Copy, Clone, PartialEq, Eq, Hash, EnumIter, Ord, PartialOrd, Serialize, Deserialize, Enum,
)]
#[allow(non_camel_case_types)]
#[allow(clippy::upper_case_acronyms)]
Expand Down
Loading

0 comments on commit f17c080

Please sign in to comment.