Skip to content

Commit

Permalink
Merge branch 'aligned' into verif_key_check
Browse files Browse the repository at this point in the history
  • Loading branch information
xqft committed Sep 27, 2024
2 parents cc1a5e7 + 91efe0d commit 152292b
Show file tree
Hide file tree
Showing 24 changed files with 345 additions and 338 deletions.
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ SAVE_PROOF=true/false # also false if other than "true" or variable were to be n
# BATCHER_ETH_ADDR=<optional>
# ETH_RPC_URL=<optional>
# PROOF_GENERATOR_ADDR=<optional>
# BRIDGE_HOLESKY_ETH_ADDR=<optional>
# BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR=<optional>
# ALIGNED_SM_HOLESKY_ETH_ADDR=<optional>

## You can choose to use a keystore or private key for your signing wallet.
## Leave empty if choosing Anvil Devnet.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ submit_account:
gen_contract_abis:
forge build --root contract/
forge build --root example/eth_contract
cp contract/out/MinaBridge.sol/MinaBridge.json core/abi/MinaBridge.json
cp contract/out/MinaStateSettlement.sol/MinaStateSettlement.json core/abi/MinaStateSettlement.json
cp contract/out/MinaAccountValidation.sol/MinaAccountValidation.json core/abi/MinaAccountValidation.json
cp example/eth_contract/out/SudokuValidity.sol/SudokuValidity.json example/app/abi/SudokuValidity.json

Expand Down
268 changes: 164 additions & 104 deletions README.md

Large diffs are not rendered by default.

33 changes: 0 additions & 33 deletions contract/script/MinaBridge.s.sol

This file was deleted.

42 changes: 25 additions & 17 deletions contract/src/MinaAccountValidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ pragma solidity ^0.8.12;

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

error MinaAccountProvingSystemIdIsNotValid(); // c1872967

