Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up example #352

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
aca4a54
Project cleanup (#287)
gabrielbosio Jul 16, 2024
5ab9681
Fetch Mina state hash and proof (#288)
gabrielbosio Jul 23, 2024
dff28c5
Send hardcoded tip for consensus check (#292)
gabrielbosio Jul 24, 2024
6d4ad4b
State size in protocol state public input (#297)
gabrielbosio Jul 25, 2024
94d49e4
Core program and Aligned polling serivce (#296)
xqft Jul 25, 2024
82f7ed1
Smart contract (#295)
xqft Jul 25, 2024
9d7f853
Smart contract utility (#298)
xqft Jul 29, 2024
678a9a5
Clean core (#301)
xqft Jul 30, 2024
fb383c7
Started README specification section (#300)
xqft Jul 31, 2024
bbd6cd7
Verify account inclusion locally (#290)
gabrielbosio Aug 1, 2024
dc91d49
Refactor mina service to use `graphql_client` (#306)
xqft Aug 7, 2024
e6eef29
Remove state_utility directory (#304)
gabrielbosio Aug 7, 2024
5ab8f1a
Add account inclusion job (#305)
gabrielbosio Aug 7, 2024
24e95d4
Use tip state from bridge contract (#307)
xqft Aug 9, 2024
1302c38
Update Aligned SDK (#314)
gabrielbosio Aug 9, 2024
cce6341
Update README.md (#313)
xqft Aug 13, 2024
b0d252d
Remove root state hash, fix pub input hash variable (#320)
xqft Aug 14, 2024
5d0b446
Aligned Layer with Holesky (#303)
gabrielbosio Aug 16, 2024
9b55219
Remove account inclusion crate's GraphQL query, improve mina_polling_…
xqft Aug 23, 2024
5bff160
Delete nonce file on submit error (#325)
gabrielbosio Aug 23, 2024
0dbf7a3
Account verifier (#322)
xqft Aug 26, 2024
4861170
Point Aligned back to Mina (#329)
gabrielbosio Aug 30, 2024
28d62a1
Relative finalization (#327)
xqft Sep 3, 2024
153b804
Remove account hashes from contract storage (#331)
xqft Sep 5, 2024
be70567
Use new GraphQL API for account inclusion (#332)
xqft Sep 6, 2024
d90b702
Sync with Aligned 0.5 (#333)
gabrielbosio Sep 9, 2024
22336ab
Sync with Aligned 0.5.2 (#335)
gabrielbosio Sep 13, 2024
ce3d4b1
Add Solidity-friendly account structure as public input for the accou…
xqft Sep 16, 2024
132e4ea
Update Aligned to 0.6.0 (#336)
gabrielbosio Sep 16, 2024
f6c43af
Fix Aligned SDK dependency (#339)
xqft Sep 17, 2024
473f0d0
Point Aligned SDK to mina branch (#340)
gabrielbosio Sep 19, 2024
34de880
Update Aligned to 0.7.0 (#341)
gabrielbosio Sep 24, 2024
48e5c43
Sudoku example app (#338)
xqft Sep 25, 2024
f9396d9
Rename MinaBridge to MinaStateSettlement (#345)
xqft Sep 25, 2024
b9ca11d
Check Proving system ID (#342)
gabrielbosio Sep 25, 2024
7dac115
Parameterize Holesky contract addresses (#343)
gabrielbosio Sep 25, 2024
f550222
Update README and code doc (#347)
xqft Sep 26, 2024
09b3469
Fix README links (#349)
gabrielbosio Sep 26, 2024
91efe0d
Fix Tock constraint domain size and add Book reference (#350)
gabrielbosio Sep 26, 2024
cc1a5e7
Add verification key check
xqft Sep 27, 2024
152292b
Merge branch 'aligned' into verif_key_check
xqft Sep 27, 2024
e9afbf0
Fix zkapp address
xqft Sep 27, 2024
32e9732
Add sudoku validity holesky address as env var
xqft Sep 27, 2024
c211338
Update README
xqft Sep 27, 2024
0de6199
Fix (#353)
xqft Sep 30, 2024
f22ebea
Merge branch 'aligned' into verif_key_check
xqft Oct 1, 2024
60ef22b
Update zkapp address
xqft Oct 1, 2024
0a7063b
Select Mina state proof source (#351)
gabrielbosio Oct 2, 2024
f3bb736
Parameterize Sudoku Holesky address (#355)
gabrielbosio Oct 2, 2024
16bc6df
Usage and Setup sections (#348)
gabrielbosio Oct 3, 2024
8b6b717
Merge branch 'aligned' into verif_key_check
xqft Oct 3, 2024
b2776fe
Fix conflict
xqft Oct 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Aligned to 0.7.0 (#341)
* [WIP] Update Aligned to 0.7.0

We must wait until Aligned uploads the release for 0.7.0.

Once it's uploaded we need to add a batcher payment service arg
to the `updateChain` call in the Aligned polling service.

* Update Aligned to 0.7.0

* Update Aligned branch

* Update Aligned and Bridge contracts

* Update Aligned Foundry submodule
gabrielbosio authored Sep 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 34de880c28ae3b3ba7807341805c2dfa32e0eb09
39 changes: 21 additions & 18 deletions contract/src/MinaAccountValidation.sol
Original file line number Diff line number Diff line change
@@ -6,35 +6,38 @@ import "aligned_layer/contracts/src/core/AlignedLayerServiceManager.sol";
error AccountIsNotVerified();

contract MinaAccountValidation {
struct AlignedArgs {
bytes32 proofCommitment;
bytes32 provingSystemAuxDataCommitment;
bytes20 proofGeneratorAddr;
bytes32 batchMerkleRoot;
bytes merkleProof;
uint256 verificationDataBatchIndex;
bytes pubInput;
address batcherPaymentService;
}

/// @notice Reference to the AlignedLayerServiceManager contract.
AlignedLayerServiceManager aligned;

constructor(address payable _alignedServiceAddr) {
aligned = AlignedLayerServiceManager(_alignedServiceAddr);
}

function validateAccount(
bytes32 proofCommitment,
bytes32 provingSystemAuxDataCommitment,
bytes20 proofGeneratorAddr,
bytes32 batchMerkleRoot,
bytes memory merkleProof,
uint256 verificationDataBatchIndex,
bytes calldata pubInput
) external view returns (Account memory) {
bytes calldata encodedAccount = pubInput[32 + 8:];
function validateAccount(AlignedArgs calldata args) external view returns (Account memory) {
bytes calldata encodedAccount = args.pubInput[32 + 8:];

bytes32 pubInputCommitment = keccak256(pubInput);
bytes32 pubInputCommitment = keccak256(args.pubInput);

bool isAccountVerified = aligned.verifyBatchInclusion(
proofCommitment,
args.proofCommitment,
pubInputCommitment,
provingSystemAuxDataCommitment,
proofGeneratorAddr,
batchMerkleRoot,
merkleProof,
verificationDataBatchIndex,
address(0)
args.provingSystemAuxDataCommitment,
args.proofGeneratorAddr,
args.batchMerkleRoot,
args.merkleProof,
args.verificationDataBatchIndex,
args.batcherPaymentService
);

if (isAccountVerified) {
9 changes: 5 additions & 4 deletions contract/src/MinaBridge.sol
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ pragma solidity ^0.8.12;

import "aligned_layer/contracts/src/core/AlignedLayerServiceManager.sol";

error NewStateIsNotValid();
error TipStateIsWrong(bytes32 pubInputTipStateHash, bytes32 tipStatehash);
error NewStateIsNotValid(); // 114602f0
error TipStateIsWrong(bytes32 pubInputTipStateHash, bytes32 tipStatehash); // bbd80128
error AccountIsNotValid(bytes32 accountIdHash);

/// @title Mina to Ethereum Bridge's smart contract.
@@ -55,7 +55,8 @@ contract MinaBridge {
bytes32 batchMerkleRoot,
bytes memory merkleProof,
uint256 verificationDataBatchIndex,
bytes memory pubInput
bytes memory pubInput,
address batcherPaymentService
) external {
bytes32 pubInputBridgeTipStateHash;
assembly {
@@ -76,7 +77,7 @@ contract MinaBridge {
batchMerkleRoot,
merkleProof,
verificationDataBatchIndex,
address(0)
batcherPaymentService
);

if (isNewStateVerified) {
10 changes: 5 additions & 5 deletions contract_deployer/Cargo.lock

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

2 changes: 1 addition & 1 deletion contract_deployer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ ethers = { tag = "v2.0.15-fix-reconnections", features = [
mina-curves = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes-rampup4-vrf" }
o1-utils = { git = "https://github.com/lambdaclass/proof-systems", branch = "add-verifier-serializations" }
kimchi = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes-rampup4-vrf" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "mina" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "update_to_0_7_for_real" }
serde = { version = "1.0", features = ["derive"] }
mina-p2p-messages = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
bincode = "1.3.3"
10 changes: 5 additions & 5 deletions core/Cargo.lock

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

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ ark-poly = { version = "0.3.0", features = ["parallel"] }
ark-serialize = "0.3.0"
mina-tree = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
mina-p2p-messages = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "mina" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "update_to_0_7_for_real" }
ethers = { tag = "v2.0.15-fix-reconnections", features = [
"ws",
"rustls",
2 changes: 1 addition & 1 deletion core/abi/MinaAccountValidation.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/abi/MinaBridge.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions core/src/aligned_polling_service.rs
Original file line number Diff line number Diff line change
@@ -109,11 +109,15 @@ async fn submit_with_nonce(
nonce: U256,
payment_service_addr: &str,
) -> Result<AlignedVerificationData, String> {
// Temporary max fee. We should consider calculating this or setting it as an env var.
let fixed_max_fee = U256::from_dec_str("1300000000000000").map_err(|err| err.to_string())?;

submit_and_wait_verification(
batcher_addr,
eth_rpc_url,
chain.to_owned(),
mina_proof,
fixed_max_fee,
wallet,
nonce,
payment_service_addr,
2 changes: 2 additions & 0 deletions core/src/main.rs
Original file line number Diff line number Diff line change
@@ -91,6 +91,7 @@ async fn main() {
&chain,
&eth_rpc_url,
wallet,
&batcher_eth_addr,
)
.await
.unwrap_or_else(|err| {
@@ -132,6 +133,7 @@ async fn main() {
&pub_input,
&chain,
&eth_rpc_url,
&batcher_eth_addr,
)
.await
{
26 changes: 20 additions & 6 deletions core/src/smart_contract_utility.rs
Original file line number Diff line number Diff line change
@@ -16,8 +16,9 @@ use crate::{
proof::{account_proof::MinaAccountPubInputs, state_proof::MinaStatePubInputs},
sol::serialization::SolSerialize,
utils::constants::{
ANVIL_CHAIN_ID, BRIDGE_ACCOUNT_DEVNET_ETH_ADDR, BRIDGE_DEVNET_ETH_ADDR,
BRIDGE_HOLESKY_ETH_ADDR, BRIDGE_TRANSITION_FRONTIER_LEN, HOLESKY_CHAIN_ID,
ANVIL_CHAIN_ID, BRIDGE_ACCOUNT_DEVNET_ETH_ADDR, BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR,
BRIDGE_DEVNET_ETH_ADDR, BRIDGE_HOLESKY_ETH_ADDR, BRIDGE_TRANSITION_FRONTIER_LEN,
HOLESKY_CHAIN_ID,
},
};

@@ -94,6 +95,7 @@ pub async fn update_chain(
chain: &Chain,
eth_rpc_url: &str,
wallet: Wallet<SigningKey>,
batcher_payment_service: &str,
) -> Result<(), String> {
let bridge_eth_addr = Address::from_str(match chain {
Chain::Devnet => BRIDGE_DEVNET_ETH_ADDR,
@@ -108,6 +110,9 @@ pub async fn update_chain(
let serialized_pub_input = bincode::serialize(pub_input)
.map_err(|err| format!("Failed to serialize public inputs: {err}"))?;

let batcher_payment_service = Address::from_str(batcher_payment_service)
.map_err(|err| format!("Failed to parse batcher payment service address: {err}"))?;

debug!("Creating contract instance");
let mina_bridge_contract = mina_bridge_contract(eth_rpc_url, bridge_eth_addr, chain, wallet)?;

@@ -141,6 +146,7 @@ pub async fn update_chain(
merkle_proof,
index_in_batch.into(),
serialized_pub_input.into(),
batcher_payment_service,
);
// update call reverts if batch is not valid or proof isn't included in it.

@@ -258,9 +264,11 @@ pub async fn validate_account(
pub_input: &MinaAccountPubInputs,
chain: &Chain,
eth_rpc_url: &str,
batcher_payment_service: &str,
) -> Result<Account, String> {
let bridge_eth_addr = Address::from_str(match chain {
Chain::Devnet => BRIDGE_ACCOUNT_DEVNET_ETH_ADDR,
Chain::Holesky => BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR,
_ => {
error!("Unimplemented Ethereum contract on selected chain");
unimplemented!()
@@ -275,6 +283,9 @@ pub async fn validate_account(
let serialized_pub_input = bincode::serialize(pub_input)
.map_err(|err| format!("Failed to serialize public inputs: {err}"))?;

let batcher_payment_service = Address::from_str(batcher_payment_service)
.map_err(|err| format!("Failed to parse batcher payment service address: {err}"))?;

let AlignedVerificationData {
verification_data_commitment,
batch_merkle_root,
@@ -298,15 +309,18 @@ pub async fn validate_account(

debug!("Validating account");

let call = contract.validate_account(
let aligned_args = AlignedArgs {
proof_commitment,
proving_system_aux_data_commitment,
proof_generator_addr,
batch_merkle_root,
merkle_proof,
index_in_batch.into(),
serialized_pub_input.into(),
);
verification_data_batch_index: index_in_batch.into(),
pub_input: serialized_pub_input.into(),
batcher_payment_service,
};

let call = contract.validate_account(aligned_args);

info!(
"Estimated account verification gas cost: {}",
5 changes: 3 additions & 2 deletions core/src/utils/constants.rs
Original file line number Diff line number Diff line change
@@ -18,11 +18,12 @@ pub const MINA_HASH_SIZE: usize = 32;

// Bridge related constants
pub const BRIDGE_DEVNET_ETH_ADDR: &str = "0x700b6A60ce7EaaEA56F065753d8dcB9653dbAD35";
pub const BRIDGE_HOLESKY_ETH_ADDR: &str = "0x42c6AA216f895278BAcfbD01E3aae2B99d2e4673";
pub const BRIDGE_HOLESKY_ETH_ADDR: &str = "0x8aED2F71774a98354091F8a885a19fA9C8659169";
pub const BRIDGE_TRANSITION_FRONTIER_LEN: usize = 16;
pub const BRIDGE_ACCOUNT_DEVNET_ETH_ADDR: &str = "0xA15BB66138824a1c7167f5E85b957d04Dd34E468";
pub const BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR: &str = "0x9Cbb0439EB42FBda982851068D52b1871F72Bea9";

// Aligned related constants
pub const PROOF_GENERATOR_ADDR: &str = "0x66f9664f97F2b50F62D13eA064982f936dE76657";
pub const ALIGNED_SM_DEVNET_ETH_ADDR: &str = "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8";
pub const ALIGNED_SM_HOLESKY_ETH_ADDR: &str = "0x0584313310bD52B77CF0b81b350Ca447B97Df5DF";
pub const ALIGNED_SM_HOLESKY_ETH_ADDR: &str = "0x8B744d6E01d13C868AB1cf69c8788D88C6058A92";