diff --git a/contract/src/MinaStateSettlement.sol b/contract/src/MinaStateSettlement.sol index 0f0c69e4..c92fb6c3 100644 --- a/contract/src/MinaStateSettlement.sol +++ b/contract/src/MinaStateSettlement.sol @@ -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. @@ -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. @@ -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]) { diff --git a/core/src/main.rs b/core/src/main.rs index bf965a31..8c6a456b 100644 --- a/core/src/main.rs +++ b/core/src/main.rs @@ -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, @@ -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, ð_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, ð_rpc_url, devnet) + .await + .unwrap_or_else(|err| { + error!("{}", err); + process::exit(1); + }); let verification_data = aligned::submit( MinaProof::State((proof, pub_input.clone())), diff --git a/core/src/mina.rs b/core/src/mina.rs index 8ba46244..39ee0f56 100644 --- a/core/src/mina.rs +++ b/core/src/mina.rs @@ -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 ( @@ -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 }, )) } diff --git a/core/src/proof/state_proof.rs b/core/src/proof/state_proof.rs index 00053171..862cae78 100644 --- a/core/src/proof/state_proof.rs +++ b/core/src/proof/state_proof.rs @@ -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")] @@ -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)]