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

Sudoku example app #338

Merged
merged 52 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
24f5c8b
Init bun project
xqft Sep 13, 2024
3a4f67c
Refactor
xqft Sep 16, 2024
4428ad2
chore: forge init
xqft Sep 16, 2024
4620db5
forge install: forge-std
xqft Sep 16, 2024
f2c5af6
Rename Counter to Sudoku
xqft Sep 16, 2024
5d951e6
forge install: mina_bridge
xqft Sep 16, 2024
0100e5c
Contract mockup
xqft Sep 16, 2024
0ed9e49
Merge branch 'aligned' into app
xqft Sep 16, 2024
049fd80
Add remappings, fix version
xqft Sep 17, 2024
5f68c55
Remove unused files, add contract constructor
xqft Sep 17, 2024
6369e7b
Remove mina_bridge submodule
xqft Sep 17, 2024
bd6428f
Rename zkapp
xqft Sep 17, 2024
6f4a99c
Rename app to example
xqft Sep 17, 2024
526c0fd
forge install: forge-std
xqft Sep 17, 2024
9d1b997
Created Rust app project
xqft Sep 17, 2024
b548235
zkApp script
xqft Sep 17, 2024
cfdf9b2
Merge branch 'aligned' into app
xqft Sep 17, 2024
de8c28a
Fiz zkapp script
xqft Sep 18, 2024
075f441
Core refactor
xqft Sep 18, 2024
75b0042
Add sdk
xqft Sep 19, 2024
ac8bced
Complete app
xqft Sep 19, 2024
d111d6a
Change zkapp address to constant
xqft Sep 19, 2024
74ba553
Updated rust app
xqft Sep 19, 2024
4569fd9
Rename mina_contract to mina_zkapp
xqft Sep 19, 2024
be56c38
Completed sudoku eth contract
xqft Sep 19, 2024
f838916
[WIP] Update Aligned to 0.7.0
gabrielbosio Sep 19, 2024
fd62b01
Update Aligned to 0.7.0
gabrielbosio Sep 20, 2024
8e3673f
Update Aligned branch
gabrielbosio Sep 20, 2024
d772516
Finish sudoku contract deployer
xqft Sep 20, 2024
3af5b5b
Rename sudoku contract
xqft Sep 20, 2024
614115f
Fix contract deployer
xqft Sep 20, 2024
41593b3
Update Aligned and Bridge contracts
gabrielbosio Sep 20, 2024
066a86d
Update Aligned Foundry submodule
gabrielbosio Sep 20, 2024
8369928
Add call to SudokuValidity, small fixes to contract
xqft Sep 20, 2024
c5d1327
Update makefile
xqft Sep 20, 2024
4fbd95c
Add better log and getter function for timestamp
xqft Sep 20, 2024
4c21c35
Fix contract validateAccount call
xqft Sep 20, 2024
36822a6
Add retrying logic for mina zkapp
xqft Sep 23, 2024
cad1f56
Fix Makefile
xqft Sep 23, 2024
591a593
Zkapp fixes
xqft Sep 23, 2024
983dbf4
Fix ledger hash search
xqft Sep 23, 2024
69a7358
Add log
xqft Sep 23, 2024
c7f2709
Fix boolean comparison
xqft Sep 23, 2024
e31b797
Add debug to query_candidate_chain()
xqft Sep 23, 2024
b3a58e9
Update app
xqft Sep 23, 2024
8f699d5
Update to aligned 0.7
xqft Sep 24, 2024
238d66d
Merge branch 'aligned_0_7' into app
xqft Sep 24, 2024
e722d2a
Update constants
xqft Sep 24, 2024
163d647
Change zkapp config
xqft Sep 24, 2024
de28c9d
Merge branch 'aligned' into app
xqft Sep 25, 2024
44c1c81
Fix clippy
xqft Sep 25, 2024
b02c2ba
Add example diagram
xqft Sep 25, 2024
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
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
28 changes: 22 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,27 @@ 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 +57,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