From 45705daf1d691f42f2238688e85731ebd0f50964 Mon Sep 17 00:00:00 2001 From: Andriian Chestnykh <> Date: Thu, 4 Apr 2024 16:00:34 +0100 Subject: [PATCH 1/2] Remove unnecessary hook --- contracts/examples/ERC20Verifier.sol | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/contracts/examples/ERC20Verifier.sol b/contracts/examples/ERC20Verifier.sol index 1166862..bacb7fc 100644 --- a/contracts/examples/ERC20Verifier.sol +++ b/contracts/examples/ERC20Verifier.sol @@ -44,19 +44,6 @@ contract ERC20Verifier is ERC20Upgradeable, ZKPVerifier { $.TOKEN_AMOUNT_FOR_AIRDROP_PER_ID = 5 * 10 ** uint256(decimals()); } - function _beforeProofSubmit( - uint64 /* requestId */, - uint256[] memory inputs, - ICircuitValidator validator - ) internal view override { - // check that challenge input is address of sender - address addr = PrimitiveTypeUtils.uint256LEToAddress( - inputs[validator.inputIndexOf('challenge')] - ); - // this is linking between msg.sender and - require(_msgSender() == addr, 'address in proof is not a sender address'); - } - function _afterProofSubmit( uint64 requestId, uint256[] memory inputs, From 92136f2f30ee4d246ddf8ce3ef2ef42a6287d13b Mon Sep 17 00:00:00 2001 From: Andriian Chestnykh <> Date: Fri, 5 Apr 2024 07:11:09 +0100 Subject: [PATCH 2/2] Add one time minting restriction to ERC20LinkedUniversalVerifier.sol --- contracts/examples/ERC20LinkedUniversalVerifier.sol | 11 ++++++++++- .../erc20-with-universal-verifier.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/contracts/examples/ERC20LinkedUniversalVerifier.sol b/contracts/examples/ERC20LinkedUniversalVerifier.sol index a6ec1cd..73469e8 100644 --- a/contracts/examples/ERC20LinkedUniversalVerifier.sol +++ b/contracts/examples/ERC20LinkedUniversalVerifier.sol @@ -12,6 +12,8 @@ contract ERC20LinkedUniversalVerifier is ERC20 { uint64 public constant TRANSFER_REQUEST_ID_MTP_VALIDATOR = 1; UniversalVerifier public verifier; + mapping(uint256 => address) public idToAddress; + mapping(address => uint256) public addressToId; uint256 public TOKEN_AMOUNT_FOR_AIRDROP_PER_ID = 5 * 10 ** uint256(decimals()); @@ -33,7 +35,14 @@ contract ERC20LinkedUniversalVerifier is ERC20 { } function mint(address to) public { - _mint(to, TOKEN_AMOUNT_FOR_AIRDROP_PER_ID); + uint256 id = verifier.getProofStorageField(to, TRANSFER_REQUEST_ID_SIG_VALIDATOR, "userID"); + id = id == 0 ? verifier.getProofStorageField(to, TRANSFER_REQUEST_ID_MTP_VALIDATOR, "userID") : id; + + if (idToAddress[id] == address(0) && addressToId[to] == 0) { + idToAddress[id] = to; + addressToId[to] = id; + _mint(to, TOKEN_AMOUNT_FOR_AIRDROP_PER_ID); + } } function _update( diff --git a/test/validators/universal-verifier/erc20-with-universal-verifier.ts b/test/validators/universal-verifier/erc20-with-universal-verifier.ts index b586d50..d01c2cd 100644 --- a/test/validators/universal-verifier/erc20-with-universal-verifier.ts +++ b/test/validators/universal-verifier/erc20-with-universal-verifier.ts @@ -33,7 +33,7 @@ describe('ERC 20 test', function () { let state: any, sig: any, mtp: any; let universalVerifier: Contract, erc20LinkedUniversalVerifier: Contract; - before(async () => { + beforeEach(async () => { const contractsSig = await deployValidatorContracts( 'VerifierSigWrapper', 'CredentialAtomicQuerySigV2Validator'