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

Add Solidity-friendly account structure as public input for the account inclusion proof #334

Merged
merged 68 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
d2e9e1b
Added merkle query
xqft Aug 13, 2024
76a145c
Rename query_and_serialize
xqft Aug 13, 2024
74bd49c
WIP merkle query
xqft Aug 13, 2024
2fc721d
Fix test
xqft Aug 14, 2024
4d9e50a
WIP Account query
xqft Aug 15, 2024
ac3769e
Finished account query
xqft Aug 15, 2024
83976a6
Fixed TokenId deserialization
xqft Aug 16, 2024
b7f4556
Remove account query
xqft Aug 19, 2024
0aa33f7
Merge branch 'aligned' into account_inclusion_check
xqft Aug 19, 2024
c763f6e
Fix clippy
xqft Aug 19, 2024
5e7b214
Removed account_inclusion crate
xqft Aug 19, 2024
cd28a42
Take into account mina account proofs
xqft Aug 20, 2024
605439c
Add CLI commands
xqft Aug 20, 2024
3c6ad97
Implement submission code for account proof
xqft Aug 20, 2024
d944c61
Add ledger hash to state verifier
xqft Aug 21, 2024
e393f51
Add accountIdHash and account verification feature for smart contract
xqft Aug 22, 2024
19bd76e
Add eth call for update account
xqft Aug 22, 2024
1a560a6
Fix clippy
xqft Aug 22, 2024
8901348
Update makefile rules
xqft Aug 22, 2024
a42dcf4
Update specification
xqft Aug 22, 2024
2c2f3ba
Added doc to smart contract
xqft Aug 22, 2024
b5e269d
Fix clippy
xqft Aug 23, 2024
e0e3f82
Update README.md
xqft Aug 23, 2024
8db0817
Query candidate chain, use bincode
xqft Aug 23, 2024
5952835
Update Makefile
xqft Aug 26, 2024
9a17497
Merge branch 'aligned' into account_inclusion_verifier
xqft Aug 26, 2024
1f80e33
Fix aligned sdk git dependency
xqft Aug 26, 2024
b6a1b7b
Update cargo.lock
xqft Aug 26, 2024
ead94ff
Merge branch 'account_inclusion_verifier' into relative_finalization
xqft Aug 26, 2024
e05d17f
Define new state proof, serialize with bincode
xqft Aug 26, 2024
e01914b
Change proof field types
xqft Aug 26, 2024
38e1437
Refactor proof definition
xqft Aug 26, 2024
fc75962
Add entire states to Mina state proof
xqft Aug 28, 2024
bf627d1
Change version of clap to work with aligned
xqft Aug 29, 2024
cfd4cb6
Fix tip state
xqft Aug 29, 2024
fd35991
Change core crate name
xqft Aug 29, 2024
844f732
Make serialization mod public
xqft Aug 29, 2024
4d25a6e
Add contract support for relative finalization
xqft Aug 29, 2024
d8bea9d
Fixed smart contract update function
xqft Aug 30, 2024
80f23ee
Merge branch 'aligned' into relative_finalization
xqft Aug 30, 2024
11ef31a
Check state hashes
xqft Sep 2, 2024
bd05fb2
Fix hash store
xqft Sep 2, 2024
9302208
Fix clippy
xqft Sep 2, 2024
807090d
Remove account hash from contract storage
xqft Sep 2, 2024
242522b
Fix clippy
xqft Sep 2, 2024
d5e1336
New account proof WIP
xqft Sep 3, 2024
fea0e6a
Finish new account proof
xqft Sep 3, 2024
921489b
Remove unused dependencies
xqft Sep 3, 2024
7663f13
Add new schema
xqft Sep 3, 2024
2e80898
Intergrate new account query schema
xqft Sep 4, 2024
a19a11b
Change mina proof to store account
xqft Sep 4, 2024
5111043
Replace ledger hash with Fp
xqft Sep 4, 2024
55eccf2
Update comment
xqft Sep 5, 2024
cff1a7b
Fix variable name
xqft Sep 5, 2024
a4f22c2
Change staged ledger hash to snarked
xqft Sep 5, 2024
e8d4c56
Fix clippy
xqft Sep 5, 2024
a763b1d
Merge branch 'aligned' into new_account_proof
xqft Sep 5, 2024
7a9e3e4
MinaAccountValidation lib
xqft Sep 6, 2024
37807eb
Gen abi of new lib
xqft Sep 6, 2024
3be61b1
Add Mina account solidity struct
xqft Sep 9, 2024
92f1a9f
Update contract
xqft Sep 9, 2024
253894e
Refactor serialization, add account conversion
xqft Sep 9, 2024
46e3a06
Doc
xqft Sep 10, 2024
7decbf8
Change mina account proof to use encoded account
xqft Sep 10, 2024
ce01a95
Readd mina account in proof
xqft Sep 10, 2024
3e4bc40
Merge branch 'aligned' into account_keccak_hash
xqft Sep 10, 2024
9bd55ed
Handle new proof in smart contract
xqft Sep 11, 2024
d64d6cf
Fix contract
xqft Sep 12, 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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ submit_account:
gen_contract_abi:
forge build --root contract/
cp contract/out/MinaBridge.sol/MinaBridge.json core/abi/MinaBridge.json
cp contract/out/MinaAccountValidation.sol/MinaAccountValidation.json core/abi/MinaAccountValidation.json

