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 9e67f0a commit a5ab7aa
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 230 deletions.
16 changes: 4 additions & 12 deletions src/test/identity-manager/WorldIDIdentityManagerDataQuery.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ contract WorldIDIdentityManagerDataQuery is WorldIDIdentityManagerTest {
vm.assume(SimpleVerify.isValidInput(uint256(prf[0])));
vm.assume(newPreRoot != newPostRoot);
vm.assume(identities.length <= 1000);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([identities.length]));
makeNewIdentityManager(
treeDepth,
newPreRoot,
Expand Down Expand Up @@ -92,12 +88,8 @@ contract WorldIDIdentityManagerDataQuery is WorldIDIdentityManagerTest {
vm.assume(newPreRoot != newPostRoot);
vm.assume(SimpleVerify.isValidInput(uint256(prf[0])));
vm.assume(identities.length <= 1000);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([identities.length]));
makeNewIdentityManager(
treeDepth,
newPreRoot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest {
/// identity registration proofs.
function testCanSetRegisterIdentitiesVerifierLookupTable() public {
// Setup
(VerifierLookupTable insertionVerifiers,,,) =
makeVerifierLookupTables(TC.makeDynArray([40]));
address newVerifiersAddress = address(insertionVerifiers);
(insertVerifiers,,,) = makeVerifierLookupTables(TC.makeDynArray([40]));
address newVerifiersAddress = address(insertVerifiers);
bytes memory callData = abi.encodeCall(
ManagerImplV1.setRegisterIdentitiesVerifierLookupTable, (insertionVerifiers)
ManagerImplV1.setRegisterIdentitiesVerifierLookupTable, (insertVerifiers)
);
bytes memory checkCallData =
abi.encodeCall(ManagerImplV1.getRegisterIdentitiesVerifierLookupTableAddress, ());
Expand All @@ -74,10 +73,9 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest {
{
// Setup
vm.assume(notOwner != address(this) && notOwner != address(0x0));
(VerifierLookupTable insertionVerifiers,,,) =
makeVerifierLookupTables(TC.makeDynArray([40]));
(insertVerifiers,,,) = makeVerifierLookupTables(TC.makeDynArray([40]));
bytes memory callData = abi.encodeCall(
ManagerImplV1.setRegisterIdentitiesVerifierLookupTable, (insertionVerifiers)
ManagerImplV1.setRegisterIdentitiesVerifierLookupTable, (insertVerifiers)
);
bytes memory errorData = encodeStringRevert("Ownable: caller is not the owner");
vm.prank(notOwner);
Expand All @@ -90,12 +88,11 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest {
/// identity registration unless called via the proxy.
function testCannotSetRegisterIdentitiesVerifierLookupTableUnlessViaProxy() public {
// Setup
(VerifierLookupTable insertionVerifiers,,,) =
makeVerifierLookupTables(TC.makeDynArray([40]));
(insertVerifiers,,,) = makeVerifierLookupTables(TC.makeDynArray([40]));
vm.expectRevert("Function must be called through delegatecall");

// Test
managerImplV2.setRegisterIdentitiesVerifierLookupTable(insertionVerifiers);
managerImplV2.setRegisterIdentitiesVerifierLookupTable(insertVerifiers);
}

/// @notice Checks that it is possible to get the address of the contract currently being used
Expand Down Expand Up @@ -124,8 +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 @@ -146,8 +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 @@ -162,8 +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 @@ -36,12 +36,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
function testDeleteIdentitiesWithCorrectInputsFromKnown() public {
// Setup
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([40]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([40]));
deletionVerifiers.addVerifier(deletionBatchSize, actualVerifier);
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -85,12 +81,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
vm.assume(packedDeletionIndices.length <= 125);
vm.assume(packedDeletionIndices.length % 4 == 0);
vm.assume(identityOperator != nullAddress && identityOperator != thisAddress);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([packedDeletionIndices.length / 4]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([packedDeletionIndices.length / 4]));
makeNewIdentityManager(
treeDepth,
newPreRoot,
Expand Down Expand Up @@ -132,12 +124,8 @@ 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
) = makeVerifierLookupTables(TC.makeDynArray([deletionBatchSize, secondIndices.length / 4]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([deletionBatchSize, secondIndices.length / 4]));
makeNewIdentityManager(
treeDepth,
newPreRoot,
Expand Down Expand Up @@ -180,12 +168,7 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
vm.assume(newPreRoot != newPostRoot);
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]));
makeNewIdentityManager(
Expand Down Expand Up @@ -220,12 +203,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
vm.assume(newPreRoot != newPostRoot);
ITreeVerifier actualVerifier = new TreeVerifier();
uint32 indicesLength = uint32(packedDeletionIndices.length / 4);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([70]));
deletionVerifiers.addVerifier(indicesLength, actualVerifier);
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -253,12 +232,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest {
// Setup
vm.assume(newPostRoot != deletionPostRoot && newPostRoot < SNARK_SCALAR_FIELD);
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([70]));
deletionVerifiers.addVerifier(deletionBatchSize, actualVerifier);
makeNewIdentityManager(
treeDepth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
function testRegisterIdentitiesWithCorrectInputsFromKnown() public {
// Setup
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([40]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([40]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -87,12 +83,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(newPreRoot != newPostRoot);
vm.assume(identities.length <= 1000);
vm.assume(identityOperator != nullAddress && identityOperator != thisAddress);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([identities.length]));
makeNewIdentityManager(
treeDepth,
newPreRoot,
Expand Down Expand Up @@ -136,12 +128,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(newPreRoot != newPostRoot);
vm.assume(identities.length <= 1000 && identities.length > 0);
uint256 secondIdentsLength = identities.length / 2;
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length, secondIdentsLength]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([identities.length, secondIdentsLength]));
makeNewIdentityManager(
treeDepth,
newPreRoot,
Expand Down Expand Up @@ -190,12 +178,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(SimpleVerify.isValidInput(uint256(prf[0])));
vm.assume(newPreRoot != newPostRoot);
vm.assume(identities.length > 0);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identities.length - 1]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([identities.length - 1]));
makeNewIdentityManager(
treeDepth,
newPreRoot,
Expand Down Expand Up @@ -228,12 +212,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
// Setup
vm.assume(!SimpleVerify.isValidInput(uint256(prf[0])));
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitments.length, actualVerifier);
makeNewIdentityManager(
treeDepth,
Expand All @@ -260,12 +240,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
// Setup
vm.assume(newStartIndex != startIndex);
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -304,12 +280,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
uint256[] memory identities = cloneArray(identityCommitments);
identities[invalidSlot] = identity;
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([70]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);
makeNewIdentityManager(
treeDepth,
Expand Down Expand Up @@ -338,11 +310,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
managerImplV2 = new ManagerImpl();
managerImplV2Address = address(managerImplV2);
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
) = makeVerifierLookupTables(TC.makeDynArray([70]));
(insertVerifiers, deletionVerifiers, updateVerifiers,) =
makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);

bytes memory callData = abi.encodeCall(
Expand Down Expand Up @@ -429,12 +398,8 @@ contract WorldIDIdentityManagerIdentityRegistration is WorldIDIdentityManagerTes
vm.assume(identitiesLength != 0 && identitiesLength <= 1000);
vm.assume(zeroPosition < identitiesLength && zeroPosition > 0);
uint256[] memory identities = new uint256[](identitiesLength);
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers,
VerifierLookupTable4844 insertVerifiers4844
) = makeVerifierLookupTables(TC.makeDynArray([identitiesLength]));
(insertVerifiers, deletionVerifiers, updateVerifiers, insertVerifiers4844) =
makeVerifierLookupTables(TC.makeDynArray([identitiesLength]));
makeNewIdentityManager(
treeDepth,
initialRoot,
Expand Down
Loading

0 comments on commit a5ab7aa

Please sign in to comment.