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

Test sig checker #102

Merged
merged 17 commits into from
Aug 1, 2023
Merged

Test sig checker #102

merged 17 commits into from
Aug 1, 2023

Conversation

gpsanant
Copy link
Contributor

Added unit tests for the signature checker

// if the operator was a part of the quorum and the quorum is a part of the provided quorumNumbers
if (nonSignerQuorumBitmap >> j & (BitmapUtils.bytesArrayToBitmap(quorumNumbers) >> j & 1) == 1) {
checkSignaturesIndices.nonSignerStakeIndices[i][stakeIndexIndex] = stakeRegistry.getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber(
if (nonSignerQuorumBitmap >> uint8(quorumNumbers[quorumNumberIndex]) & 1 == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

going to suggest parentheses for clarity here. I realize they're unnecessary but IMO it's easier to verify it's right if we write operators like this (multiple bitwise ops chained together) as:
if ((nonSignerQuorumBitmap >> uint8(quorumNumbers[quorumNumberIndex])) & 1 == 1) {

Comment on lines +119 to +121
// if (i != 0) {
// require(uint256(nonSignerPubkeyHashes[i]) > uint256(nonSignerPubkeyHashes[i - 1]), "BLSSignatureChecker.checkSignatures: nonSignerPubkeys not sorted");
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

is this just a temporary change to deal with ordering being hard?
IIRC this check was key for ensuring no duplicates (we should add a comment to this effect as well)

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 actually think this is fine. if you subtract the same public key twice, then the amount of stake that has confirmed a fact will only be underestimated

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think this is fine. if you subtract the same public key twice, then the amount of stake that has confirmed a fact will only be underestimated

hmm OK I guess. I suppose you wouldn't have a valid signature for the resultant public key anyway, right (in the case where you subtract a signature twice)? Just want to be very sure before deleting anything that was intended as some kind of safety/correctness check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, agreed.

@ChaoticWalrus
Copy link
Contributor

Medium-level design question: what happens when none of the non-signers is part of one of the quorums? is the answer that we just don't optimize for this and can still handle it? because that is my guess based on review so far

Comment on lines +17 to +28
function recordOperatorQuorumBitmapUpdate(bytes32 operatorId, uint192 quorumBitmap) external {
uint256 operatorQuorumBitmapHistoryLength = _operatorIdToQuorumBitmapHistory[operatorId].length;
if (operatorQuorumBitmapHistoryLength != 0) {
_operatorIdToQuorumBitmapHistory[operatorId][operatorQuorumBitmapHistoryLength - 1].nextUpdateBlockNumber = uint32(block.number);
}

_operatorIdToQuorumBitmapHistory[operatorId].push(QuorumBitmapUpdate({
updateBlockNumber: uint32(block.number),
nextUpdateBlockNumber: 0,
quorumBitmap: quorumBitmap
}));
}
Copy link
Contributor

@ChaoticWalrus ChaoticWalrus Jul 20, 2023

Choose a reason for hiding this comment

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

should there be a corresponding internal function in the BLSRegistryCoordinatorWithIndices? If there is already, why not use it? Am a bit concerned about any possibility for divergence between harnessed + non-harnessed versions

Comment on lines 101 to 104
assertEq(checkSignaturesIndices.nonSignerQuorumBitmapIndices.length, 0);
assertEq(checkSignaturesIndices.quorumApkIndices.length, allInclusiveQuorumNumbers.length);
assertEq(checkSignaturesIndices.totalStakeIndices.length, allInclusiveQuorumNumbers.length);
assertEq(checkSignaturesIndices.nonSignerStakeIndices.length, 0);
assertEq(checkSignaturesIndices.nonSignerStakeIndices.length, allInclusiveQuorumNumbers.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add some revert messages to these? also helps document exactly what it's checking (although these seem ~fairly clear)

Comment on lines +36 to +39

// 0 nonSigners: 159908
// 1 nonSigner: 178683
// 2 nonSigners: 197410
Copy link
Contributor

Choose a reason for hiding this comment

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

can we check anything here other than the call not reverting? it's a 'view' function so no state transition to check, but maybe we can check something about the returned values (looks like we're just tossing those out right now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

db7e47e

looks like the commit you linked just puts the returned values into memory and then immediately dumps them? this is still short of checking anything about the returned values

Comment on lines 218 to 228
// set the sigma to a different value
nonSignerStakesAndSignature.sigma.X++;

cheats.expectRevert();
blsSignatureChecker.checkSignatures(
msgHash,
quorumNumbers,
referenceBlockNumber,
nonSignerStakesAndSignature
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should this have a specific revert message or does this end up in some low-level call failure (like a failure in the precompile call?) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

precompile call fails rip

Copy link
Contributor

Choose a reason for hiding this comment

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

OK plz add a comment like

        // expect a non-specific low-level revert, since this call will ultimately fail as part of the precompile call
        cheats.expectRevert();
        blsSignatureChecker.checkSignatures(
            msgHash, 
            quorumNumbers,
            referenceBlockNumber, 
            nonSignerStakesAndSignature
        );

Copy link
Contributor

@ChaoticWalrus ChaoticWalrus left a comment

Choose a reason for hiding this comment

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

This is looking really good!
Definitely want more documentation on this, but I don't think I'm seeing any real problems; I'd like to take another look after documentation is added but am primarily expecting to understand better (but it should also help me identify bugs or holes in testing easier)

@ChaoticWalrus
Copy link
Contributor

Am approving the PR for now, assuming no further logical changes. Please add some more clarifying comments / documentation prior to merging.

@gpsanant gpsanant merged commit 64ace4e into multiquorums Aug 1, 2023
7 of 8 checks passed
@gpsanant gpsanant deleted the test-sig-checker branch August 1, 2023 23:52
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