From a6ab8c099ead2611077dc1bbba117c2791286fbd Mon Sep 17 00:00:00 2001 From: "dcbuilder.eth" Date: Wed, 6 Sep 2023 21:44:11 +0100 Subject: [PATCH] compilation fix tests are still broken --- src/WorldIDIdentityManagerImplV2.sol | 6 +- src/test/data/TestDeletionParams.json | 112 ++++++++++++++++-- .../WorldIDIdentityManagerCalculation.t.sol | 4 +- ...WorldIDIdentityManagerGettersSetters.t.sol | 15 +-- ...rldIDIdentityManagerIdentityDeletion.t.sol | 82 ++++++++----- .../WorldIDIdentityManagerTest.sol | 25 ++-- .../WorldIDIdentityManagerUninit.t.sol | 8 +- 7 files changed, 185 insertions(+), 67 deletions(-) diff --git a/src/WorldIDIdentityManagerImplV2.sol b/src/WorldIDIdentityManagerImplV2.sol index 5fdf498..da452bc 100644 --- a/src/WorldIDIdentityManagerImplV2.sol +++ b/src/WorldIDIdentityManagerImplV2.sol @@ -122,7 +122,8 @@ contract WorldIDIdentityManagerImplV2 is WorldIDIdentityManagerImplV1 { } // Having validated the preconditions we can now check the proof itself. - bytes32 inputHash = calculateIdentityDeletionInputHash(packedDeletionIndices, preRoot, postRoot, batchSize); + bytes32 inputHash = + calculateIdentityDeletionInputHash(packedDeletionIndices, preRoot, postRoot, batchSize); // No matter what, the inputs can result in a hash that is not an element of the scalar // field in which we're operating. We reduce it into the field before handing it to the @@ -130,8 +131,7 @@ contract WorldIDIdentityManagerImplV2 is WorldIDIdentityManagerImplV1 { uint256 reducedElement = uint256(inputHash) % SNARK_SCALAR_FIELD; // We need to look up the correct verifier before we can verify. - ITreeVerifier deletionVerifier = - batchDeletionVerifiers.getVerifierFor(batchSize); + ITreeVerifier deletionVerifier = batchDeletionVerifiers.getVerifierFor(batchSize); // With that, we can properly try and verify. try deletionVerifier.verifyProof( diff --git a/src/test/data/TestDeletionParams.json b/src/test/data/TestDeletionParams.json index 569e3a3..36e66e8 100644 --- a/src/test/data/TestDeletionParams.json +++ b/src/test/data/TestDeletionParams.json @@ -1,15 +1,15 @@ { - "inputHash": "0xfe7bd6158c7603ed86cef4dbe90a417fe7c16e94a730ae75ff0135837c6f4dd1", - "deletionIndices": [0, 2, 4], - "preRoot": "0x218676b10b4d8c25fce789f3b13f2b3e49497ce0b20f57bacd7dfda85c0b6ac2", - "postRoot": "0x7c453712267d1cca763c6da89bb632bd85bf9d8b48ef71bd0b7595f81357edb", - "identityCommitments": ["0x1", "0x3", "0x5"], + "inputHash": "0x227590f99431e20f2f95fdfb1b7dfb648c04242c950c31263ba165647c96501a", + "deletionIndices": [0, 2, 4, 6, 8, 10, 12, 14], + "preRoot": "0x18cb13df3e79b9f847a1494d0a2e6f3cc0041d9cae7e5ccb8cd1852ecdc4af58", + "postRoot": "0x82fcf94594d7363636338e2c29242cc77e3d04f36c8ad64d294d2ab4d251708", + "identityCommitments": ["0x1", "0x3", "0x5", "0x7", "0x9", "0xb", "0xd", "0xf"], "merkleProofs": [ [ "0x2", "0x20a3af0435914ccd84b806164531b0cd36e37d4efb93efab76913a93e1f30996", - "0x176cf35331147314efef56ab615fe64b748584a01d362fa17297672192d5ecd", - "0x18f43331537ee2af2e3d758d50f72106467c6eea50371dd528d57eb2b856d238", + "0x207c74956e87b3f9e6d31ca140770d3b0921e96ff4131e83c93404c448aace11", + "0x20eadd2578c984addd652554c2e2e104406bb3156de001b765b40bd2178c9b8d", "0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a", "0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55", "0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78", @@ -26,8 +26,8 @@ [ "0x4", "0x65e2c6cc08a36c4a943286bc91c216054a1981eb4f7570f67394ef8937a21b8", - "0x176cf35331147314efef56ab615fe64b748584a01d362fa17297672192d5ecd", - "0x18f43331537ee2af2e3d758d50f72106467c6eea50371dd528d57eb2b856d238", + "0x207c74956e87b3f9e6d31ca140770d3b0921e96ff4131e83c93404c448aace11", + "0x20eadd2578c984addd652554c2e2e104406bb3156de001b765b40bd2178c9b8d", "0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a", "0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55", "0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78", @@ -43,9 +43,99 @@ ], [ "0x6", - "0x2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864", + "0x2aef487272d385cd5eba40e25144e80641fef93ff5b25a0133b0d1bd50077920", "0x1ebadf14eecbfe79f7ac75d3b6c688b8630fb675fcf24ab20e2a08381998266f", - "0x18f43331537ee2af2e3d758d50f72106467c6eea50371dd528d57eb2b856d238", + "0x20eadd2578c984addd652554c2e2e104406bb3156de001b765b40bd2178c9b8d", + "0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a", + "0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55", + "0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78", + "0x78295e5a22b84e982cf601eb639597b8b0515a88cb5ac7fa8a4aabe3c87349d", + "0x2fa5e5f18f6027a6501bec864564472a616b2e274a41211a444cbe3a99f3cc61", + "0xe884376d0d8fd21ecb780389e941f66e45e7acce3e228ab3e2156a614fcd747", + "0x1b7201da72494f1e28717ad1a52eb469f95892f957713533de6175e5da190af2", + "0x1f8d8822725e36385200c0b201249819a6e6e1e4650808b5bebc6bface7d7636", + "0x2c5d82f66c914bafb9701589ba8cfcfb6162b0a12acf88a8d0879a0471b5f85a", + "0x14c54148a0940bb820957f5adf3fa1134ef5c4aaa113f4646458f270e0bfbfd0", + "0x190d33b12f986f961e10c0ee44d8b9af11be25588cad89d416118e4bf4ebe80c", + "0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92" + ], + [ + "0x8", + "0x20dc7044757b1f24c7f832b9667c4556714019a71a066a22b92bdd77723f6b04", + "0x1ebadf14eecbfe79f7ac75d3b6c688b8630fb675fcf24ab20e2a08381998266f", + "0x20eadd2578c984addd652554c2e2e104406bb3156de001b765b40bd2178c9b8d", + "0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a", + "0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55", + "0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78", + "0x78295e5a22b84e982cf601eb639597b8b0515a88cb5ac7fa8a4aabe3c87349d", + "0x2fa5e5f18f6027a6501bec864564472a616b2e274a41211a444cbe3a99f3cc61", + "0xe884376d0d8fd21ecb780389e941f66e45e7acce3e228ab3e2156a614fcd747", + "0x1b7201da72494f1e28717ad1a52eb469f95892f957713533de6175e5da190af2", + "0x1f8d8822725e36385200c0b201249819a6e6e1e4650808b5bebc6bface7d7636", + "0x2c5d82f66c914bafb9701589ba8cfcfb6162b0a12acf88a8d0879a0471b5f85a", + "0x14c54148a0940bb820957f5adf3fa1134ef5c4aaa113f4646458f270e0bfbfd0", + "0x190d33b12f986f961e10c0ee44d8b9af11be25588cad89d416118e4bf4ebe80c", + "0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92" + ], + [ + "0xa", + "0x1340c981e5112e73251c5f2e80a7d95c02a2d6086f8cd28c201e09f38d054cf8", + "0x2285bd343aa98c6c45b027216e1cb201894a8c3cf1a0b3765abca88a0ed3a644", + "0x1c430bfac3ed5c853cd68c414d64defb441b07efdd649912885a43f0c39a6f6e", + "0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a", + "0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55", + "0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78", + "0x78295e5a22b84e982cf601eb639597b8b0515a88cb5ac7fa8a4aabe3c87349d", + "0x2fa5e5f18f6027a6501bec864564472a616b2e274a41211a444cbe3a99f3cc61", + "0xe884376d0d8fd21ecb780389e941f66e45e7acce3e228ab3e2156a614fcd747", + "0x1b7201da72494f1e28717ad1a52eb469f95892f957713533de6175e5da190af2", + "0x1f8d8822725e36385200c0b201249819a6e6e1e4650808b5bebc6bface7d7636", + "0x2c5d82f66c914bafb9701589ba8cfcfb6162b0a12acf88a8d0879a0471b5f85a", + "0x14c54148a0940bb820957f5adf3fa1134ef5c4aaa113f4646458f270e0bfbfd0", + "0x190d33b12f986f961e10c0ee44d8b9af11be25588cad89d416118e4bf4ebe80c", + "0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92" + ], + [ + "0xc", + "0x275543cd9fbcdee56ac8c9a937ad062f198be71714077c99e50ee6b5e2328a2c", + "0x2285bd343aa98c6c45b027216e1cb201894a8c3cf1a0b3765abca88a0ed3a644", + "0x1c430bfac3ed5c853cd68c414d64defb441b07efdd649912885a43f0c39a6f6e", + "0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a", + "0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55", + "0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78", + "0x78295e5a22b84e982cf601eb639597b8b0515a88cb5ac7fa8a4aabe3c87349d", + "0x2fa5e5f18f6027a6501bec864564472a616b2e274a41211a444cbe3a99f3cc61", + "0xe884376d0d8fd21ecb780389e941f66e45e7acce3e228ab3e2156a614fcd747", + "0x1b7201da72494f1e28717ad1a52eb469f95892f957713533de6175e5da190af2", + "0x1f8d8822725e36385200c0b201249819a6e6e1e4650808b5bebc6bface7d7636", + "0x2c5d82f66c914bafb9701589ba8cfcfb6162b0a12acf88a8d0879a0471b5f85a", + "0x14c54148a0940bb820957f5adf3fa1134ef5c4aaa113f4646458f270e0bfbfd0", + "0x190d33b12f986f961e10c0ee44d8b9af11be25588cad89d416118e4bf4ebe80c", + "0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92" + ], + [ + "0xe", + "0x158743daa8227296c7b3b03fca21e8c7e7e535b1791091d38182cd29795e6001", + "0xa89786c05a24b044fcac8caa1e998c39d9975c454860e5442d85ff42be75e85", + "0x1c430bfac3ed5c853cd68c414d64defb441b07efdd649912885a43f0c39a6f6e", + "0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a", + "0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55", + "0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78", + "0x78295e5a22b84e982cf601eb639597b8b0515a88cb5ac7fa8a4aabe3c87349d", + "0x2fa5e5f18f6027a6501bec864564472a616b2e274a41211a444cbe3a99f3cc61", + "0xe884376d0d8fd21ecb780389e941f66e45e7acce3e228ab3e2156a614fcd747", + "0x1b7201da72494f1e28717ad1a52eb469f95892f957713533de6175e5da190af2", + "0x1f8d8822725e36385200c0b201249819a6e6e1e4650808b5bebc6bface7d7636", + "0x2c5d82f66c914bafb9701589ba8cfcfb6162b0a12acf88a8d0879a0471b5f85a", + "0x14c54148a0940bb820957f5adf3fa1134ef5c4aaa113f4646458f270e0bfbfd0", + "0x190d33b12f986f961e10c0ee44d8b9af11be25588cad89d416118e4bf4ebe80c", + "0x22f98aa9ce704152ac17354914ad73ed1167ae6596af510aa5b3649325e06c92" + ], + [ + "0x10", + "0x158cdf90c232e1624129ff7a0994c9acb5b45340ad851036088946991e724354", + "0xa89786c05a24b044fcac8caa1e998c39d9975c454860e5442d85ff42be75e85", + "0x1c430bfac3ed5c853cd68c414d64defb441b07efdd649912885a43f0c39a6f6e", "0x7f9d837cb17b0d36320ffe93ba52345f1b728571a568265caac97559dbc952a", "0x2b94cf5e8746b3f5c9631f4c5df32907a699c58c94b2ad4d7b5cec1639183f55", "0x2dee93c5a666459646ea7d22cca9e1bcfed71e6951b953611d11dda32ea09d78", diff --git a/src/test/identity-manager/WorldIDIdentityManagerCalculation.t.sol b/src/test/identity-manager/WorldIDIdentityManagerCalculation.t.sol index 597e53e..551f31d 100644 --- a/src/test/identity-manager/WorldIDIdentityManagerCalculation.t.sol +++ b/src/test/identity-manager/WorldIDIdentityManagerCalculation.t.sol @@ -43,7 +43,7 @@ contract WorldIDIdentityManagerCalculation is WorldIDIdentityManagerTest { // Setup bytes memory callData = abi.encodeCall( ManagerImpl.calculateIdentityDeletionInputHash, - (deletionIndices, insertionPreRoot, insertionPostRoot) + (packedDeletionIndices, insertionPreRoot, insertionPostRoot, deletionBatchSize) ); bytes memory returnData = abi.encode(deletionInputHash); @@ -58,7 +58,7 @@ contract WorldIDIdentityManagerCalculation is WorldIDIdentityManagerTest { // Test managerImpl.calculateIdentityDeletionInputHash( - deletionIndices, insertionPreRoot, insertionPostRoot + packedDeletionIndices, deletionPreRoot, deletionPostRoot, deletionBatchSize ); } diff --git a/src/test/identity-manager/WorldIDIdentityManagerGettersSetters.t.sol b/src/test/identity-manager/WorldIDIdentityManagerGettersSetters.t.sol index 3571d72..852137b 100644 --- a/src/test/identity-manager/WorldIDIdentityManagerGettersSetters.t.sol +++ b/src/test/identity-manager/WorldIDIdentityManagerGettersSetters.t.sol @@ -122,11 +122,10 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest { /// identity deletion proofs. function testCanSetDeleteIdentitiesVerifierLookupTable() public { // Setup - (,VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40])); + (, VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40])); address newVerifiersAddress = address(deletionVerifiers); - bytes memory callData = abi.encodeCall( - ManagerImpl.setDeleteIdentitiesVerifierLookupTable, (deletionVerifiers) - ); + bytes memory callData = + abi.encodeCall(ManagerImpl.setDeleteIdentitiesVerifierLookupTable, (deletionVerifiers)); bytes memory checkCallData = abi.encodeCall(ManagerImpl.getDeleteIdentitiesVerifierLookupTableAddress, ()); bytes memory expectedReturn = abi.encode(newVerifiersAddress); @@ -141,12 +140,10 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest { } /// @notice Checks that the delete identities lookup table cannot be set except by the owner. - function testCannotSetDeleteIdentitiesVerifierLookupTableUnlessOwner(address notOwner) - public - { + function testCannotSetDeleteIdentitiesVerifierLookupTableUnlessOwner(address notOwner) public { // Setup vm.assume(notOwner != address(this) && notOwner != address(0x0)); - (,VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40])); + (, VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40])); bytes memory callData = abi.encodeCall( ManagerImplV1.setRegisterIdentitiesVerifierLookupTable, (deletionVerifiers) ); @@ -161,7 +158,7 @@ contract WorldIDIdentityManagerGettersSetters is WorldIDIdentityManagerTest { /// identity deletion unless called via the proxy. function testCannotSetDeleteIdentitiesVerifierLookupTableUnlessViaProxy() public { // Setup - (,VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40])); + (, VerifierLookupTable deletionVerifiers,) = makeVerifierLookupTables(TC.makeDynArray([40])); vm.expectRevert("Function must be called through delegatecall"); // Test diff --git a/src/test/identity-manager/WorldIDIdentityManagerIdentityDeletion.t.sol b/src/test/identity-manager/WorldIDIdentityManagerIdentityDeletion.t.sol index 150fcdf..ce19582 100644 --- a/src/test/identity-manager/WorldIDIdentityManagerIdentityDeletion.t.sol +++ b/src/test/identity-manager/WorldIDIdentityManagerIdentityDeletion.t.sol @@ -49,7 +49,13 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { ); bytes memory deleteCallData = abi.encodeCall( ManagerImpl.deleteIdentities, - (deletionProof, deletionPreRoot, deletionIndices, deletionPostRoot) + ( + deletionProof, + deletionBatchSize, + packedDeletionIndices, + deletionPreRoot, + deletionPostRoot + ) ); bytes memory latestRootCallData = abi.encodeCall(ManagerImplV1.latestRoot, ()); bytes memory queryRootCallData = abi.encodeCall(ManagerImplV1.queryRoot, (deletionPostRoot)); @@ -70,20 +76,20 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { function testDeleteIdentitiesWithCorrectInputs( uint128[8] memory prf, uint128 newPreRoot, - uint32[] memory deletionIndices, + uint256[] memory packedDeletionIndices, uint128 newPostRoot, address identityOperator ) public { // Setup vm.assume(SimpleVerify.isValidInput(uint256(prf[0]))); vm.assume(newPreRoot != newPostRoot); - vm.assume(deletionIndices.length <= 1000); + vm.assume(packedDeletionIndices.length <= 1000); vm.assume(identityOperator != nullAddress && identityOperator != thisAddress); ( VerifierLookupTable insertVerifiers, VerifierLookupTable deletionVerifiers, VerifierLookupTable updateVerifiers - ) = makeVerifierLookupTables(TC.makeDynArray([deletionIndices.length])); + ) = makeVerifierLookupTables(TC.makeDynArray([packedDeletionIndices.length])); makeNewIdentityManager( treeDepth, newPreRoot, @@ -94,7 +100,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { ); uint256[8] memory actualProof = prepareDeleteIdentitiesTestCase(prf); bytes memory callData = abi.encodeCall( - ManagerImpl.deleteIdentities, (actualProof, newPreRoot, deletionIndices, newPostRoot) + ManagerImpl.deleteIdentities, + (actualProof, deletionBatchSize, packedDeletionIndices, newPreRoot, newPostRoot) ); bytes memory setupCallData = @@ -116,18 +123,20 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { function testDeleteIdentitiesSelectsCorrectVerifier( uint128[8] memory prf, uint128 newPreRoot, - uint32[] memory deletionIndices, + uint256[] memory packedDeletionIndices, uint128 newPostRoot ) public { vm.assume(SimpleVerify.isValidInput(uint256(prf[0]))); vm.assume(newPreRoot != newPostRoot); - vm.assume(deletionIndices.length <= 1000 && deletionIndices.length > 0); - uint256 secondIndicesLength = deletionIndices.length / 2; + vm.assume(packedDeletionIndices.length <= 125 && packedDeletionIndices.length > 0); + uint256 secondIndicesLength = packedDeletionIndices.length / 2; ( VerifierLookupTable insertVerifiers, VerifierLookupTable deletionVerifiers, VerifierLookupTable updateVerifiers - ) = makeVerifierLookupTables(TC.makeDynArray([deletionIndices.length, secondIndicesLength])); + ) = makeVerifierLookupTables( + TC.makeDynArray([packedDeletionIndices.length, secondIndicesLength]) + ); makeNewIdentityManager( treeDepth, newPreRoot, @@ -137,26 +146,28 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { semaphoreVerifier ); uint256[8] memory actualProof = prepareDeleteIdentitiesTestCase(prf); - uint32[] memory secondIndices = new uint32[](secondIndicesLength); + uint256[] memory secondIndices = new uint256[](secondIndicesLength); for (uint256 i = 0; i < secondIndicesLength; ++i) { - secondIndices[i] = deletionIndices[i]; + secondIndices[i] = packedDeletionIndices[i]; } bytes memory firstCallData = abi.encodeCall( - ManagerImpl.deleteIdentities, (actualProof, newPreRoot, deletionIndices, newPostRoot) + ManagerImpl.deleteIdentities, + (actualProof, deletionBatchSize, packedDeletionIndices, newPreRoot, newPostRoot) ); uint256 secondPostRoot = uint256(newPostRoot) + 1; bytes memory secondCallData = abi.encodeCall( - ManagerImpl.deleteIdentities, (actualProof, newPostRoot, secondIndices, secondPostRoot) + ManagerImpl.deleteIdentities, + (actualProof, deletionBatchSize, secondIndices, newPostRoot, secondPostRoot) ); vm.expectEmit(true, true, true, true); - emit VerifiedProof(deletionIndices.length); + emit VerifiedProof(packedDeletionIndices.length); // Test assertCallSucceedsOn(identityManagerAddress, firstCallData); vm.expectEmit(true, true, true, true); - emit VerifiedProof(deletionIndices.length / 2); + emit VerifiedProof(packedDeletionIndices.length / 2); assertCallSucceedsOn(identityManagerAddress, secondCallData); } @@ -165,17 +176,17 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { function testCannotDeleteIdentitiesWithInvalidBatchSize( uint128[8] memory prf, uint128 newPreRoot, - uint32[] memory deletionIndices, + uint256[] memory packedDeletionIndices, uint128 newPostRoot ) public { vm.assume(SimpleVerify.isValidInput(uint256(prf[0]))); vm.assume(newPreRoot != newPostRoot); - vm.assume(deletionIndices.length > 0); + vm.assume(packedDeletionIndices.length > 0); ( VerifierLookupTable insertVerifiers, VerifierLookupTable deletionVerifiers, VerifierLookupTable updateVerifiers - ) = makeVerifierLookupTables(TC.makeDynArray([deletionIndices.length - 1])); + ) = makeVerifierLookupTables(TC.makeDynArray([packedDeletionIndices.length - 1])); makeNewIdentityManager( treeDepth, newPreRoot, @@ -187,7 +198,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { uint256[8] memory actualProof = prepareDeleteIdentitiesTestCase(prf); bytes memory callData = abi.encodeCall( - ManagerImpl.deleteIdentities, (actualProof, newPreRoot, deletionIndices, newPostRoot) + ManagerImpl.deleteIdentities, + (actualProof, deletionBatchSize, packedDeletionIndices, newPreRoot, newPostRoot) ); bytes memory errorData = abi.encodeWithSelector(VerifierLookupTable.NoSuchVerifier.selector); @@ -199,18 +211,20 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { function testCannotDeleteIdentitiesWithIncorrectInputs( uint128[8] memory prf, uint128 newPreRoot, - uint32[] memory deletionIndices, + uint256[] memory packedDeletionIndices, uint128 newPostRoot ) public { // Setup vm.assume(!SimpleVerify.isValidInput(uint256(prf[0]))); vm.assume(newPreRoot != newPostRoot); - vm.assume(deletionIndices.length <= 1000); + vm.assume(packedDeletionIndices.length <= 1000); + uint32 indicesLength = uint32(packedDeletionIndices.length * 8); + ( VerifierLookupTable insertVerifiers, VerifierLookupTable deletionVerifiers, VerifierLookupTable updateVerifiers - ) = makeVerifierLookupTables(TC.makeDynArray([deletionIndices.length])); + ) = makeVerifierLookupTables(TC.makeDynArray([40])); makeNewIdentityManager( treeDepth, newPreRoot, @@ -221,7 +235,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { ); uint256[8] memory actualProof = prepareDeleteIdentitiesTestCase(prf); bytes memory callData = abi.encodeCall( - ManagerImpl.deleteIdentities, (actualProof, newPreRoot, deletionIndices, newPostRoot) + ManagerImpl.deleteIdentities, + (actualProof,indicesLength, packedDeletionIndices, newPreRoot, newPostRoot) ); bytes memory expectedError = abi.encodeWithSelector(ManagerImplV1.ProofValidationFailure.selector); @@ -252,7 +267,7 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { bytes memory deletionCallData = abi.encodeCall( ManagerImpl.deleteIdentities, - (deletionProof, deletionPreRoot, deletionIndices, newPostRoot) + (deletionProof, deletionBatchSize, packedDeletionIndices, deletionPreRoot, newPostRoot) ); bytes memory expectedError = abi.encodeWithSelector(ManagerImplV1.ProofValidationFailure.selector); @@ -268,7 +283,13 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { vm.assume(nonOperator != address(this) && nonOperator != address(0x0)); bytes memory callData = abi.encodeCall( ManagerImpl.deleteIdentities, - (deletionProof, deletionPreRoot, deletionIndices, deletionPostRoot) + ( + deletionProof, + deletionBatchSize, + packedDeletionIndices, + deletionPreRoot, + deletionPostRoot + ) ); bytes memory errorData = abi.encodeWithSelector(ManagerImplV1.Unauthorized.selector, nonOperator); @@ -298,7 +319,7 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { ); bytes memory callData = abi.encodeCall( ManagerImpl.deleteIdentities, - (deletionProof, actualRoot, deletionIndices, deletionPostRoot) + (deletionProof, deletionBatchSize, packedDeletionIndices, actualRoot, deletionPostRoot) ); bytes memory expectedError = abi.encodeWithSelector( ManagerImplV1.NotLatestRoot.selector, actualRoot, uint256(currentPreRoot) @@ -315,7 +336,7 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { uint256 newPreRoot = SNARK_SCALAR_FIELD + i; bytes memory callData = abi.encodeCall( ManagerImpl.deleteIdentities, - (deletionProof, newPreRoot, deletionIndices, deletionPostRoot) + (deletionProof, deletionBatchSize, packedDeletionIndices, newPreRoot, deletionPostRoot) ); bytes memory expectedError = abi.encodeWithSelector( ManagerImplV1.UnreducedElement.selector, @@ -333,7 +354,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { // Setup uint256 newPostRoot = SNARK_SCALAR_FIELD + i; bytes memory callData = abi.encodeCall( - ManagerImpl.deleteIdentities, (deletionProof, initialRoot, deletionIndices, newPostRoot) + ManagerImpl.deleteIdentities, + (deletionProof, deletionBatchSize, packedDeletionIndices, initialRoot, newPostRoot) ); bytes memory expectedError = abi.encodeWithSelector( ManagerImplV1.UnreducedElement.selector, @@ -353,6 +375,8 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { vm.prank(expectedOwner); // Test - managerImpl.deleteIdentities(deletionProof, initialRoot, deletionIndices, deletionPostRoot); + managerImpl.deleteIdentities( + deletionProof, deletionBatchSize, packedDeletionIndices, initialRoot, deletionPostRoot + ); } } diff --git a/src/test/identity-manager/WorldIDIdentityManagerTest.sol b/src/test/identity-manager/WorldIDIdentityManagerTest.sol index cd77fc3..9a5dc39 100644 --- a/src/test/identity-manager/WorldIDIdentityManagerTest.sol +++ b/src/test/identity-manager/WorldIDIdentityManagerTest.sol @@ -70,12 +70,13 @@ contract WorldIDIdentityManagerTest is WorldIDTest { // All hardcoded test data taken from `src/test/data/TestDeletionParams.json`. This will be dynamically // generated at some point in the future. bytes32 internal constant deletionInputHash = - 0xfe7bd6158c7603ed86cef4dbe90a417fe7c16e94a730ae75ff0135837c6f4dd1; + 0x227590f99431e20f2f95fdfb1b7dfb648c04242c950c31263ba165647c96501a; uint256 internal constant deletionPreRoot = - 0x218676b10b4d8c25fce789f3b13f2b3e49497ce0b20f57bacd7dfda85c0b6ac2; + 0x18cb13df3e79b9f847a1494d0a2e6f3cc0041d9cae7e5ccb8cd1852ecdc4af58; uint256 internal constant deletionPostRoot = - 0x7c453712267d1cca763c6da89bb632bd85bf9d8b48ef71bd0b7595f81357edb; - uint32[] deletionIndices = [0, 2, 4]; + 0x82fcf94594d7363636338e2c29242cc77e3d04f36c8ad64d294d2ab4d251708; + uint256[] packedDeletionIndices = [0x20000000400000006000000080000000a0000000c0000000e]; + uint32 deletionBatchSize = 8; uint256[8] deletionProof; // Needed for testing things. @@ -117,14 +118,14 @@ contract WorldIDIdentityManagerTest is WorldIDTest { // Create the deletion proof term. deletionProof = [ - 0x10145dce25fb4a9a1e4e305873c2a7ac91075da0db580fb1f6eeffa33ef52f5, - 0x192814271941d11d6185e154da26f194e07472704a0f94ec7bffc4fc1e3bbb40, - 0x3bfad23cb9da38fb86524c50c6dc69e3439ee56037ed559a7cf5851326d5922, - 0x2ea282b1ac2aa9faf003c7346d294cf77b78027db61a6165e5c461ac9fcc7e0c, - 0x2fdf35f34b7f3b97ce8bdf2a0641c25cb07cb67350ef9757b43a0b7778a73a5d, - 0xf2f797f11e59fe3d034777f97378f7d5f7702474b545e52c01db129f9555425, - 0x19f3b8fa4f138d70da5b0afea373f2eff69c58377f15c089062a463d3dfa6c65, - 0x2c53aeeaf305844fad88b917bf7fffbf5d57a384b6d959a957cf31fe8eb3779f + 0x226cb5c88ce8ccf2774dc13847c3b579c4e4bc8d47bfc2a9ac1454e1a9a42ee3, + 0x1e69ced73a40a88c9f68df4a1bf34c3ff67efca6e2682bd8d1bb96a7a3e4bf50, + 0x1029d8179a82355f902562af0f0e719e31ac12f63effb0c9006ee3332c280e01, + 0x24ae80c2f18161206a0eacc736ddef2c518e0dec37e13c6f0cf17034d04508cc, + 0x29213a2cb6582178edd743f8e8b5541175855b55d0c90f1894a1e415b625af70, + 0x2c9119a368d137dd2409dee4796eb96059296f87009e3d47b0a858cfd05d6954, + 0x2cdd77b17d2270a8fe1385ec60fdd6c644f83549331ae116a538c555f56a9540, + 0x1f7214627223f7839a538052d96ad480a9565a6ec8a9e1fcecf54a7d73a55495 ]; } diff --git a/src/test/identity-manager/WorldIDIdentityManagerUninit.t.sol b/src/test/identity-manager/WorldIDIdentityManagerUninit.t.sol index 2eeda19..594f70c 100644 --- a/src/test/identity-manager/WorldIDIdentityManagerUninit.t.sol +++ b/src/test/identity-manager/WorldIDIdentityManagerUninit.t.sol @@ -43,7 +43,13 @@ contract WorldIDIdentityManagerUninit is WorldIDIdentityManagerTest { makeUninitIdentityManager(); bytes memory callData = abi.encodeCall( ManagerImpl.deleteIdentities, - (deletionProof, insertionPreRoot, deletionIndices, insertionPostRoot) + ( + deletionProof, + deletionBatchSize, + packedDeletionIndices, + deletionPreRoot, + deletionPostRoot + ) ); bytes memory expectedError = abi.encodeWithSelector(CheckInitialized.ImplementationNotInitialized.selector);