Skip to content

Commit

Permalink
Add batcher addr and group args in struct
Browse files Browse the repository at this point in the history
This is because of StackTooDeepException in Solidity.
  • Loading branch information
gabrielbosio committed Sep 17, 2024
1 parent 0e5bf06 commit a0a7623
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
40 changes: 21 additions & 19 deletions contract/src/MinaAccountValidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +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 batcherPaymentServiceAddr;
}

/// @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,
address batcherPaymentServiceAddress
) 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,
batcherPaymentServiceAddress
args.provingSystemAuxDataCommitment,
args.proofGeneratorAddr,
args.batchMerkleRoot,
args.merkleProof,
args.verificationDataBatchIndex,
args.batcherPaymentServiceAddr
);

if (isAccountVerified) {
Expand Down
2 changes: 1 addition & 1 deletion core/abi/MinaAccountValidation.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ async fn main() {
&pub_input,
&chain,
&eth_rpc_url,
&batcher_eth_addr,
)
.await
{
Expand Down
16 changes: 9 additions & 7 deletions core/src/smart_contract_utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub async fn validate_account(
pub_input: &MinaAccountPubInputs,
chain: &Chain,
eth_rpc_url: &str,
batcher_eth_addr: &str,
batcher_payment_service_addr: &str,
) -> Result<Account, String> {
let bridge_eth_addr = Address::from_str(match chain {
Chain::Devnet => BRIDGE_ACCOUNT_DEVNET_ETH_ADDR,
Expand Down Expand Up @@ -302,21 +302,23 @@ pub async fn validate_account(
..
} = verification_data_commitment;

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

debug!("Validating account");

let call = contract.validate_account(
let 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(),
batcher_eth_addr,
);
verification_data_batch_index: index_in_batch.into(),
pub_input: serialized_pub_input.into(),
batcher_payment_service_addr,
};

let call = contract.validate_account(args);

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

0 comments on commit a0a7623

Please sign in to comment.