diff --git a/src/WorldIDIdentityManagerImplV2.sol b/src/WorldIDIdentityManagerImplV2.sol index da452bc..dd4bcf4 100644 --- a/src/WorldIDIdentityManagerImplV2.sol +++ b/src/WorldIDIdentityManagerImplV2.sol @@ -99,7 +99,7 @@ contract WorldIDIdentityManagerImplV2 is WorldIDIdentityManagerImplV1 { function deleteIdentities( uint256[8] calldata deletionProof, uint32 batchSize, - uint256[] calldata packedDeletionIndices, + bytes calldata packedDeletionIndices, uint256 preRoot, uint256 postRoot ) public virtual onlyProxy onlyInitialized onlyIdentityOperator { @@ -213,12 +213,15 @@ contract WorldIDIdentityManagerImplV2 is WorldIDIdentityManagerImplV1 { /// /// @return hash The input hash calculated as described below. /// + /// @dev the deletion indices are packed into a uint256[] array where each element of the array + /// packs 8 different uint32 indices, + /// /// We keccak hash all input to save verification gas. Inputs are arranged as follows: /// /// deletionIndices[0] || deletionIndices[1] || ... || deletionIndices[batchSize-1] || PreRoot || PostRoot /// 32 || 32 || ... || 32 || 256 || 256 function calculateIdentityDeletionInputHash( - uint256[] calldata packedDeletionIndices, + bytes calldata packedDeletionIndices, uint256 preRoot, uint256 postRoot, uint32 batchSize diff --git a/src/test/identity-manager/WorldIDIdentityManagerIdentityDeletion.t.sol b/src/test/identity-manager/WorldIDIdentityManagerIdentityDeletion.t.sol index a8985b2..c916f13 100644 --- a/src/test/identity-manager/WorldIDIdentityManagerIdentityDeletion.t.sol +++ b/src/test/identity-manager/WorldIDIdentityManagerIdentityDeletion.t.sol @@ -13,6 +13,8 @@ import {WorldIDIdentityManager as IdentityManager} from "../../WorldIDIdentityMa import {WorldIDIdentityManagerImplV2 as ManagerImpl} from "../../WorldIDIdentityManagerImplV2.sol"; import {WorldIDIdentityManagerImplV1 as ManagerImplV1} from "../../WorldIDIdentityManagerImplV1.sol"; +import {console} from "forge-std/console.sol"; + /// @title World ID Identity Manager Identity Deletion Tests /// @notice Contains tests for the WorldID identity manager. /// @author Worldcoin @@ -76,7 +78,7 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { function testDeleteIdentitiesWithCorrectInputs( uint128[8] memory prf, uint128 newPreRoot, - uint256[] memory packedDeletionIndices, + bytes calldata packedDeletionIndices, uint128 newPostRoot, address identityOperator ) public { @@ -129,15 +131,16 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { function testDeleteIdentitiesSelectsCorrectVerifier( uint128[8] memory prf, uint128 newPreRoot, - uint256[] memory packedDeletionIndices, + bytes calldata packedDeletionIndices, uint128 newPostRoot ) public { vm.assume(SimpleVerify.isValidInput(uint256(prf[0]))); vm.assume(newPreRoot != newPostRoot); - vm.assume(packedDeletionIndices.length <= 125 && packedDeletionIndices.length > 0); - uint256 secondIndicesArrayLength = 1; - // Half of the first batch of 8 - uint32 secondIndicesLength = uint32(4); + vm.assume(packedDeletionIndices.length <= 1000 && packedDeletionIndices.length > 0); + + bytes memory secondIndices = abi.encodePacked(uint32(0), uint32(2), uint32(4), uint32(6)); + uint32 secondIndicesLength = uint32(secondIndices.length); + ( VerifierLookupTable insertVerifiers, VerifierLookupTable deletionVerifiers, @@ -152,10 +155,6 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { semaphoreVerifier ); uint256[8] memory actualProof = prepareDeleteIdentitiesTestCase(prf); - uint256[] memory secondIndices = new uint256[](secondIndicesArrayLength); - for (uint256 i = 0; i < secondIndicesArrayLength; ++i) { - secondIndices[i] = packedDeletionIndices[i]; - } bytes memory firstCallData = abi.encodeCall( ManagerImpl.deleteIdentities, (actualProof, deletionBatchSize, packedDeletionIndices, newPreRoot, newPostRoot) @@ -182,7 +181,7 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { function testCannotDeleteIdentitiesWithInvalidBatchSize( uint128[8] memory prf, uint128 newPreRoot, - uint256[] memory packedDeletionIndices, + bytes calldata packedDeletionIndices, uint128 newPostRoot ) public { vm.assume(SimpleVerify.isValidInput(uint256(prf[0]))); @@ -217,13 +216,13 @@ contract WorldIDIdentityManagerIdentityDeletion is WorldIDIdentityManagerTest { function testCannotDeleteIdentitiesWithIncorrectInputs( uint128[8] memory prf, uint128 newPreRoot, - uint256[] memory packedDeletionIndices, + bytes calldata packedDeletionIndices, uint128 newPostRoot ) public { // Setup vm.assume(!SimpleVerify.isValidInput(uint256(prf[0]))); vm.assume(newPreRoot != newPostRoot); - vm.assume(packedDeletionIndices.length <= 125); + vm.assume(packedDeletionIndices.length <= 1000); uint32 indicesLength = uint32(packedDeletionIndices.length * 8); ( diff --git a/src/test/identity-manager/WorldIDIdentityManagerTest.sol b/src/test/identity-manager/WorldIDIdentityManagerTest.sol index 9a5dc39..0a47834 100644 --- a/src/test/identity-manager/WorldIDIdentityManagerTest.sol +++ b/src/test/identity-manager/WorldIDIdentityManagerTest.sol @@ -75,7 +75,7 @@ contract WorldIDIdentityManagerTest is WorldIDTest { 0x18cb13df3e79b9f847a1494d0a2e6f3cc0041d9cae7e5ccb8cd1852ecdc4af58; uint256 internal constant deletionPostRoot = 0x82fcf94594d7363636338e2c29242cc77e3d04f36c8ad64d294d2ab4d251708; - uint256[] packedDeletionIndices = [0x20000000400000006000000080000000a0000000c0000000e]; + bytes packedDeletionIndices = abi.encodePacked(uint32(0), uint32(2), uint32(4), uint32(6),uint32(8),uint32(10),uint32(12),uint32(14)); uint32 deletionBatchSize = 8; uint256[8] deletionProof;