-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
177 additions
and
12 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
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
56 changes: 56 additions & 0 deletions
56
ethereum/circuits/lib/src/account_with_storage_recursive.nr
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,56 @@ | ||
use crate::account_with_storage::StorageWithinBlock; | ||
use crate::misc::{fragment::Fragment, types::{Address, Bytes32, ADDRESS_LENGTH, BYTES32_LENGTH}}; | ||
use crate::serde::STORAGE_BLOCK_LEN; | ||
use dep::std::{verify_proof, unsafe::zeroed}; | ||
|
||
struct RecursiveProof { | ||
key_hash: Field, | ||
verification_key: [Field; 114], | ||
proof: [Field; 93], | ||
} | ||
|
||
global NUM_PUBLIC_INPUTS = 1 + 1 + ADDRESS_LENGTH + BYTES32_LENGTH + STORAGE_BLOCK_LEN; // chain_id + block_number + address + storage_key + public_return_inputs | ||
|
||
pub fn get_account_with_storage_recursive( | ||
chain_id: Field, | ||
block_number: u64, | ||
address: Address, | ||
storage_key: Bytes32 | ||
) -> StorageWithinBlock<1> { | ||
let (storage_within_block, RecursiveProof {key_hash, verification_key, proof}) = get_account_with_storage_recursive_unconstrained(chain_id, block_number, address, storage_key); | ||
|
||
let mut public_inputs: Fragment<NUM_PUBLIC_INPUTS, Field> = Fragment::empty(); | ||
public_inputs.push_back(chain_id); | ||
public_inputs.push_back(block_number as Field); | ||
public_inputs.extend_back(address.serialize()); | ||
public_inputs.extend_back(storage_key.serialize()); | ||
public_inputs.extend_back(storage_within_block.serialize()); | ||
|
||
verify_proof( | ||
verification_key.as_slice(), | ||
proof.as_slice(), | ||
public_inputs.to_array::<NUM_PUBLIC_INPUTS>().as_slice(), | ||
key_hash | ||
); | ||
|
||
storage_within_block | ||
} | ||
|
||
#[oracle(get_storage_recursive)] | ||
unconstrained fn get_account_with_storage_recursive_oracle( | ||
chain_id: Field, | ||
block_number: u64, | ||
address: Address, | ||
storage_key: Bytes32 | ||
) -> ([Field; STORAGE_BLOCK_LEN], RecursiveProof) {} | ||
|
||
unconstrained fn get_account_with_storage_recursive_unconstrained( | ||
chain_id: Field, | ||
block_number: u64, | ||
address: Address, | ||
storage_key: Bytes32 | ||
) -> (StorageWithinBlock<1>, RecursiveProof) { | ||
let (return_value_serialized, proof) = get_account_with_storage_recursive_oracle(chain_id, block_number, address, storage_key); | ||
let return_value = StorageWithinBlock::deserialize(return_value_serialized); | ||
(return_value, proof) | ||
} |
18 changes: 18 additions & 0 deletions
18
ethereum/circuits/lib/src/account_with_storage_recursive_int_test.nr
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,18 @@ | ||
use crate::account_with_storage_recursive::{get_account_with_storage_recursive, RecursiveProof}; | ||
use crate::account_with_storage::StorageWithinBlock; | ||
use crate::fixtures::mainnet::paris::usdc_circle::{header::{number, hash}, account::{address, account}, storage::{keys, values}}; | ||
use crate::chain::ETHEREUM_MAINNET_ID; | ||
use crate::misc::types::{Bytes32, Address}; | ||
use dep::std::test::OracleMock; | ||
use dep::std::unsafe::zeroed; | ||
|
||
#[test] | ||
fn success() { | ||
let result = StorageWithinBlock { block_hash: hash, account, values }; | ||
// This is not a correct proof but it passes because nargo does not verify it. Nargo thinks that it's bb's job, but doesn't call bb. | ||
let recursive_proof: RecursiveProof = zeroed(); | ||
|
||
let _ = OracleMock::mock("get_storage_recursive").returns((result.serialize(), recursive_proof)); | ||
|
||
let _ = get_account_with_storage_recursive(ETHEREUM_MAINNET_ID, number, address, keys[0]); | ||
} |
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
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
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
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
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
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
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
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
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,8 @@ | ||
[package] | ||
name = "is_dao_worthy_recursive" | ||
type = "bin" | ||
compiler_version = ">=0.30.0" | ||
|
||
[dependencies] | ||
ethereum = { path = "../../../../ethereum/circuits/lib" } | ||
token = { path = "../../../ethereum/circuits/lib" } |
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,4 @@ | ||
block_number = 19000000 | ||
|
||
# Circle address | ||
wallet_address = [ 0x55, 0xfe, 0x00, 0x2a, 0xef, 0xf0, 0x2f, 0x77, 0x36, 0x4d, 0xe3, 0x39, 0xa1, 0x29, 0x29, 0x23, 0xa1, 0x58, 0x44, 0xb8 ] |
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 @@ | ||
block_number = 19000000 |
12 changes: 12 additions & 0 deletions
12
vlayer/examples/circuits/is_dao_worthy_recursive/src/main.nr
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,12 @@ | ||
use dep::ethereum::misc::types::Address; | ||
use dep::token::token_list::mainnet::USDC; | ||
|
||
mod main_test; | ||
|
||
global MIN_BALANCE = U128::from_integer(100_000_000_000); // $100k | ||
|
||
fn main(wallet_address: Address, block_number: pub u64) { | ||
let wallet_balance = USDC.get_balance(wallet_address, block_number, true); | ||
|
||
assert(MIN_BALANCE <= wallet_balance, "Insufficient USDC balance"); | ||
} |
27 changes: 27 additions & 0 deletions
27
vlayer/examples/circuits/is_dao_worthy_recursive/src/main_test.nr
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,27 @@ | ||
mod is_dao_worthy_main { | ||
use dep::std::test::OracleMock; | ||
use dep::ethereum::fixtures::mainnet::{ | ||
paris::usdc_circle::header::{hash, block_header_partial as paris_block_header_partial, block_header_rlp as paris_block_header_rlp}, | ||
paris::usdc_circle::account::account, paris::usdc_circle::storage::values, | ||
paris::usdc_circle::state_proof::proof_input_serialized as state_proof_input_serialized, | ||
paris::usdc_circle::storage_proof::proofs_serialized | ||
}; | ||
use dep::ethereum::{account_with_storage_recursive::RecursiveProof, account_with_storage::StorageWithinBlock}; | ||
use crate::main; | ||
|
||
#[test] | ||
fn success_greater_then() { | ||
let result = StorageWithinBlock { block_hash: hash, account, values }; | ||
let recursive_proof = RecursiveProof { key_hash: 1, verification_key: [0; 114], proof: [0; 93] }; | ||
|
||
let _ = OracleMock::mock("get_storage_recursive").returns((result.serialize(), recursive_proof)); | ||
let _ = OracleMock::mock("get_header").returns((paris_block_header_partial, paris_block_header_rlp)); | ||
let _ = OracleMock::mock("get_proof").returns((account, state_proof_input_serialized, proofs_serialized[0])); | ||
|
||
let block_number = 19_000_000; | ||
let circle_address = [ | ||
0x55, 0xfe, 0x00, 0x2a, 0xef, 0xf0, 0x2f, 0x77, 0x36, 0x4d, 0xe3, 0x39, 0xa1, 0x29, 0x29, 0x23, 0xa1, 0x58, 0x44, 0xb8 | ||
]; | ||
main(circle_address, block_number); | ||
} | ||
} |