Skip to content

Commit

Permalink
4844 tests to dedicated contract: testCannotRegisterIdentitiesIfPostR…
Browse files Browse the repository at this point in the history
…ootIncorrect
  • Loading branch information
wzmuda committed Aug 22, 2024
1 parent 9a359ca commit 89ac500
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {TypeConverter as TC} from "../utils/TypeConverter.sol";
import {Verifier as TreeVerifier} from "src/test/InsertionTreeVerifier164844.sol";
import {VerifierLookupTable} from "../../data/VerifierLookupTable.sol";

import {WorldIDIdentityManager as IdentityManager} from "../../WorldIDIdentityManager.sol";
import {WorldIDIdentityManagerImplV2 as ManagerImpl} from "../../WorldIDIdentityManagerImplV2.sol";
import {WorldIDIdentityManagerImplV1 as ManagerImplV1} from "../../WorldIDIdentityManagerImplV1.sol";
import {WorldIDIdentityManagerImplV3 as ManagerImplV3} from "../../WorldIDIdentityManagerImplV3.sol";

Expand Down Expand Up @@ -422,4 +424,68 @@ contract WorldIDIdentityManagerIdentityRegistration4844 is WorldIDIdentityManage
// Test
assertCallFailsOn(identityManagerAddress, registerCallData, expectedError);
}

/// @notice Checks that it reverts if the provided post root is incorrect.
function testCannotRegisterIdentitiesIfPostRootIncorrect(uint256 newPostRoot) public {
// Setup
vm.assume(newPostRoot != insertionPostRoot && newPostRoot < SNARK_SCALAR_FIELD);
managerImplV2 = new ManagerImpl();
managerImplV2Address = address(managerImplV2);
ITreeVerifier actualVerifier = new TreeVerifier();
(
VerifierLookupTable insertVerifiers,
VerifierLookupTable deletionVerifiers,
VerifierLookupTable updateVerifiers
) = makeVerifierLookupTables(TC.makeDynArray([70]));
insertVerifiers.addVerifier(identityCommitmentsSize, actualVerifier);

bytes memory callData = abi.encodeCall(
ManagerImplV1.initialize,
(treeDepth, insertionPreRoot, insertVerifiers, updateVerifiers, semaphoreVerifier)
);

identityManager = new IdentityManager(managerImplV2Address, callData);
identityManagerAddress = address(identityManager);

// Init V2
bytes memory initCallV2 = abi.encodeCall(ManagerImpl.initializeV2, (deletionVerifiers));
bytes memory upgradeCall = abi.encodeCall(
UUPSUpgradeable.upgradeToAndCall, (address(managerImplV2Address), initCallV2)
);
assertCallSucceedsOn(identityManagerAddress, upgradeCall, new bytes(0x0));

// Init V3
managerImplV3 = new ManagerImplV3();
managerImplV3Address = address(managerImplV3);
bytes memory initCallV3 = abi.encodeCall(managerImplV3.initializeV3, (insertVerifiers));
bytes memory upgradeCallV3 = abi.encodeCall(
UUPSUpgradeable.upgradeToAndCall, (address(managerImplV3Address), initCallV3)
);
assertCallSucceedsOn(identityManagerAddress, upgradeCallV3, new bytes(0x0));

ManagerImplV3.RegisterIdentities4844Params memory params = ManagerImplV3.RegisterIdentities4844Params({
insertionProof: insertionProof,
commitments: commitments,
commitmentPok: commitmentsPok,
kzgCommitment: kzgCommitment,
kzgProof: kzgProof,
expectedEvaluation: insertionExpectedEvaluation,
preRoot: insertionPreRoot,
postRoot: newPostRoot,
kzgChallenge: kzgChallenge,
inputHash: insertionInputHash4844,
batchSize: uint32(identityCommitments.length),
startIndex: startIndex
});

// Mock blobhash. This is valid for the next call only.
prepareBlobhash(kzgToVersionedHash(kzgCommitment));
bytes memory registerCallData = abi.encodeCall(ManagerImplV3.registerIdentities, params);

bytes memory expectedError =
abi.encodeWithSelector(ManagerImplV1.ProofValidationFailure.selector);

// Test
assertCallFailsOn(identityManagerAddress, registerCallData, expectedError);
}
}

0 comments on commit 89ac500

Please sign in to comment.