Skip to content

Commit

Permalink
Merge branch 'aligned' into parameterize_contract_addr
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Sep 25, 2024
2 parents 81d486e + 48e5c43 commit f346d39
Show file tree
Hide file tree
Showing 56 changed files with 17,572 additions and 207 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
[submodule "contract/lib/aligned_layer"]
path = contract/lib/aligned_layer
url = https://github.com/lambdaclass/aligned_layer
[submodule "app/eth_contract/lib/forge-std"]
path = app/eth_contract/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "example/eth_contract/lib/forge-std"]
path = example/eth_contract/lib/forge-std
url = https://github.com/foundry-rs/forge-std
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ submit_state:
submit_account:
@cargo run --manifest-path core/Cargo.toml --release -- submit-account ${PUBLIC_KEY} ${STATE_HASH}

gen_contract_abi:
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/MinaAccountValidation.sol/MinaAccountValidation.json core/abi/MinaAccountValidation.json
cp example/eth_contract/out/SudokuValidity.sol/SudokuValidity.json example/app/abi/SudokuValidity.json

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

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

execute_example:
cd example/mina_zkapp; \
npm run build; \
node build/src/run.js
cargo run --manifest-path example/app/Cargo.toml --release -- validate-solution
2 changes: 1 addition & 1 deletion contract/lib/aligned_layer
Submodule aligned_layer updated 211 files
23 changes: 17 additions & 6 deletions contract/src/MinaAccountValidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pragma solidity ^0.8.12;

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

error AccountIsNotVerified();

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

function validateAccount(AlignedArgs calldata args) external view returns (Account memory) {
bytes calldata encodedAccount = args.pubInput[32 + 8:];
function validateAccount(AlignedArgs calldata args) external view returns (bool) {
bytes32 pubInputCommitment = keccak256(args.pubInput);

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) {
bytes32 pubInputCommitment = keccak256(args.pubInput);

bool isAccountVerified = aligned.verifyBatchInclusion(
Expand All @@ -41,9 +52,9 @@ contract MinaAccountValidation {
);

if (isAccountVerified) {
return abi.decode(encodedAccount, (Account));
return abi.decode(args.pubInput[32 + 8:], (Account));
} else {
revert AccountIsNotVerified();
revert();
}
}

Expand Down
48 changes: 41 additions & 7 deletions contract/src/MinaBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,36 @@ 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
) {
return true;
}
}
return false;
}

function updateChain(
bytes32 proofCommitment,
bytes32 provingSystemAuxDataCommitment,
Expand All @@ -63,8 +84,14 @@ contract MinaBridge {
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 @@ -91,9 +118,16 @@ 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
Loading

0 comments on commit f346d39

Please sign in to comment.