Skip to content

Commit

Permalink
Update Aligned to 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Sep 20, 2024
1 parent f838916 commit fd62b01
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 29 deletions.
39 changes: 21 additions & 18 deletions contract/src/MinaAccountValidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,38 @@ import "aligned_layer/contracts/src/core/AlignedLayerServiceManager.sol";
error AccountIsNotVerified();

contract MinaAccountValidation {
struct AlignedArgs {
bytes32 proofCommitment;
bytes32 provingSystemAuxDataCommitment;
bytes20 proofGeneratorAddr;
bytes32 batchMerkleRoot;
bytes merkleProof;
uint256 verificationDataBatchIndex;
bytes pubInput;
address batcherPaymentService;
}

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

constructor(address payable _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:];
function validateAccount(AlignedArgs calldata args) external view returns (Account memory) {
bytes calldata encodedAccount = args.pubInput[32 + 8:];

bytes32 pubInputCommitment = keccak256(pubInput);
bytes32 pubInputCommitment = keccak256(args.pubInput);

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

if (isAccountVerified) {
Expand Down
2 changes: 1 addition & 1 deletion contract_deployer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contract_deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ethers = { tag = "v2.0.15-fix-reconnections", features = [
mina-curves = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes-rampup4-vrf" }
o1-utils = { git = "https://github.com/lambdaclass/proof-systems", branch = "add-verifier-serializations" }
kimchi = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes-rampup4-vrf" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "update_to_0_7" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "update_to_0_7_for_real" }
serde = { version = "1.0", features = ["derive"] }
mina-p2p-messages = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
bincode = "1.3.3"
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ark-poly = { version = "0.3.0", features = ["parallel"] }
ark-serialize = "0.3.0"
mina-tree = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
mina-p2p-messages = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "update_to_0_7" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "update_to_0_7_for_real" }
ethers = { tag = "v2.0.15-fix-reconnections", features = [
"ws",
"rustls",
Expand Down
2 changes: 1 addition & 1 deletion core/abi/MinaAccountValidation.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/abi/MinaBridge.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async fn main() {
&chain,
&eth_rpc_url,
wallet,
&batcher_eth_addr,
)
.await
.unwrap_or_else(|err| {
Expand Down Expand Up @@ -132,6 +133,7 @@ async fn main() {
&pub_input,
&chain,
&eth_rpc_url,
&batcher_eth_addr,
)
.await
{
Expand Down
20 changes: 16 additions & 4 deletions core/src/smart_contract_utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub async fn update_chain(
chain: &Chain,
eth_rpc_url: &str,
wallet: Wallet<SigningKey>,
batcher_payment_service: &str,
) -> Result<(), String> {
let bridge_eth_addr = Address::from_str(match chain {
Chain::Devnet => BRIDGE_DEVNET_ETH_ADDR,
Expand All @@ -108,6 +109,9 @@ pub async fn update_chain(
let serialized_pub_input = bincode::serialize(pub_input)
.map_err(|err| format!("Failed to serialize public inputs: {err}"))?;

let batcher_payment_service = Address::from_str(batcher_payment_service)
.map_err(|err| format!("Failed to parse batcher payment service address: {err}"))?;

debug!("Creating contract instance");
let mina_bridge_contract = mina_bridge_contract(eth_rpc_url, bridge_eth_addr, chain, wallet)?;

Expand Down Expand Up @@ -141,6 +145,7 @@ pub async fn update_chain(
merkle_proof,
index_in_batch.into(),
serialized_pub_input.into(),
batcher_payment_service,
);
// update call reverts if batch is not valid or proof isn't included in it.

Expand Down Expand Up @@ -258,6 +263,7 @@ pub async fn validate_account(
pub_input: &MinaAccountPubInputs,
chain: &Chain,
eth_rpc_url: &str,
batcher_payment_service: &str,
) -> Result<Account, String> {
let bridge_eth_addr = Address::from_str(match chain {
Chain::Devnet => BRIDGE_ACCOUNT_DEVNET_ETH_ADDR,
Expand All @@ -275,6 +281,9 @@ pub async fn validate_account(
let serialized_pub_input = bincode::serialize(pub_input)
.map_err(|err| format!("Failed to serialize public inputs: {err}"))?;

let batcher_payment_service = Address::from_str(batcher_payment_service)
.map_err(|err| format!("Failed to parse batcher payment service address: {err}"))?;

let AlignedVerificationData {
verification_data_commitment,
batch_merkle_root,
Expand All @@ -298,15 +307,18 @@ pub async fn validate_account(

debug!("Validating account");

let call = contract.validate_account(
let aligned_args = AlignedArgs {
proof_commitment,
proving_system_aux_data_commitment,
proof_generator_addr,
batch_merkle_root,
merkle_proof,
index_in_batch.into(),
serialized_pub_input.into(),
);
verification_data_batch_index: index_in_batch.into(),
pub_input: serialized_pub_input.into(),
batcher_payment_service,
};

let call = contract.validate_account(aligned_args);

info!(
"Estimated account verification gas cost: {}",
Expand Down

0 comments on commit fd62b01

Please sign in to comment.