deploy_contract: gen_contract_abi
@cargo run --manifest-path contract_deployer/Cargo.toml --release
32 changes: 0 additions & 32 deletions contract/src/Account.sol

This file was deleted.

135 changes: 135 additions & 0 deletions contract/src/MinaAccountValidation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;

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

error AccountIsNotVerified();

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

constructor(address _alignedServiceAddr) {
aligned = AlignedLayerServiceManager(_alignedServiceAddr);
}

function validateAccount(
bytes32 proofCommitment,
bytes32 provingSystemAuxDataCommitment,
bytes20 proofGeneratorAddr,
bytes32 batchMerkleRoot,
bytes memory merkleProof,
uint256 verificationDataBatchIndex,
bytes calldata pubInput
) external view returns (Account memory) {
bytes calldata encodedAccount = pubInput[32 + 8:];

bytes32 pubInputCommitment = keccak256(pubInput);

bool isAccountVerified = aligned.verifyBatchInclusion(
proofCommitment,
pubInputCommitment,
provingSystemAuxDataCommitment,
proofGeneratorAddr,
batchMerkleRoot,
merkleProof,
verificationDataBatchIndex
);

if (isAccountVerified) {
return abi.decode(encodedAccount, (Account));
} else {
revert AccountIsNotVerified();
}
}

struct Account {
CompressedECPoint publicKey;
bytes32 tokenIdKeyHash;
string tokenSymbol;
uint64 balance;
uint32 nonce;
bytes32 receiptChainHash;
CompressedECPoint delegate;
bytes32 votingFor;
Timing timing;
Permissions permissions;
ZkappAccount zkapp;
}

struct CompressedECPoint {
bytes32 x;
bool isOdd;
}

struct Timing {
uint64 initialMinimumBalance;
uint32 cliffTime;
uint64 cliffAmount;
uint32 vestingPeriod;
uint64 vestingIncrement;
}

enum AuthRequired {
None,
Either,
Proof,
Signature,
Impossible
}

struct Permissions {
AuthRequired editState;
AuthRequired access;
AuthRequired send;
AuthRequired rreceive;
AuthRequired setDelegate;
AuthRequired setPermissions;
AuthRequired setVerificationKeyAuth;
uint32 setVerificationKeyUint;
AuthRequired setZkappUri;
AuthRequired editActionState;
AuthRequired setTokenSymbol;
AuthRequired incrementNonce;
AuthRequired setVotingFor;
AuthRequired setTiming;
}

struct ZkappAccount {
bytes32[8] appState;
VerificationKey verificationKey;
uint32 zkappVersion;
bytes32[5] actionState;
uint32 lastActionSlot;
bool provedState;
bytes zkappUri;
}

struct VerificationKey {
ProofsVerified maxProofsVerified;
ProofsVerified actualWrapDomainSize;
WrapIndex wrapIndex;
}

enum ProofsVerified {
N0,
N1,
N2
}

struct WrapIndex {
Commitment[7] sigmaComm;
Commitment[15] coefficientsComm;
Commitment genericComm;
Commitment psmComm;
Commitment completeAddComm;
Commitment mulComm;
Commitment emulComm;
Commitment endomulScalarComm;
}

struct Commitment {
bytes32 x;
bytes32 y;
}
}
33 changes: 0 additions & 33 deletions contract/src/MinaBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.12;

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

error NewStateIsNotValid();
error TipStateIsWrong(bytes32 pubInputTipStateHash, bytes32 tipStatehash);
Expand Down Expand Up @@ -127,36 +126,4 @@ contract MinaBridge {
revert NewStateIsNotValid();
}
}

function isAccountVerified(
bytes32 proofCommitment,
bytes32 provingSystemAuxDataCommitment,
bytes20 proofGeneratorAddr,
bytes32 batchMerkleRoot,
bytes memory merkleProof,
uint256 verificationDataBatchIndex,
bytes memory pubInput
) external view returns (bool) {
bytes32 ledgerHash;
bytes32 accountHash;
bytes32 accountIdHash;
assembly {
ledgerHash := mload(add(pubInput, 0x20))
accountHash := mload(add(pubInput, 0x40))
accountIdHash := mload(add(pubInput, 0x60))
}

bytes32 pubInputCommitment = keccak256(pubInput);

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