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

Update Aligned to 0.7.0 #341

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 21 additions & 18 deletions contract/src/MinaAccountValidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions contract/src/MinaBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -76,7 +77,7 @@ contract MinaBridge {
batchMerkleRoot,
merkleProof,
verificationDataBatchIndex,
address(0)
batcherPaymentService
);

if (isNewStateVerified) {
Expand Down
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
Expand Up @@ -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"
Expand Down
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
Expand Up @@ -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",
Expand Down
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
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async fn main() {
&chain,
&eth_rpc_url,
wallet,
&batcher_eth_addr,
)
.await
.unwrap_or_else(|err| {
Expand Down Expand Up @@ -132,6 +133,7 @@ async fn main() {
&pub_input,
&chain,
&eth_rpc_url,
&batcher_eth_addr,
)
.await
{
Expand Down
26 changes: 20 additions & 6 deletions core/src/smart_contract_utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down Expand Up @@ -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,
Expand All @@ -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)?;

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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!()
Expand All @@ -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,
Expand All @@ -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: {}",
Expand Down
5 changes: 3 additions & 2 deletions core/src/utils/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";