-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Xinding Wei <weixinding@gmail.com> Co-authored-by: MonkeyKing-1 <67293785+MonkeyKing-1@users.noreply.github.com> Co-authored-by: Roshan <roshan.palakkal@gmail.com> Co-authored-by: PatStiles <33334338+PatStiles@users.noreply.github.com>
- Loading branch information
Showing
352 changed files
with
55,035 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: ["main", "develop"] | ||
pull_request: | ||
branches: ["main", "develop", "release*", "release/*", "rc*", "*-audit*", "v0.13", "v0.12"] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest-64core-256ram | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Build | ||
run: | | ||
export AXIOM_SKIP_CONSTANT_GEN=1 | ||
cargo build --verbose | ||
- name: Run axiom-eth tests MockProver | ||
working-directory: "axiom-eth" | ||
run: | | ||
export ALCHEMY_KEY=${{ secrets.ALCHEMY_KEY}} | ||
export JSON_RPC_URL=${{ secrets.JSON_RPC_URL }} | ||
cargo t test_keccak | ||
cargo t rlc::tests | ||
cargo t rlp::tests | ||
cargo t keccak::tests | ||
cargo t block_header::tests | ||
cargo t mpt | ||
cargo t storage::tests::test_mock | ||
cargo t transaction::tests | ||
BLOCK_NUM=17000000 cargo test receipt::tests | ||
cargo t solidity::tests::mapping::test_mock | ||
cargo t solidity::tests::nested_mappings::test_mock | ||
cargo t solidity::tests::mapping_storage::test_mock | ||
- name: Run axiom-eth tests real prover | ||
working-directory: "axiom-eth" | ||
run: | | ||
export ALCHEMY_KEY=${{ secrets.ALCHEMY_KEY }} | ||
export JSON_RPC_URL=${{ secrets.JSON_RPC_URL }} | ||
cargo t --release -- test_one_mainnet_header_prover | ||
cargo t --release -- bench_mpt_inclusion_fixed --ignored | ||
cargo t --release utils::component:: | ||
- name: Run axiom-core tests | ||
working-directory: "axiom-core" | ||
run: | | ||
export ALCHEMY_KEY=${{ secrets.ALCHEMY_KEY }} | ||
export JSON_RPC_URL=${{ secrets.JSON_RPC_URL }} | ||
cargo t | ||
- name: Run axiom-query tests | ||
working-directory: "axiom-query" | ||
run: | | ||
export AXIOM_SKIP_CONSTANT_GEN=1 | ||
export ALCHEMY_KEY=${{ secrets.ALCHEMY_KEY }} | ||
export JSON_RPC_URL=${{ secrets.JSON_RPC_URL }} | ||
mkdir -p data/test | ||
cargo t --no-default-features --features "halo2-axiom, jemallocator" |
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,34 @@ | ||
name: Lints | ||
|
||
on: | ||
push: | ||
branches: ["main", "develop"] | ||
pull_request: | ||
branches: ["main", "develop"] | ||
|
||
jobs: | ||
lint: | ||
name: Lint | ||
if: github.event.pull_request.draft == false | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
override: false | ||
components: rustfmt, clippy | ||
|
||
- uses: Swatinem/rust-cache@v1 | ||
with: | ||
cache-on-failure: true | ||
|
||
- name: Run fmt | ||
run: | | ||
export AXIOM_SKIP_CONSTANT_GEN=1 | ||
cargo fmt --all -- --check | ||
- name: Run clippy | ||
run: cargo clippy --all -- -D warnings |
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,24 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
# ======= | ||
target/ | ||
params/ | ||
!params/integration_test | ||
|
||
*.png | ||
|
||
/halo2_ecc/src/bn254/data/ | ||
/halo2_ecc/src/secp256k1/data/ | ||
**/.env | ||
|
||
*.pk | ||
*.snark | ||
.DS_Store |
Empty file.
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,37 @@ | ||
[workspace] | ||
members = ["axiom-eth", "axiom-core", "axiom-query", "axiom-codec"] | ||
resolver = "2" | ||
|
||
[profile.dev] | ||
opt-level = 3 | ||
debug = 2 # change to 0 or 2 for more or less debug info | ||
overflow-checks = true | ||
incremental = true | ||
|
||
# Local "release" mode, more optimized than dev but faster to compile than release | ||
[profile.local] | ||
inherits = "dev" | ||
opt-level = 3 | ||
# Set this to 1 or 2 to get more useful backtraces | ||
debug = 1 | ||
debug-assertions = true | ||
panic = 'unwind' | ||
# better recompile times | ||
incremental = true | ||
lto = "thin" | ||
codegen-units = 16 | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
debug = false | ||
debug-assertions = false | ||
lto = "fat" | ||
# `codegen-units = 1` can lead to WORSE performance - always bench to find best profile for your machine! | ||
codegen-units = 1 | ||
panic = "abort" | ||
incremental = false | ||
|
||
# For performance profiling | ||
[profile.flamegraph] | ||
inherits = "release" | ||
debug = true |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Axiom | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,21 @@ | ||
# Axiom ZK Circuits | ||
|
||
This repository builds on [halo2-lib](https://github.com/axiom-crypto/halo2-lib/releases/tag/v0.3.0) and [snark-verifier](https://github.com/axiom-crypto/snark-verifier/tree/v0.1.1) to create a library of zero-knowledge proof circuits that [Axiom](https://axiom.xyz) uses to read data from the Ethereum virtual machine (EVM). | ||
|
||
This monorepo consists of multiple crates: | ||
|
||
## `axiom-eth` | ||
|
||
This is the main library of chips and frameworks for building ZK circuits that prove data from the Ethereum virtual machine (EVM). For more details, see the [README](./axiom-eth/README.md). | ||
|
||
## `axiom-core` | ||
|
||
This contains the ZK circuits that generate proofs for the `AxiomV2Core` smart contract. These circuits read the RLP encoded block headers for a chain of blocks and verify that the block headers form a chain. They output a Merkle Mountain Range of the block hashes of the chain. This crate also contains aggregation circuits to aggregate multiple circuits for the purpose of proving longer chains. For more details, see the [README](./axiom-core/README.md). | ||
|
||
## `axiom-query` | ||
|
||
This contains the ZK circuits that generate proofs for the `AxiomV2Query` smart contract. For more details, see the [README](./axiom-query/README.md). | ||
|
||
### `axiom-codec` | ||
|
||
This crate does not contain any ZK circuits, but it contains Rust types for Axiom queries and specifies how to encode/decode them to field elements for in-circuit use. |
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,37 @@ | ||
[package] | ||
name = "axiom-codec" | ||
version = "0.2.0" | ||
authors = ["Intrinsic Technologies"] | ||
license = "MIT" | ||
edition = "2021" | ||
repository = "https://github.com/axiom-crypto/axiom-eth" | ||
readme = "README.md" | ||
description = "This crate contains Rust types for Axiom queries and specifies how to encode/decode them to field elements for in-circuit use." | ||
rust-version = "1.73.0" | ||
|
||
[dependencies] | ||
byteorder = { version = "1.4.3" } | ||
serde = { version = "1.0", default-features = false, features = ["derive"] } | ||
serde_json = { version = "1.0", default-features = false } | ||
serde_repr = "0.1" | ||
base64 = { version = "0.21", optional = true } | ||
serde_with = { version = "2.2", optional = true } | ||
anyhow = "1.0" | ||
|
||
# halo2, features turned on by axiom-eth | ||
axiom-eth = { version = "=0.4.0", path = "../axiom-eth", default-features = false } | ||
|
||
# ethereum | ||
ethers-core = { version = "2.0.10" } | ||
|
||
[dev-dependencies] | ||
hex = "0.4.3" | ||
|
||
[build-dependencies] | ||
serde_json = "1.0" | ||
serde = { version = "1.0", features = ["derive"] } | ||
|
||
[features] | ||
default = ["halo2-axiom"] | ||
# halo2-pse = ["axiom-eth/halo2-pse"] | ||
halo2-axiom = ["axiom-eth/halo2-axiom"] |
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,20 @@ | ||
pub const ENCODED_K_BYTES: usize = 1; | ||
pub const ENCODED_VKEY_LENGTH_BYTES: usize = 1; | ||
pub const FIELD_IDX_BITS: usize = 32; | ||
pub const FIELD_IDX_BYTES: usize = 4; | ||
pub const MAX_SOLIDITY_MAPPING_KEYS: usize = 4; | ||
pub const MAX_SUBQUERY_INPUTS: usize = 13; | ||
pub const MAX_SUBQUERY_OUTPUTS: usize = 2; | ||
pub const NUM_SUBQUERY_TYPES: usize = 7; | ||
pub const SOURCE_CHAIN_ID_BYTES: usize = 8; | ||
pub const SUBQUERY_TYPE_BYTES: usize = 2; | ||
pub const USER_ADVICE_COLS: usize = 4; | ||
pub const USER_FIXED_COLS: usize = 1; | ||
pub const USER_INSTANCE_COLS: usize = 1; | ||
pub const USER_LOOKUP_ADVICE_COLS: usize = 1; | ||
pub const USER_MAX_OUTPUTS: usize = 128; | ||
pub const USER_MAX_SUBQUERIES: usize = 128; | ||
pub const USER_PROOF_LEN_BYTES: usize = 4; | ||
pub const USER_RESULT_BYTES: usize = 32; | ||
pub const USER_RESULT_FIELD_ELEMENTS: usize = 2; | ||
pub const USER_RESULT_LEN_BYTES: usize = 2; |
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,120 @@ | ||
use std::io::{Error, ErrorKind, Result}; | ||
|
||
use crate::{ | ||
constants::MAX_SOLIDITY_MAPPING_KEYS, | ||
encoder::field_elements::{ | ||
NUM_FE_SOLIDITY_NESTED_MAPPING, NUM_FE_SOLIDITY_NESTED_MAPPING_WITHOUT_KEYS, | ||
}, | ||
types::field_elements::{ | ||
FieldAccountSubquery, FieldHeaderSubquery, FieldReceiptSubquery, | ||
FieldSolidityNestedMappingSubquery, FieldStorageSubquery, FieldTxSubquery, | ||
FlattenedSubqueryResult, SubqueryKey, SubqueryOutput, SUBQUERY_KEY_LEN, | ||
SUBQUERY_RESULT_LEN, | ||
}, | ||
HiLo, | ||
}; | ||
|
||
impl<T> TryFrom<Vec<T>> for FlattenedSubqueryResult<T> { | ||
type Error = Error; | ||
|
||
fn try_from(value: Vec<T>) -> Result<Self> { | ||
if value.len() != SUBQUERY_RESULT_LEN { | ||
return Err(Error::new(ErrorKind::InvalidInput, "invalid array length")); | ||
} | ||
let mut key = value; | ||
let value = key.split_off(SUBQUERY_KEY_LEN); | ||
let key = key.try_into().map_err(|_| Error::other("should never happen"))?; | ||
let value = value.try_into().map_err(|_| Error::other("should never happen"))?; | ||
Ok(Self { key: SubqueryKey(key), value: SubqueryOutput(value) }) | ||
} | ||
} | ||
|
||
impl<T> TryFrom<Vec<T>> for FieldHeaderSubquery<T> { | ||
type Error = Error; | ||
|
||
fn try_from(value: Vec<T>) -> Result<Self> { | ||
let [block_number, field_idx] = value | ||
.try_into() | ||
.map_err(|_| Error::new(ErrorKind::InvalidInput, "invalid array length"))?; | ||
Ok(Self { block_number, field_idx }) | ||
} | ||
} | ||
|
||
impl<T> TryFrom<Vec<T>> for FieldAccountSubquery<T> { | ||
type Error = Error; | ||
|
||
fn try_from(value: Vec<T>) -> Result<Self> { | ||
let [block_number, addr, field_idx] = value | ||
.try_into() | ||
.map_err(|_| Error::new(ErrorKind::InvalidInput, "invalid array length"))?; | ||
Ok(Self { block_number, addr, field_idx }) | ||
} | ||
} | ||
|
||
impl<T> TryFrom<Vec<T>> for FieldStorageSubquery<T> { | ||
type Error = Error; | ||
|
||
fn try_from(value: Vec<T>) -> Result<Self> { | ||
let [block_number, addr, slot_hi, slot_lo] = value | ||
.try_into() | ||
.map_err(|_| Error::new(ErrorKind::InvalidInput, "invalid array length"))?; | ||
Ok(Self { block_number, addr, slot: HiLo::from_hi_lo([slot_hi, slot_lo]) }) | ||
} | ||
} | ||
|
||
impl<T> TryFrom<Vec<T>> for FieldTxSubquery<T> { | ||
type Error = Error; | ||
|
||
fn try_from(value: Vec<T>) -> Result<Self> { | ||
let [block_number, tx_idx, field_or_calldata_idx] = value | ||
.try_into() | ||
.map_err(|_| Error::new(ErrorKind::InvalidInput, "invalid array length"))?; | ||
Ok(Self { block_number, tx_idx, field_or_calldata_idx }) | ||
} | ||
} | ||
|
||
impl<T> TryFrom<Vec<T>> for FieldReceiptSubquery<T> { | ||
type Error = Error; | ||
|
||
fn try_from(value: Vec<T>) -> Result<Self> { | ||
let [block_number, tx_idx, field_or_log_idx, topic_or_data_or_address_idx, event_schema_hi, event_schema_lo] = | ||
value | ||
.try_into() | ||
.map_err(|_| Error::new(ErrorKind::InvalidInput, "invalid array length"))?; | ||
Ok(Self { | ||
block_number, | ||
tx_idx, | ||
field_or_log_idx, | ||
topic_or_data_or_address_idx, | ||
event_schema: HiLo::from_hi_lo([event_schema_hi, event_schema_lo]), | ||
}) | ||
} | ||
} | ||
|
||
impl<T> TryFrom<Vec<T>> for FieldSolidityNestedMappingSubquery<T> { | ||
type Error = Error; | ||
|
||
fn try_from(mut value: Vec<T>) -> Result<Self> { | ||
if value.len() != NUM_FE_SOLIDITY_NESTED_MAPPING { | ||
return Err(Error::new(ErrorKind::InvalidInput, "invalid array length")); | ||
} | ||
let keys = value.split_off(NUM_FE_SOLIDITY_NESTED_MAPPING_WITHOUT_KEYS); | ||
let [block_number, addr, slot_hi, slot_lo, mapping_depth] = | ||
value.try_into().map_err(|_| Error::other("should never happen"))?; | ||
let mut keys_iter = keys.into_iter(); | ||
let keys: Vec<_> = (0..MAX_SOLIDITY_MAPPING_KEYS) | ||
.map(|_| { | ||
let key_hi = keys_iter.next().unwrap(); | ||
let key_lo = keys_iter.next().unwrap(); | ||
HiLo::from_hi_lo([key_hi, key_lo]) | ||
}) | ||
.collect(); | ||
Ok(Self { | ||
block_number, | ||
addr, | ||
mapping_slot: HiLo::from_hi_lo([slot_hi, slot_lo]), | ||
mapping_depth, | ||
keys: keys.try_into().map_err(|_| Error::other("max keys wrong length"))?, | ||
}) | ||
} | ||
} |
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,2 @@ | ||
pub mod field_elements; | ||
pub mod native; |
Oops, something went wrong.