contract MinaAccountValidation {
/// @notice The commitment to Mina Account proving system ID.
bytes32 constant PROVING_SYSTEM_ID_COMM = 0xd33e25809fcaa2b6900567812852539da8559dc8b76a7ce3fc5ddd77e8d19a69;

struct AlignedArgs {
bytes32 proofCommitment;
bytes32 provingSystemAuxDataCommitment;
Expand All @@ -22,27 +27,30 @@ contract MinaAccountValidation {
aligned = AlignedLayerServiceManager(_alignedServiceAddr);
}

function validateAccount(
AlignedArgs calldata args
) external view returns (bool) {
function validateAccount(AlignedArgs calldata args) external view returns (bool) {
if (args.provingSystemAuxDataCommitment != PROVING_SYSTEM_ID_COMM) {
revert MinaAccountProvingSystemIdIsNotValid();
}

bytes32 pubInputCommitment = keccak256(args.pubInput);

return
aligned.verifyBatchInclusion(
args.proofCommitment,
pubInputCommitment,
args.provingSystemAuxDataCommitment,
args.proofGeneratorAddr,
args.batchMerkleRoot,
args.merkleProof,
args.verificationDataBatchIndex,
args.batcherPaymentService
);
return aligned.verifyBatchInclusion(
args.proofCommitment,
pubInputCommitment,
args.provingSystemAuxDataCommitment,
args.proofGeneratorAddr,
args.batchMerkleRoot,
args.merkleProof,
args.verificationDataBatchIndex,
args.batcherPaymentService
);
}

function validateAccountAndReturn(
AlignedArgs calldata args
) external view returns (Account memory) {
function validateAccountAndReturn(AlignedArgs calldata args) external view returns (Account memory) {
if (args.provingSystemAuxDataCommitment != PROVING_SYSTEM_ID_COMM) {
revert MinaAccountProvingSystemIdIsNotValid();
}

bytes32 pubInputCommitment = keccak256(args.pubInput);

bool isAccountVerified = aligned.verifyBatchInclusion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ 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 AccountIsNotValid(bytes32 accountIdHash);

/// @title Mina to Ethereum Bridge's smart contract.
contract MinaBridge {
/// @title Mina to Ethereum Bridge's smart contract for verifying and storing a valid state chain.
contract MinaStateSettlement {
/// @notice The commitment to Mina proving system ID.
bytes32 constant PROVING_SYSTEM_ID_COMM = 0xee2a4bc7db81da2b7164e56b3649b1e2a09c58c455b15dabddd9146c7582cebc;

/// @notice The length of the verified state chain (also called the bridge's transition
/// frontier) to store.
uint256 public constant BRIDGE_TRANSITION_FRONTIER_LEN = 16;
Expand Down Expand Up @@ -39,30 +43,19 @@ contract MinaBridge {
}

/// @notice Returns the latest verified chain state hashes.
function getChainStateHashes()
external
view
returns (bytes32[BRIDGE_TRANSITION_FRONTIER_LEN] memory)
{
function getChainStateHashes() external view returns (bytes32[BRIDGE_TRANSITION_FRONTIER_LEN] memory) {
return chainStateHashes;
}

/// @notice Returns the latest verified chain ledger hashes.
function getChainLedgerHashes()
external
view
returns (bytes32[BRIDGE_TRANSITION_FRONTIER_LEN] memory)
{
function getChainLedgerHashes() external view returns (bytes32[BRIDGE_TRANSITION_FRONTIER_LEN] memory) {
return chainLedgerHashes;
}

/// @notice Returns true if this snarked ledger hash was bridged.
function isLedgerVerified(bytes32 ledgerHash) external view returns (bool) {
for (uint256 i = 0; i < BRIDGE_TRANSITION_FRONTIER_LEN; i++) {
if (
chainLedgerHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1 - i] ==
ledgerHash
) {
if (chainLedgerHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1 - i] == ledgerHash) {
return true;
}
}
Expand All @@ -79,19 +72,17 @@ contract MinaBridge {
bytes memory pubInput,
address batcherPaymentService
) external {
if (provingSystemAuxDataCommitment != PROVING_SYSTEM_ID_COMM) {
revert MinaProvingSystemIdIsNotValid(provingSystemAuxDataCommitment);
}

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

if (
pubInputBridgeTipStateHash !=
chainStateHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1]
) {
revert TipStateIsWrong(
pubInputBridgeTipStateHash,
chainStateHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1]
);
if (pubInputBridgeTipStateHash != chainStateHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1]) {
revert TipStateIsWrong(pubInputBridgeTipStateHash, chainStateHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1]);
}

bytes32 pubInputCommitment = keccak256(pubInput);
Expand All @@ -118,16 +109,9 @@ contract MinaBridge {
// the next BRIDGE_TRANSITION_FRONTIER_LEN sets of 32 bytes are state hashes.
let addr_states := add(pubInput, 64)
// 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)
)

for {
let i := 0
} lt(i, BRIDGE_TRANSITION_FRONTIER_LEN) {
i := add(i, 1)
} {
let addr_ledgers := add(addr_states, mul(32, BRIDGE_TRANSITION_FRONTIER_LEN))

for { let i := 0 } lt(i, BRIDGE_TRANSITION_FRONTIER_LEN) { i := add(i, 1) } {
sstore(slot_states, mload(addr_states))
addr_states := add(addr_states, 32)
slot_states := add(slot_states, 1)
Expand Down
16 changes: 0 additions & 16 deletions contract/test/MinaBridge.t.sol

This file was deleted.

33 changes: 15 additions & 18 deletions contract_deployer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use aligned_sdk::core::types::Chain;
use log::{debug, error, info};
use mina_bridge_core::{
eth::{
deploy_mina_account_validation_contract, deploy_mina_bridge_contract,
MinaAccountValidationConstructorArgs, MinaBridgeConstructorArgs, SolStateHash,
MinaAccountValidationConstructorArgs, MinaStateSettlementConstructorArgs, SolStateHash,
},
mina::query_root,
utils::{
constants::{
ALIGNED_SM_DEVNET_ETH_ADDR, ALIGNED_SM_HOLESKY_ETH_ADDR, BRIDGE_TRANSITION_FRONTIER_LEN,
},
env::EnvironmentVariables,
wallet_alloy::get_wallet,
constants::BRIDGE_TRANSITION_FRONTIER_LEN, contract::get_aligned_sm_contract_addr,
env::EnvironmentVariables, wallet_alloy::get_wallet,
},
};
use std::process;
Expand Down Expand Up @@ -47,18 +43,19 @@ async fn main() {
process::exit(1);
});

let aligned_sm_addr = match chain {
Chain::Devnet => ALIGNED_SM_DEVNET_ETH_ADDR,
Chain::Holesky => ALIGNED_SM_HOLESKY_ETH_ADDR,
_ => todo!(),
};
let aligned_sm_addr = get_aligned_sm_contract_addr(&chain).unwrap_or_else(|err| {
error!("{err}");
process::exit(1);
});

let bridge_constructor_args = MinaBridgeConstructorArgs::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)
let bridge_constructor_args =
MinaStateSettlementConstructorArgs::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| {
error!("Failed to make constructor args for account contract call: {err}");
process::exit(1);
Expand Down
2 changes: 1 addition & 1 deletion core/abi/MinaAccountValidation.json

Large diffs are not rendered by default.

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

This file was deleted.

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

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion core/src/aligned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ pub async fn submit(
proving_system,
proof,
pub_input: Some(pub_input),
verification_key: None,
// Use this instead of `None` to force Aligned to include the commitment to the proving system ID (valid for Aligned 0.7.0)
verification_key: Some(vec![]),
vm_program_code: None,
proof_generator_addr,
};
Expand Down
Loading

0 comments on commit 152292b

Please sign in to comment.