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

Parameterize Sudoku Holesky address #355

Merged
merged 16 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
4 changes: 3 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ETH_CHAIN=<devnet/holesky>
MINA_RPC_URL=<url>
STATE_SETTLEMENT_ETH_ADDR=<address>
ACCOUNT_VALIDATION_ETH_ADDR=<address>
SAVE_PROOF=true/false # also false if other than "true" or variable were to be not defined

## These can be skipped if using devnet with Anvil.
Expand All @@ -9,7 +11,7 @@ SAVE_PROOF=true/false # also false if other than "true" or variable were to be n
# PROOF_GENERATOR_ADDR=<optional>
# BRIDGE_HOLESKY_ETH_ADDR=<optional>
# BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR=<optional>
# ALIGNED_SM_HOLESKY_ETH_ADDR=<optional>
# ALIGNED_SERVICE_MANAGER_ADDR=<optional>

## You can choose to use a keystore or private key for your signing wallet.
## Leave empty if choosing Anvil Devnet.
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.PHONY: submit-state submit-account gen_contract_abi deploy_contract
.PHONY: submit_mainnet_state submit_devnet_state submit_account gen_contract_abi deploy_contract

submit_state:
submit_mainnet_state:
@cargo run --manifest-path core/Cargo.toml --release -- submit-state

submit_devnet_state:
@cargo run --manifest-path core/Cargo.toml --release -- submit-state --devnet

submit_account:
@cargo run --manifest-path core/Cargo.toml --release -- submit-account ${PUBLIC_KEY} ${STATE_HASH}

Expand Down
28 changes: 21 additions & 7 deletions contract/src/MinaStateSettlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ pragma solidity ^0.8.12;

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

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

/// @title Mina to Ethereum Bridge's smart contract for verifying and storing a valid state chain.
Expand All @@ -24,12 +25,15 @@ contract MinaStateSettlement {
/// the bridge's transition frontier).
bytes32[BRIDGE_TRANSITION_FRONTIER_LEN] chainLedgerHashes;

bool devnetFlag;

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

constructor(address payable _alignedServiceAddr, bytes32 _tipStateHash) {
constructor(address payable _alignedServiceAddr, bytes32 _tipStateHash, bool _devnetFlag) {
aligned = AlignedLayerServiceManager(_alignedServiceAddr);
chainStateHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1] = _tipStateHash;
devnetFlag = _devnetFlag;
}

/// @notice Returns the last verified state hash.
Expand Down Expand Up @@ -76,9 +80,18 @@ contract MinaStateSettlement {
revert MinaProvingSystemIdIsNotValid(provingSystemAuxDataCommitment);
}

bool pubInputDevnetFlag;
assembly {
pubInputDevnetFlag := mload(add(pubInput, 0x20))
}

if (pubInputDevnetFlag != devnetFlag) {
revert MinaNetworkIsWrong();
}

bytes32 pubInputBridgeTipStateHash;
assembly {
pubInputBridgeTipStateHash := mload(add(pubInput, 0x20))
pubInputBridgeTipStateHash := mload(add(pubInput, 0x21))
}

if (pubInputBridgeTipStateHash != chainStateHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1]) {
Expand All @@ -105,9 +118,10 @@ contract MinaStateSettlement {
let slot_ledgers := chainLedgerHashes.slot

// first 32 bytes is length of byte array.
// second 32 bytes is the bridge tip state hash
// the next byte is the Devnet flag
// the next 32 bytes set is the bridge tip state hash
// the next BRIDGE_TRANSITION_FRONTIER_LEN sets of 32 bytes are state hashes.
let addr_states := add(pubInput, 64)
let addr_states := add(pubInput, 65)
// the next BRIDGE_TRANSITION_FRONTIER_LEN sets of 32 bytes are ledger hashes.
let addr_ledgers := add(addr_states, mul(32, BRIDGE_TRANSITION_FRONTIER_LEN))

Expand Down
2 changes: 1 addition & 1 deletion 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 = "update_to_0_7_for_real" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "use_two_vks" }
serde = { version = "1.0", features = ["derive"] }
mina-p2p-messages = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
bincode = "1.3.3"
Expand Down
25 changes: 21 additions & 4 deletions contract_deployer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aligned_sdk::core::types::Chain;
use log::{debug, error, info};
use mina_bridge_core::{
eth::{
Expand All @@ -6,8 +7,9 @@ use mina_bridge_core::{
},
mina::query_root,
utils::{
constants::BRIDGE_TRANSITION_FRONTIER_LEN, contract::get_aligned_sm_contract_addr,
env::EnvironmentVariables, wallet_alloy::get_wallet,
constants::{ALIGNED_SM_DEVNET_ETH_ADDR, BRIDGE_TRANSITION_FRONTIER_LEN},
env::EnvironmentVariables,
wallet_alloy::get_wallet,
},
};
use std::process;
Expand Down Expand Up @@ -43,7 +45,13 @@ async fn main() {
process::exit(1);
});

let aligned_sm_addr = get_aligned_sm_contract_addr(&chain).unwrap_or_else(|err| {
let aligned_sm_addr = match chain {
Chain::Devnet => Ok(ALIGNED_SM_DEVNET_ETH_ADDR.to_owned()),
Chain::Holesky => std::env::var("ALIGNED_SERVICE_MANAGER_ADDR")
.map_err(|err| format!("Error getting Aligned SM contract address: {err}")),
_ => Err("Unimplemented Ethereum contract on selected chain".to_owned()),
}
.unwrap_or_else(|err| {
error!("{err}");
process::exit(1);
});
Expand All @@ -67,7 +75,16 @@ async fn main() {
process::exit(1);
});

deploy_mina_bridge_contract(&eth_rpc_url, bridge_constructor_args, &wallet)
// Contract for Devnet state proofs
deploy_mina_bridge_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)
.await
.unwrap_or_else(|err| {
error!("Failed to deploy contract: {err}");
Expand Down
Loading