diff --git a/on-chain-verification/contracts/ERC20Verifier.sol b/on-chain-verification/contracts/ERC20Verifier.sol index e089b07..75d204f 100644 --- a/on-chain-verification/contracts/ERC20Verifier.sol +++ b/on-chain-verification/contracts/ERC20Verifier.sol @@ -1,24 +1,36 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.16; +pragma solidity 0.8.20; -import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import {ERC20Upgradeable} from '@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol'; import {PrimitiveTypeUtils} from "@iden3/contracts/lib/PrimitiveTypeUtils.sol"; import {ICircuitValidator} from "@iden3/contracts/interfaces/ICircuitValidator.sol"; import {ZKPVerifier} from "@iden3/contracts/verifiers/ZKPVerifier.sol"; -contract ERC20Verifier is ERC20, ZKPVerifier { +contract ERC20Verifier is ERC20Upgradeable, ZKPVerifier { uint64 public constant TRANSFER_REQUEST_ID = 1; mapping(uint256 => address) public idToAddress; mapping(address => uint256) public addressToId; - uint256 public TOKEN_AMOUNT_FOR_AIRDROP_PER_ID = - 5 * 10 ** uint256(decimals()); + uint256 public TOKEN_AMOUNT_FOR_AIRDROP_PER_ID; - constructor( - string memory name_, - string memory symbol_ - ) ERC20(name_, symbol_) {} + modifier beforeTransfer(address to) { + MainStorage storage s = _getMainStorage(); + require( + s.proofs[to][TRANSFER_REQUEST_ID] == true, + "only identities who provided proof are allowed to receive tokens" + ); + _; + } + + function initialize( + string memory name, + string memory symbol + ) public initializer { + super.__ERC20_init(name, symbol); + super.__ZKPVerifier_init(_msgSender()); + TOKEN_AMOUNT_FOR_AIRDROP_PER_ID = 5 * 10 ** uint256(decimals()); + } function _beforeProofSubmit( uint64 /* requestId */, @@ -26,7 +38,7 @@ contract ERC20Verifier is ERC20, ZKPVerifier { ICircuitValidator validator ) internal view override { // check that challenge input is address of sender - address addr = PrimitiveTypeUtils.int256ToAddress( + address addr = PrimitiveTypeUtils.uint256LEToAddress( inputs[validator.inputIndexOf("challenge")] ); // this is linking between msg.sender and @@ -56,14 +68,12 @@ contract ERC20Verifier is ERC20, ZKPVerifier { } } - function _beforeTokenTransfer( - address /* from */, + function _update( + address from /* from */, address to, - uint256 /* amount */ - ) internal view override { - require( - proofs[to][TRANSFER_REQUEST_ID] == true, - "only identities who provided proof are allowed to receive tokens" - ); + uint256 amount /* amount */ + ) internal override beforeTransfer(to) { + super._update(from, to, amount); } + } diff --git a/on-chain-verification/contracts/Imports.sol b/on-chain-verification/contracts/Imports.sol index f9a489f..3167725 100644 --- a/on-chain-verification/contracts/Imports.sol +++ b/on-chain-verification/contracts/Imports.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity 0.8.16; +pragma solidity 0.8.20; -import {CredentialAtomicQueryMTPValidator} from "@iden3/contracts/validators/CredentialAtomicQueryMTPValidator.sol"; -import {CredentialAtomicQuerySigValidator} from "@iden3/contracts/validators/CredentialAtomicQuerySigValidator.sol"; +import {CredentialAtomicQueryMTPV2Validator} from "@iden3/contracts/validators/CredentialAtomicQueryMTPV2Validator.sol"; +import {CredentialAtomicQuerySigV2Validator} from "@iden3/contracts/validators/CredentialAtomicQuerySigV2Validator.sol"; diff --git a/on-chain-verification/hardhat.config.js b/on-chain-verification/hardhat.config.js index 3a45d97..215f4f4 100644 --- a/on-chain-verification/hardhat.config.js +++ b/on-chain-verification/hardhat.config.js @@ -3,7 +3,7 @@ require('dotenv').config(); require('@openzeppelin/hardhat-upgrades'); module.exports = { - solidity: "0.8.16", + solidity: "0.8.20", networks: { mumbai: { chainId: 80001, diff --git a/on-chain-verification/package-lock.json b/on-chain-verification/package-lock.json index 56d2e6b..c0cc916 100644 --- a/on-chain-verification/package-lock.json +++ b/on-chain-verification/package-lock.json @@ -10,12 +10,12 @@ "license": "ISC", "dependencies": { "@0xpolygonid/js-sdk": "1.4.1", - "@iden3/contracts": "1.4.5", + "@iden3/contracts": "2.0.1", "@iden3/js-crypto": "1.0.3", "@iden3/js-iden3-core": "1.1.0", "@nomiclabs/hardhat-waffle": "^2.0.3", - "@openzeppelin/contracts": "^4.7.3", - "@openzeppelin/contracts-upgradeable": "^4.7.3", + "@openzeppelin/contracts": "^5.0.1", + "@openzeppelin/contracts-upgradeable": "^5.0.1", "@openzeppelin/hardhat-upgrades": "^1.22.1", "dotenv": "^16.0.2", "solidity-bytes-utils": "^0.8.0", @@ -1695,12 +1695,13 @@ } }, "node_modules/@iden3/contracts": { - "version": "1.4.5", - "resolved": "https://registry.npmjs.org/@iden3/contracts/-/contracts-1.4.5.tgz", - "integrity": "sha512-XSd3iFMMU6goMPU88eexQtAydCq9QaT7LD4dHLPJhuZJPF390Ad6XIcfAFU8mUylNU7C+XpzPzNG7qytZitqzQ==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@iden3/contracts/-/contracts-2.0.1.tgz", + "integrity": "sha512-T9GsbS19W5ACUhg69sbm4OelnIYKWPEXO6I7iiEwWpsbQjVUXEh+jJMdrut/+OBVLskuBgJJPqVsJNSwiLEeGA==", "dependencies": { - "@openzeppelin/contracts": "^4.7.3", - "@openzeppelin/contracts-upgradeable": "^4.8.2" + "@openzeppelin/contracts": "^5.0.1", + "@openzeppelin/contracts-upgradeable": "^5.0.1", + "@openzeppelin/contracts-upgradeable-v4": "npm:@openzeppelin/contracts-upgradeable@^4.9.5" } }, "node_modules/@iden3/js-crypto": { @@ -2400,14 +2401,23 @@ } }, "node_modules/@openzeppelin/contracts": { - "version": "4.7.3", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.7.3.tgz", - "integrity": "sha512-dGRS0agJzu8ybo44pCIf3xBaPQN/65AIXNgK8+4gzKd5kbvlqyxryUYVLJv7fK98Seyd2hDZzVEHSWAh0Bt1Yw==" + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.0.2.tgz", + "integrity": "sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA==" }, "node_modules/@openzeppelin/contracts-upgradeable": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.3.tgz", - "integrity": "sha512-jjaHAVRMrE4UuZNfDwjlLGDxTHWIOwTJS2ldnc278a0gevfXfPr8hxKEVBGFBE96kl2G3VHDZhUimw/+G3TG2A==" + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.0.2.tgz", + "integrity": "sha512-0MmkHSHiW2NRFiT9/r5Lu4eJq5UJ4/tzlOgYXNAIj/ONkQTVnz22pLxDvp4C4uZ9he7ZFvGn3Driptn1/iU7tQ==", + "peerDependencies": { + "@openzeppelin/contracts": "5.0.2" + } + }, + "node_modules/@openzeppelin/contracts-upgradeable-v4": { + "name": "@openzeppelin/contracts-upgradeable", + "version": "4.9.6", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.6.tgz", + "integrity": "sha512-m4iHazOsOCv1DgM7eD7GupTJ+NFVujRZt1wzddDPSVGpWdKq1SKkla5htKG7+IS4d2XOCtzkUNwRZ7Vq5aEUMA==" }, "node_modules/@openzeppelin/hardhat-upgrades": { "version": "1.22.1", @@ -26581,12 +26591,13 @@ } }, "@iden3/contracts": { - "version": "1.4.5", - "resolved": "https://registry.npmjs.org/@iden3/contracts/-/contracts-1.4.5.tgz", - "integrity": "sha512-XSd3iFMMU6goMPU88eexQtAydCq9QaT7LD4dHLPJhuZJPF390Ad6XIcfAFU8mUylNU7C+XpzPzNG7qytZitqzQ==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@iden3/contracts/-/contracts-2.0.1.tgz", + "integrity": "sha512-T9GsbS19W5ACUhg69sbm4OelnIYKWPEXO6I7iiEwWpsbQjVUXEh+jJMdrut/+OBVLskuBgJJPqVsJNSwiLEeGA==", "requires": { - "@openzeppelin/contracts": "^4.7.3", - "@openzeppelin/contracts-upgradeable": "^4.8.2" + "@openzeppelin/contracts": "^5.0.1", + "@openzeppelin/contracts-upgradeable": "^5.0.1", + "@openzeppelin/contracts-upgradeable-v4": "npm:@openzeppelin/contracts-upgradeable@^4.9.5" } }, "@iden3/js-crypto": { @@ -27067,14 +27078,20 @@ } }, "@openzeppelin/contracts": { - "version": "4.7.3", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.7.3.tgz", - "integrity": "sha512-dGRS0agJzu8ybo44pCIf3xBaPQN/65AIXNgK8+4gzKd5kbvlqyxryUYVLJv7fK98Seyd2hDZzVEHSWAh0Bt1Yw==" + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.0.2.tgz", + "integrity": "sha512-ytPc6eLGcHHnapAZ9S+5qsdomhjo6QBHTDRRBFfTxXIpsicMhVPouPgmUPebZZZGX7vt9USA+Z+0M0dSVtSUEA==" }, "@openzeppelin/contracts-upgradeable": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.3.tgz", - "integrity": "sha512-jjaHAVRMrE4UuZNfDwjlLGDxTHWIOwTJS2ldnc278a0gevfXfPr8hxKEVBGFBE96kl2G3VHDZhUimw/+G3TG2A==" + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.0.2.tgz", + "integrity": "sha512-0MmkHSHiW2NRFiT9/r5Lu4eJq5UJ4/tzlOgYXNAIj/ONkQTVnz22pLxDvp4C4uZ9he7ZFvGn3Driptn1/iU7tQ==", + "requires": {} + }, + "@openzeppelin/contracts-upgradeable-v4": { + "version": "npm:@openzeppelin/contracts-upgradeable@4.9.6", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.6.tgz", + "integrity": "sha512-m4iHazOsOCv1DgM7eD7GupTJ+NFVujRZt1wzddDPSVGpWdKq1SKkla5htKG7+IS4d2XOCtzkUNwRZ7Vq5aEUMA==" }, "@openzeppelin/hardhat-upgrades": { "version": "1.22.1", diff --git a/on-chain-verification/package.json b/on-chain-verification/package.json index 0e02da9..a744d08 100644 --- a/on-chain-verification/package.json +++ b/on-chain-verification/package.json @@ -10,10 +10,10 @@ "author": "", "license": "ISC", "dependencies": { - "@iden3/contracts": "1.4.5", + "@iden3/contracts": "2.0.1", "@nomiclabs/hardhat-waffle": "^2.0.3", - "@openzeppelin/contracts": "^4.7.3", - "@openzeppelin/contracts-upgradeable": "^4.7.3", + "@openzeppelin/contracts": "^5.0.1", + "@openzeppelin/contracts-upgradeable": "^5.0.1", "@openzeppelin/hardhat-upgrades": "^1.22.1", "dotenv": "^16.0.2", "solidity-bytes-utils": "^0.8.0", diff --git a/on-chain-verification/scripts/deploy.js b/on-chain-verification/scripts/deploy.js index 2456b51..748c1cf 100644 --- a/on-chain-verification/scripts/deploy.js +++ b/on-chain-verification/scripts/deploy.js @@ -4,9 +4,9 @@ async function main() { const verifierSymbol = "zkERC20"; const ERC20Verifier = await ethers.getContractFactory(verifierContract); - const erc20Verifier = await ERC20Verifier.deploy( - verifierName, - verifierSymbol + const erc20Verifier = await upgrades.deployProxy( + ERC20Verifier, + [verifierName, verifierSymbol] ); await erc20Verifier.deployed(); diff --git a/on-chain-verification/scripts/deployValidators.js b/on-chain-verification/scripts/deployValidators.js index 9fbe619..487ad47 100644 --- a/on-chain-verification/scripts/deployValidators.js +++ b/on-chain-verification/scripts/deployValidators.js @@ -10,11 +10,11 @@ async function main() { const validators = [ { verifierAddress: "0x357Bb671fEb5577d310410eab93291B4De04a834", - validatorContractName: "CredentialAtomicQueryMTPValidator", + validatorContractName: "CredentialAtomicQueryMTPV2Validator", }, { verifierAddress: "0xf635aCA4E8B5268aA9Bf8E226907C27383fC9686", - validatorContractName: "CredentialAtomicQuerySigValidator", + validatorContractName: "CredentialAtomicQuerySigV2Validator", }, ]; const deployInfo = [];