Skip to content

Commit

Permalink
Add devnet flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Sep 27, 2024
1 parent 491721f commit 206a963
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
24 changes: 17 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,15 +25,15 @@ contract MinaStateSettlement {
/// the bridge's transition frontier).
bytes32[BRIDGE_TRANSITION_FRONTIER_LEN] chainLedgerHashes;

bool isStateProofFromDevnet;
bool devnetFlag;

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

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

/// @notice Returns the last verified state hash.
Expand Down Expand Up @@ -79,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 Down
17 changes: 9 additions & 8 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Cli {
enum Command {
SubmitState {
#[arg(short, long)]
is_state_proof_from_devnet: bool,
devnet: bool,
/// Write the proof into .proof and .pub files
#[arg(short, long)]
save_proof: bool,
Expand Down Expand Up @@ -61,13 +61,14 @@ async fn main() {
});

match cli.command {
Command::SubmitState { is_state_proof_from_devnet, save_proof } => {
let (proof, pub_input) = mina::get_mina_proof_of_state(&rpc_url, &chain, &eth_rpc_url, is_state_proof_from_devnet)
.await
.unwrap_or_else(|err| {
error!("{}", err);
process::exit(1);
});
Command::SubmitState { devnet, save_proof } => {
let (proof, pub_input) =
mina::get_mina_proof_of_state(&rpc_url, &chain, &eth_rpc_url, devnet)
.await
.unwrap_or_else(|err| {
error!("{}", err);
process::exit(1);
});

let verification_data = aligned::submit(
MinaProof::State((proof, pub_input.clone())),
Expand Down
4 changes: 2 additions & 2 deletions core/src/mina.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub async fn get_mina_proof_of_state(
rpc_url: &str,
chain: &Chain,
eth_rpc_url: &str,
is_state_proof_from_devnet: bool
is_state_proof_from_devnet: bool,
) -> Result<(MinaStateProof, MinaStatePubInputs), String> {
let bridge_tip_state_hash = get_bridge_tip_hash(chain, eth_rpc_url).await?.0;
let (
Expand All @@ -86,10 +86,10 @@ pub async fn get_mina_proof_of_state(
bridge_tip_state,
},
MinaStatePubInputs {
is_state_proof_from_devnet,
bridge_tip_state_hash,
candidate_chain_state_hashes,
candidate_chain_ledger_hashes,
is_state_proof_from_devnet
},
))
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/proof/state_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{sol::serialization::SolSerialize, utils::constants::BRIDGE_TRANSITIO
#[serde_as]
#[derive(Serialize, Deserialize, Clone)]
pub struct MinaStatePubInputs {
pub is_state_proof_from_devnet: bool,
/// The hash of the bridge's transition frontier tip state. Used for making sure that we're
/// checking if a candidate tip is better than the latest bridged tip.
#[serde_as(as = "SolSerialize")]
Expand All @@ -20,7 +21,6 @@ pub struct MinaStatePubInputs {
/// where the leafs are Mina account hashes. Used for account verification.
#[serde_as(as = "[SolSerialize; BRIDGE_TRANSITION_FRONTIER_LEN]")]
pub candidate_chain_ledger_hashes: [LedgerHash; BRIDGE_TRANSITION_FRONTIER_LEN],
pub is_state_proof_from_devnet: bool
}

#[derive(Serialize, Deserialize)]
Expand Down

0 comments on commit 206a963

Please sign in to comment.