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

Rename Bridge contracts #369

Merged
merged 2 commits into from
Mar 6, 2025
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
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: submit_mainnet_state submit_devnet_state submit_account gen_contract_abi deploy_contract
.PHONY: submit_mainnet_state submit_devnet_state submit_account gen_contract_abi deploy_example_bridge_contracts

submit_mainnet_state:
@cargo run --manifest-path core/Cargo.toml --release -- submit-state
Expand All @@ -12,14 +12,14 @@ submit_account:
gen_contract_abis:
forge build --root contract/
forge build --root example/eth_contract
cp contract/out/MinaStateSettlement.sol/MinaStateSettlement.json core/abi/MinaStateSettlement.json
cp contract/out/MinaAccountValidation.sol/MinaAccountValidation.json core/abi/MinaAccountValidation.json
cp contract/out/MinaStateSettlementExample.sol/MinaStateSettlementExample.json core/abi/MinaStateSettlementExample.json
cp contract/out/MinaAccountValidationExample.sol/MinaAccountValidationExample.json core/abi/MinaAccountValidationExample.json
cp example/eth_contract/out/SudokuValidity.sol/SudokuValidity.json example/app/abi/SudokuValidity.json

deploy_contract:
deploy_example_bridge_contracts:
@cargo run --manifest-path contract_deployer/Cargo.toml --release

deploy_example_contract:
deploy_example_app_contracts:
@cargo run --manifest-path example/app/Cargo.toml --release -- deploy-contract

execute_example:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ This repo also includes example contracts that show how to interact with Aligned
1. In the root folder, deploy the example Bridge's contracts with:

```sh
make deploy_contract
make deploy_example_bridge_contracts
```

In the `.env` file, set `STATE_SETTLEMENT_ETH_ADDR` and `ACCOUNT_VALIDATION_ETH_ADDR` to the corresponding deployed contract addresses.
Expand Down Expand Up @@ -156,13 +156,13 @@ For running the example you need to:
2. Deploy the example bridge smart contracts by executing

```sh
make deploy_contract
make deploy_example_bridge_contracts
```

3. Deploy the SudokuValidity smart contract by executing

```sh
make deploy_example_contract
make deploy_example_app_contracts
```

