Skip to content

Commit

Permalink
identity-manager: move verifier lookup tables to the base test contract
Browse files Browse the repository at this point in the history
Making these variables global shrunks stack significantly, allowing to
build contracts without the --via-ir flag.

Signed-off-by: Wojciech Zmuda <[email protected]>
  • Loading branch information
wzmuda committed Sep 10, 2024
1 parent cbe167d commit 6ca49e5
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 141 deletions.
16 changes: 8 additions & 8 deletions src/test/identity-manager/WorldIDIdentityManagerDataQuery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ contract WorldIDIdentityManagerDataQuery is WorldIDIdentityManagerTest {
vm.assume(newPreRoot != newPostRoot);
vm.assume(identities.length <= 1000);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length]));
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -93,10 +93,10 @@ contract WorldIDIdentityManagerDataQuery is WorldIDIdentityManagerTest {
vm.assume(SimpleVerify.isValidInput(uint256(prf[0])));
vm.assume(identities.length <= 1000);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length]));
makeNewIdentityManager(
treeDepth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest {
/// identity deletion proofs.
function testCanSetDeleteIdentitiesVerifierLookupTable() public {
// Setup
(,, VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40]));
(,, deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40]));
address newVerifiersAddress = address(deletionVerifiers);
bytes memory callData =
abi.encodeCall(ManagerImpl.setDeleteIdentitiesVerifierLookupTable, (deletionVerifiers));
Expand All @@ -142,7 +142,7 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest {
function testCannotSetDeleteIdentitiesVerifierLookupTableUnlessOwner(address notOwner) public {
// Setup
vm.assume(notOwner != address(this) && notOwner != address(0x0));
(,, VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40]));
(,, deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40]));
bytes memory callData = abi.encodeCall(
ManagerImplV1.setRegisterIdentitiesVerifierLookupTable, (deletionVerifiers)
);
Expand All @@ -157,7 +157,7 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest {
/// identity deletion unless called via the proxy.
function testCannotSetDeleteIdentitiesVerifierLookupTableUnlessViaProxy() public {
// Setup
(,, VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40]));
(,, deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40]));
vm.expectRevert("Function must be called through delegatecall");

// Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
// Setup
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([40]));
deletionVerifiers.addVerifier(deletionBatchSize, actualVerifier);
makeNewIdentityManager(
Expand Down Expand Up @@ -86,10 +86,10 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
vm.assume(packedDeletionIndices.length % 4 == 0);
vm.assume(identityOperator != nullAddress && identityOperator != thisAddress);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([packedDeletionIndices.length / 4]));
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -133,10 +133,10 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
bytes memory secondIndices = abi.encodePacked(uint32(0), uint32(2), uint32(4), uint32(6));

(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([deletionBatchSize, secondIndices.length / 4]));
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -181,10 +181,10 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
vm.assume(packedDeletionIndices.length > 4);
vm.assume(packedDeletionIndices.length % 4 == 0);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) =
// the -1 offsets the correct batch size by 1 thus causing the error
makeVerifierLookupTables(TC.makeDynArray([(packedDeletionIndices.length / 4) - 1]));
Expand Down Expand Up @@ -221,10 +221,10 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
ITreeVerifier actualVerifier = new TreeVerifier();
uint32 indicesLength = uint32(packedDeletionIndices.length / 4);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
deletionVerifiers.addVerifier(indicesLength, actualVerifier);
makeNewIdentityManager(
Expand Down Expand Up @@ -254,10 +254,10 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
vm.assume(newPostRoot != deletionPostRoot && newPostRoot < SNARK_SCALAR_FIELD);
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
deletionVerifiers.addVerifier(deletionBatchSize, actualVerifier);
makeNewIdentityManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
// Setup
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([40]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);
makeNewIdentityManager(
Expand Down Expand Up @@ -88,10 +88,10 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(identities.length <= 1000);
vm.assume(identityOperator != nullAddress && identityOperator != thisAddress);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length]));
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -137,10 +137,10 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(identities.length <= 1000 && identities.length > 0);
uint256 secondIdentsLength = identities.length / 2;
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length, secondIdentsLength]));
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -191,10 +191,10 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(newPreRoot != newPostRoot);
vm.assume(identities.length > 0);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length - 1]));
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -229,10 +229,10 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(!SimpleVerify.isValidInput(uint256(prf[0])));
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitments.length, actualVerifier);
makeNewIdentityManager(
Expand Down Expand Up @@ -261,10 +261,10 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(newStartIndex != startIndex);
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);
makeNewIdentityManager(
Expand Down Expand Up @@ -305,10 +305,10 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
identities[invalidSlot] = identity;
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);
makeNewIdentityManager(
Expand Down Expand Up @@ -339,9 +339,9 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
managerImplV2Address = address(managerImplV2);
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
insertVerifiers,
deletionVerifiers,
updateVerifiers,
) = makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);

Expand Down Expand Up @@ -430,10 +430,10 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(zeroPosition < identitiesLength && zeroPosition > 0);
uint256[] memory identities = new uint256[](identitiesLength);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
insertVerifiers,
deletionVerifiers,
updateVerifiers,
insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identitiesLength]));
makeNewIdentityManager(
treeDepth,
Expand Down
Loading

0 comments on commit 6ca49e5

Please sign in to comment.