Skip to content

Add monotonic counter for submitted claims#479

Merged
henriquemarlon merged 1 commit intomainfrom
feat/claim-submission-counter
Jan 20, 2026
Merged

Add monotonic counter for submitted claims#479
henriquemarlon merged 1 commit intomainfrom
feat/claim-submission-counter

Conversation

@henriquemarlon
Copy link
Contributor

@henriquemarlon henriquemarlon commented Jan 16, 2026

Added getNumberOfSubmittedClaims() to IConsensus interface to expose a monotonic counter of submitted claims, as described in #478

Behavior:

  • Authority: 1 submission/increment per epoch, resubmission reverts;
  • Quorum: 1 submission/increment per validator per epoch, same validator resubmission is silently ignored;

( I’ve also updated the tests ).

@henriquemarlon henriquemarlon force-pushed the feat/claim-submission-counter branch 2 times, most recently from 16c1155 to 6c49df1 Compare January 16, 2026 18:54
@henriquemarlon henriquemarlon requested review from Copilot and guidanoli and removed request for guidanoli, pedroargento and vfusco January 16, 2026 21:56
@henriquemarlon henriquemarlon requested review from guidanoli, pedroargento and vfusco and removed request for Copilot January 16, 2026 21:57
Copy link
Contributor

@ZzzzHui ZzzzHui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great

Comment on lines +140 to +156
function testSubmittedClaimsCounter(bytes32[] calldata claims) public {
address owner = vm.addr(1);
address app = vm.addr(2);
uint256 epochLength = 5;

IAuthority authority = new Authority(owner, epochLength);

assertEq(authority.getNumberOfSubmittedClaims(), 0);

for (uint256 i; i < claims.length; ++i) {
uint256 blockNum = (i + 1) * epochLength;
vm.roll(blockNum);

vm.prank(owner);
authority.submitClaim(app, blockNum - 1, claims[i]);

assertEq(authority.getNumberOfSubmittedClaims(), i + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block seems redundant? The behaviour is already tested in line 136, right?
More tests can be added following how authority.getNumberOfAcceptedClaims() was tested and add one more line to test authority.getNumberOfSubmittedClaims() there :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right @ZzzzHui I made the adjustment. Let me know if it meets what you proposed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks Henri

Comment on lines +462 to +494
function testSubmittedClaimsCounter(bytes32[] calldata claims) external {
uint256 epochLength = 5;
uint256 numOfValidators = 3;

IQuorum quorum = _deployQuorum(numOfValidators, epochLength);

assertEq(quorum.getNumberOfSubmittedClaims(), 0);

Claim memory claim;
claim.appContract = vm.addr(1);

uint256 blockNum = epochLength;
vm.roll(blockNum);

uint256 totalSubmissions;

for (uint256 i = 0; i < claims.length; ++i) {
claim.lastProcessedBlockNumber = blockNum - 1;
claim.outputsMerkleRoot = claims[i];

// submit claim with majority validators
uint256 majority = numOfValidators / 2 + 1;
for (uint256 id = 1; id <= majority; ++id) {
vm.prank(quorum.validatorById(id));
quorum.submitClaim(claim);
++totalSubmissions;
assertEq(quorum.getNumberOfSubmittedClaims(), totalSubmissions);
}

blockNum += epochLength;
vm.roll(blockNum);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is almost the same test as testMultipleClaimsAcceptedCounter, we could consider merging into it. We could then change the test name to something like testMultipleClaimsCounters etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged the tests under the name testMultipleClaimsCounters. Let me know if this looks better

@henriquemarlon henriquemarlon force-pushed the feat/claim-submission-counter branch from 6c49df1 to e13644e Compare January 17, 2026 16:32
@henriquemarlon henriquemarlon force-pushed the feat/claim-submission-counter branch 2 times, most recently from 3210479 to c8627c8 Compare January 19, 2026 03:29
@ZzzzHui
Copy link
Contributor

ZzzzHui commented Jan 19, 2026

You can keep testSubmittedClaimsCounterIgnoresSameValidatorResubmission and testSubmittedClaimsCounterMaxIsNumOfValidators test case if you want. I think they are good test cases.

@henriquemarlon henriquemarlon force-pushed the feat/claim-submission-counter branch from c8627c8 to f33840c Compare January 19, 2026 21:06
Copy link
Contributor

@ZzzzHui ZzzzHui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

@henriquemarlon henriquemarlon merged commit fd51074 into main Jan 20, 2026
4 checks passed
@henriquemarlon henriquemarlon deleted the feat/claim-submission-counter branch January 20, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants