Skip to content

Commit

Permalink
fix to use bytes calldata instead of uint256[]
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbuild3r committed Sep 7, 2023
1 parent 636f818 commit 64ea079
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/WorldIDIdentityManagerImplV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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])));
Expand Down Expand Up @@ -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);

(
Expand Down
2 changes: 1 addition & 1 deletion src/test/identity-manager/WorldIDIdentityManagerTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 64ea079

Please sign in to comment.