Skip to content

Commit e46ebfb

Browse files
committed
refactor: change storage to merkle_root=>bool in AlignedProofAggregationService.sol
1 parent 97df060 commit e46ebfb

File tree

3 files changed

+15
-64
lines changed

3 files changed

+15
-64
lines changed

contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

contracts/src/core/AlignedProofAggregationService.sol

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ contract AlignedProofAggregationService is
1313
OwnableUpgradeable,
1414
UUPSUpgradeable
1515
{
16-
/// @notice Maps the aggregated verification merkle root with the blob transaction hash that contains the leaves
17-
uint64 public currentAggregatedProofNumber;
18-
mapping(uint64 => AggregatedProof) public aggregatedProofs;
16+
17+
/// @notice Map the merkle root to a boolean to indicate it was verified
18+
mapping(bytes32 => bool) public aggregatedProofs;
1919

2020
/// @notice The address of the SP1 verifier contract.
2121
/// @dev This can either be a specific SP1Verifier for a specific version, or the
@@ -24,6 +24,7 @@ contract AlignedProofAggregationService is
2424
/// https://docs.succinct.xyz/onchain-verification/contract-addresses
2525
address public sp1VerifierAddress;
2626

27+
/// @notice The address of the Wallet that is allowed to call the verify function.
2728
address public alignedAggregatorAddress;
2829

2930
/// @notice whether we are in dev mode or not
@@ -51,43 +52,19 @@ contract AlignedProofAggregationService is
5152
bytes calldata sp1PublicValues,
5253
bytes calldata sp1ProofBytes
5354
) public onlyAlignedAggregator {
54-
// In dev mode, poofs are mocked, so we skip the verification part
55-
if (sp1VerifierAddress == VERIFIER_MOCK_ADDRESS) {
56-
(bytes32 merkleRoot) = abi.decode(sp1PublicValues, (bytes32));
57-
_newAggregatedProof(merkleRoot, blobVersionedHash);
58-
return;
59-
}
55+
(bytes32 merkleRoot) = abi.decode(sp1PublicValues, (bytes32));
6056

61-
try ISP1Verifier(sp1VerifierAddress).verifyProof(sp1ProgramVKey, sp1PublicValues, sp1ProofBytes) {
62-
(bytes32 merkleRoot) = abi.decode(sp1PublicValues, (bytes32));
63-
_newAggregatedProof(merkleRoot, blobVersionedHash);
64-
} catch {
65-
AggregatedProof storage proof = aggregatedProofs[currentAggregatedProofNumber];
66-
proof.status = AggregatedProofStatus.Failed;
67-
emit NewAggregatedProof(currentAggregatedProofNumber, AggregatedProofStatus.Failed, 0x0, 0x0);
68-
currentAggregatedProofNumber += 1;
57+
// In dev mode, poofs are mocked, so we skip the verification part
58+
if (_isVerificationEnabled()) {
59+
ISP1Verifier(sp1VerifierAddress).verifyProof(sp1ProgramVKey, sp1PublicValues, sp1ProofBytes);
6960
}
70-
}
71-
72-
function markCurrentAggregatedProofAsMissed() public onlyAlignedAggregator {
73-
AggregatedProof storage proof = aggregatedProofs[currentAggregatedProofNumber];
74-
proof.status = AggregatedProofStatus.Missed;
75-
emit NewAggregatedProof(currentAggregatedProofNumber, AggregatedProofStatus.Missed, 0x0, 0x0);
76-
currentAggregatedProofNumber += 1;
77-
}
7861

79-
function _newAggregatedProof(bytes32 merkleRoot, bytes32 blobHash) internal {
80-
AggregatedProof storage proof = aggregatedProofs[currentAggregatedProofNumber];
81-
proof.merkleRoot = merkleRoot;
82-
proof.blobHash = blobHash;
83-
proof.status = AggregatedProofStatus.Verified;
84-
emit NewAggregatedProof(currentAggregatedProofNumber, AggregatedProofStatus.Verified, merkleRoot, blobHash);
85-
currentAggregatedProofNumber += 1;
62+
aggregatedProofs[merkleRoot] = true;
63+
emit AggregatedProofVerified(merkleRoot, blobVersionedHash);
8664
}
8765

88-
function getAggregatedProof(uint64 proofNumber) public view returns (uint8, bytes32 blobHash, bytes32 merkleRoot) {
89-
AggregatedProof storage proof = aggregatedProofs[proofNumber];
90-
return (uint8(proof.status), proof.blobHash, proof.merkleRoot);
66+
function _isVerificationEnabled() internal view returns (bool) {
67+
return sp1VerifierAddress != VERIFIER_MOCK_ADDRESS;
9168
}
9269

9370
function _authorizeUpgrade(address newImplementation)

contracts/src/core/IAlignedProofAggregationService.sol

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
pragma solidity ^0.8.12;
22

33
interface IAlignedProofAggregationService {
4-
/// @notice aggregated proof status
5-
/// Verified -> Verification was successful
6-
/// Failed -> Verification failed
7-
/// Missed -> Internal error in the aligned service could not send the aggregated proof to verify
8-
enum AggregatedProofStatus {
9-
Verified,
10-
Failed,
11-
Missed
12-
}
13-
14-
/// @notice aggregated proof
15-
/// Status -> proof status
16-
/// blobHash -> the hash of the blob transaction containing the hashes of all the proofs that have been aggregated
17-
/// merkleRoot -> the committed merkle root in the aggregated
18-
struct AggregatedProof {
19-
AggregatedProofStatus status;
20-
bytes32 blobHash;
21-
bytes32 merkleRoot;
22-
}
234

245
/// @notice Method to verify an aggregated proof from aligned
256
/// @dev This function is called by the aligned proof aggregator after collecting the proofs and aggregating them
@@ -35,16 +16,9 @@ interface IAlignedProofAggregationService {
3516
bytes calldata sp1ProofBytes
3617
) external;
3718

38-
function getAggregatedProof(uint64 proofNumber)
39-
external
40-
view
41-
returns (uint8 status, bytes32 blobHash, bytes32 merkleRoot);
42-
43-
function markCurrentAggregatedProofAsMissed() external;
44-
4519
/// @notice event that gets emitted after a successful aggregated proof verification
46-
event NewAggregatedProof(
47-
uint64 indexed proofNumber, AggregatedProofStatus status, bytes32 merkleRoot, bytes32 blobVersionedHash
20+
event AggregatedProofVerified(
21+
bytes32 indexed merkleRoot, bytes32 blobVersionedHash
4822
);
4923

5024
error OnlyAlignedAggregator(address sender);

0 commit comments

Comments
 (0)