Skip to content

Commit

Permalink
4844 tests to dedicated contract: testCannotRegisterIdentitiesWithOut…
Browse files Browse the repository at this point in the history
…datedRoot
  • Loading branch information
wzmuda committed Aug 22, 2024
1 parent 78b1b8f commit 21fafe7
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,51 @@ contract WorldIDIdentityManagerIdentityRegistration4844 is WorldIDIdentityManage
// Test
assertCallFailsOn(identityManagerAddress, callData, errorData);
}

/// @notice Tests that it reverts if an attempt is made to register identities with an outdated
/// root.
function testCannotRegisterIdentitiesWithOutdatedRoot(
uint256 currentPreRoot,
uint256 actualRoot
) public {
// Setup
vm.assume(
currentPreRoot != actualRoot && currentPreRoot < SNARK_SCALAR_FIELD
&& actualRoot < SNARK_SCALAR_FIELD
);
makeNewIdentityManager(
treeDepth,
uint256(currentPreRoot),
defaultInsertVerifiers,
defaultDeletionVerifiers,
defaultUpdateVerifiers,
semaphoreVerifier
);

ManagerImplV3.RegisterIdentities4844Params memory params = ManagerImplV3.RegisterIdentities4844Params({
insertionProof: insertionProof,
commitments: commitments,
commitmentPok: commitmentsPok,
kzgCommitment: kzgCommitment,
kzgProof: kzgProof,
expectedEvaluation: insertionExpectedEvaluation,
preRoot: actualRoot,
postRoot: insertionPostRoot,
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 callData = abi.encodeCall(ManagerImplV3.registerIdentities, params);

bytes memory expectedError = abi.encodeWithSelector(
ManagerImplV1.NotLatestRoot.selector, actualRoot, uint256(currentPreRoot)
);

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

0 comments on commit 21fafe7

Please sign in to comment.