4. Install `zkapp-cli`:
Expand Down Expand Up @@ -363,7 +363,7 @@ The verification consists in calculating the merkle root by hashing the branch (

### Mina State Settlement contract

[mina_bridge repo: contract/src/MinaStateSettlement.sol](https://github.com/lambdaclass/mina_bridge/tree/aligned/contract/src/MinaStateSettlement.sol)
[mina_bridge repo: contract/src/MinaStateSettlementExample.sol](https://github.com/lambdaclass/mina_bridge/tree/aligned/contract/src/MinaStateSettlementExample.sol)

This contract stores the latest verified state and ledger hashes (also called the bridge’s transition frontier) and updates the arrays with new values whenever a new Mina Proof of State is submitted.

Expand All @@ -377,7 +377,7 @@ The contract is deployed by a `contract_deployer` crate with an initial state th

### Mina Account Validation contract

[mina_bridge repo: contract/src/MinaAccountValidation.sol](https://github.com/lambdaclass/mina_bridge/tree/aligned/contract/src/MinaAccountValidation.sol)
[mina_bridge repo: contract/src/MinaAccountValidationExample.sol](https://github.com/lambdaclass/mina_bridge/tree/aligned/contract/src/MinaAccountValidationExample.sol)

This contract implements a method for validating an account, taking as parameter the verification data and public inputs of the proof sent to Aligned. It also implements a structure for representing account data. A user can decode the account from the public inputs into this structure.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import "aligned_layer/contracts/src/core/AlignedLayerServiceManager.sol";

error MinaAccountProvingSystemIdIsNotValid(bytes32); // c1872967

contract MinaAccountValidation {
/// WARNING: This contract is meant ot be used as an example of how to use the Bridge.
/// NEVER use this contract in a production environment.
contract MinaAccountValidationExample {
/// @notice The commitment to Mina Account proving system ID.
bytes32 constant PROVING_SYSTEM_ID_COMM = 0xd0591206d9e81e07f4defc5327957173572bcd1bca7838caa7be39b0c12b1873;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ error TipStateIsWrong(bytes32 pubInputTipStateHash, bytes32 tipStatehash); // bb
error AccountIsNotValid(bytes32 accountIdHash);

/// @title Mina to Ethereum Bridge's smart contract for verifying and storing a valid state chain.
contract MinaStateSettlement {
/// WARNING: This contract is meant ot be used as an example of how to use the Bridge.
/// NEVER use this contract in a production environment.
contract MinaStateSettlementExample {
/// @notice The commitment to Mina proving system ID.
bytes32 constant PROVING_SYSTEM_ID_COMM =
0xdbb8d0f4c497851a5043c6363657698cb1387682cac2f786c731f8936109d795;
Expand Down
31 changes: 18 additions & 13 deletions contract_deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use aligned_sdk::core::types::Network;
use log::{debug, error, info};
use mina_bridge_core::{
eth::{
deploy_mina_account_validation_contract, deploy_mina_bridge_contract,
MinaAccountValidationConstructorArgs, MinaStateSettlementConstructorArgs, SolStateHash,
deploy_mina_account_validation_example_contract, deploy_mina_bridge_example_contract,
MinaAccountValidationExampleConstructorArgs, MinaStateSettlementExampleConstructorArgs,
SolStateHash,
},
mina::query_root,
utils::{
Expand Down Expand Up @@ -57,14 +58,14 @@ async fn main() {
});

let bridge_constructor_args =
MinaStateSettlementConstructorArgs::new(&aligned_sm_addr, root_hash).unwrap_or_else(
MinaStateSettlementExampleConstructorArgs::new(&aligned_sm_addr, root_hash).unwrap_or_else(
|err| {
error!("Failed to make constructor args for bridge contract call: {err}");
process::exit(1);
},
);
let account_constructor_args = MinaAccountValidationConstructorArgs::new(&aligned_sm_addr)
.unwrap_or_else(|err| {
let account_constructor_args =
MinaAccountValidationExampleConstructorArgs::new(&aligned_sm_addr).unwrap_or_else(|err| {
error!("Failed to make constructor args for account contract call: {err}");
process::exit(1);
});
Expand All @@ -76,25 +77,29 @@ async fn main() {
});

// Contract for Devnet state proofs
deploy_mina_bridge_contract(&eth_rpc_url, &bridge_constructor_args, &wallet, true)
deploy_mina_bridge_example_contract(&eth_rpc_url, &bridge_constructor_args, &wallet, true)
.await
.unwrap_or_else(|err| {
error!("Failed to deploy contract: {err}");
process::exit(1);
});

// Contract for Mainnet state proofs
deploy_mina_bridge_contract(&eth_rpc_url, &bridge_constructor_args, &wallet, false)
deploy_mina_bridge_example_contract(&eth_rpc_url, &bridge_constructor_args, &wallet, false)
.await
.unwrap_or_else(|err| {
error!("Failed to deploy contract: {err}");
process::exit(1);
});

deploy_mina_account_validation_contract(&eth_rpc_url, account_constructor_args, &wallet)
.await
.unwrap_or_else(|err| {
error!("Failed to deploy contract: {err}");
process::exit(1);
});
deploy_mina_account_validation_example_contract(
&eth_rpc_url,
account_constructor_args,
&wallet,
)
.await
.unwrap_or_else(|err| {
error!("Failed to deploy contract: {err}");
process::exit(1);
});
}
1 change: 0 additions & 1 deletion core/abi/MinaAccountValidation.json

This file was deleted.

1 change: 1 addition & 0 deletions core/abi/MinaAccountValidationExample.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion core/abi/MinaStateSettlement.json

This file was deleted.

1 change: 1 addition & 0 deletions core/abi/MinaStateSettlementExample.json

Large diffs are not rendered by default.

70 changes: 38 additions & 32 deletions core/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,51 @@ use crate::{
};

abigen!(
MinaStateSettlementEthereumContract,
"abi/MinaStateSettlement.json"
MinaStateSettlementExampleEthereumContract,
"abi/MinaStateSettlementExample.json"
);
abigen!(
MinaAccountValidationEthereumContract,
"abi/MinaAccountValidation.json"
MinaAccountValidationExampleEthereumContract,
"abi/MinaAccountValidationExample.json"
);

type MinaStateSettlementEthereum =
MinaStateSettlementEthereumContract<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>>;
type MinaStateSettlementExampleEthereum = MinaStateSettlementExampleEthereumContract<
SignerMiddleware<Provider<Http>, Wallet<SigningKey>>,
>;

type MinaStateSettlementEthereumCallOnly = MinaStateSettlementEthereumContract<Provider<Http>>;
type MinaAccountValidationEthereumCallOnly = MinaAccountValidationEthereumContract<Provider<Http>>;
type MinaStateSettlementExampleEthereumCallOnly =
MinaStateSettlementExampleEthereumContract<Provider<Http>>;
type MinaAccountValidationExampleEthereumCallOnly =
MinaAccountValidationExampleEthereumContract<Provider<Http>>;

sol!(
#[allow(clippy::too_many_arguments)]
#[sol(rpc)]
MinaStateSettlement,
"abi/MinaStateSettlement.json"
MinaStateSettlementExample,
"abi/MinaStateSettlementExample.json"
);

sol!(
#[allow(clippy::too_many_arguments)]
#[sol(rpc)]
MinaAccountValidation,
"abi/MinaAccountValidation.json"
MinaAccountValidationExample,
"abi/MinaAccountValidationExample.json"
);

#[serde_as]
#[derive(Serialize, Deserialize)]
pub struct SolStateHash(#[serde_as(as = "SolSerialize")] pub StateHash);

pub struct MinaStateSettlementConstructorArgs {
pub struct MinaStateSettlementExampleConstructorArgs {
aligned_service_addr: alloy::primitives::Address,
root_state_hash: alloy::primitives::FixedBytes<32>,
}

pub struct MinaAccountValidationConstructorArgs {
pub struct MinaAccountValidationExampleConstructorArgs {
aligned_service_addr: alloy::primitives::Address,
}

impl MinaStateSettlementConstructorArgs {
impl MinaStateSettlementExampleConstructorArgs {
pub fn new(aligned_service_addr: &str, root_state_hash: Vec<u8>) -> Result<Self, String> {
let aligned_service_addr =
alloy::primitives::Address::parse_checksummed(aligned_service_addr, None)
Expand All @@ -77,7 +80,7 @@ impl MinaStateSettlementConstructorArgs {
}
}

impl MinaAccountValidationConstructorArgs {
impl MinaAccountValidationExampleConstructorArgs {
pub fn new(aligned_service_addr: &str) -> Result<Self, String> {
let aligned_service_addr =
alloy::primitives::Address::parse_checksummed(aligned_service_addr, None)
Expand Down Expand Up @@ -303,9 +306,9 @@ pub async fn validate_account(
Ok(())
}

pub async fn deploy_mina_bridge_contract(
pub async fn deploy_mina_bridge_example_contract(
eth_rpc_url: &str,
constructor_args: &MinaStateSettlementConstructorArgs,
constructor_args: &MinaStateSettlementExampleConstructorArgs,
wallet: &EthereumWallet,
is_state_proof_from_devnet: bool,
) -> Result<alloy::primitives::Address, String> {
Expand All @@ -314,11 +317,11 @@ pub async fn deploy_mina_bridge_contract(
.wallet(wallet)
.on_http(reqwest::Url::parse(eth_rpc_url).map_err(|err| err.to_string())?);

let MinaStateSettlementConstructorArgs {
let MinaStateSettlementExampleConstructorArgs {
aligned_service_addr,
root_state_hash,
} = constructor_args;
let contract = MinaStateSettlement::deploy(
let contract = MinaStateSettlementExample::deploy(
&provider,
*aligned_service_addr,
*root_state_hash,
Expand All @@ -335,7 +338,7 @@ pub async fn deploy_mina_bridge_contract(
};

info!(
"Mina {} Bridge contract successfuly deployed with address {}",
"Mina {} Bridge example contract successfuly deployed with address {}",
network, address
);
info!(
Expand All @@ -346,26 +349,26 @@ pub async fn deploy_mina_bridge_contract(
Ok(*address)
}

pub async fn deploy_mina_account_validation_contract(
pub async fn deploy_mina_account_validation_example_contract(
eth_rpc_url: &str,
constructor_args: MinaAccountValidationConstructorArgs,
constructor_args: MinaAccountValidationExampleConstructorArgs,
wallet: &EthereumWallet,
) -> Result<alloy::primitives::Address, String> {
let provider = ProviderBuilder::new()
.with_recommended_fillers()
.wallet(wallet)
.on_http(reqwest::Url::parse(eth_rpc_url).map_err(|err| err.to_string())?);

let MinaAccountValidationConstructorArgs {
let MinaAccountValidationExampleConstructorArgs {
aligned_service_addr,
} = constructor_args;
let contract = MinaAccountValidation::deploy(&provider, aligned_service_addr)
let contract = MinaAccountValidationExample::deploy(&provider, aligned_service_addr)
.await
.map_err(|err| err.to_string())?;
let address = contract.address();

info!(
"Mina Account Validation contract successfuly deployed with address {}",
"Mina Account Validation example contract successfuly deployed with address {}",
address
);
info!("Set ACCOUNT_VALIDATION_ETH_ADDR={}", address);
Expand All @@ -378,7 +381,7 @@ fn mina_bridge_contract(
contract_address: Address,
network: &Network,
wallet: Wallet<SigningKey>,
) -> Result<MinaStateSettlementEthereum, String> {
) -> Result<MinaStateSettlementExampleEthereum, String> {
let eth_rpc_provider =
Provider::<Http>::try_from(eth_rpc_url).map_err(|err| err.to_string())?;
let network_id = match network {
Expand All @@ -389,17 +392,20 @@ fn mina_bridge_contract(
let signer = SignerMiddleware::new(eth_rpc_provider, wallet.with_chain_id(network_id));
let client = Arc::new(signer);
debug!("contract address: {contract_address}");
Ok(MinaStateSettlementEthereum::new(contract_address, client))
Ok(MinaStateSettlementExampleEthereum::new(
contract_address,
client,
))
}

fn mina_bridge_contract_call_only(
eth_rpc_url: &str,
contract_address: Address,
) -> Result<MinaStateSettlementEthereumCallOnly, String> {
) -> Result<MinaStateSettlementExampleEthereumCallOnly, String> {
let eth_rpc_provider =
Provider::<Http>::try_from(eth_rpc_url).map_err(|err| err.to_string())?;
let client = Arc::new(eth_rpc_provider);
Ok(MinaStateSettlementEthereumCallOnly::new(
Ok(MinaStateSettlementExampleEthereumCallOnly::new(
contract_address,
client,
))
Expand All @@ -408,11 +414,11 @@ fn mina_bridge_contract_call_only(
fn mina_account_validation_contract_call_only(
eth_rpc_url: &str,
contract_address: Address,
) -> Result<MinaAccountValidationEthereumCallOnly, String> {
) -> Result<MinaAccountValidationExampleEthereumCallOnly, String> {
let eth_rpc_provider =
Provider::<Http>::try_from(eth_rpc_url).map_err(|err| err.to_string())?;
let client = Arc::new(eth_rpc_provider);
Ok(MinaAccountValidationEthereumCallOnly::new(
Ok(MinaAccountValidationExampleEthereumCallOnly::new(
contract_address,
client,
))
Expand Down
4 changes: 2 additions & 2 deletions core/src/mina.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
account_proof::{MerkleNode, MinaAccountProof, MinaAccountPubInputs},
state_proof::{MinaStateProof, MinaStatePubInputs},
},
sol::account::MinaAccountValidation,
sol::account::MinaAccountValidationExample,
utils::constants::BRIDGE_TRANSITION_FRONTIER_LEN,
};

Expand Down Expand Up @@ -101,7 +101,7 @@ pub async fn get_mina_proof_of_account(
let (account, ledger_hash, merkle_path) =
query_account(rpc_url, state_hash, public_key).await?;

let encoded_account = MinaAccountValidation::Account::try_from(&account)?.abi_encode();
let encoded_account = MinaAccountValidationExample::Account::try_from(&account)?.abi_encode();

debug!(
"Retrieved proof of account for ledger {}",
Expand Down
7 changes: 5 additions & 2 deletions core/src/sol/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ use mina_p2p_messages::{
},
};
use num_traits::ToPrimitive;
use MinaAccountValidation::*;
use MinaAccountValidationExample::*;

sol!(MinaAccountValidation, "abi/MinaAccountValidation.json");
sol!(
MinaAccountValidationExample,
"abi/MinaAccountValidationExample.json"
);

#[allow(non_snake_case)]
impl TryFrom<&MinaAccount> for Account {
Expand Down
2 changes: 1 addition & 1 deletion core/src/sol/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use mina_p2p_messages::{
use serde::{Deserialize, Serialize};

/// Serialization to bytes for simple types that need to be deserialized in Ethereum.
/// More complex structures, like an [`MinaAccountValidation::Account`], may use Solidity's ABI Encoding.
/// More complex structures, like an [`MinaAccountValidationExample::Account`], may use Solidity's ABI Encoding.
pub struct SolSerialize;

impl serde_with::SerializeAs<StateHash> for SolSerialize {
Expand Down
2 changes: 1 addition & 1 deletion example/app/abi/SudokuValidity.json

Large diffs are not rendered by default.

Loading