Skip to content

Commit

Permalink
Merge pull request #26 from 0xPolygonID/feature/iden3-contracts-2-0-1
Browse files Browse the repository at this point in the history
update to "@iden3/contracts": "2.0.1"
  • Loading branch information
vmidyllic authored Apr 16, 2024
2 parents 2ba06e3 + d27d2e7 commit de37f7b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 55 deletions.
46 changes: 28 additions & 18 deletions on-chain-verification/contracts/ERC20Verifier.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
// 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 */,
uint256[] memory inputs,
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
Expand Down Expand Up @@ -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);
}

}
6 changes: 3 additions & 3 deletions on-chain-verification/contracts/Imports.sol
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 1 addition & 1 deletion on-chain-verification/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
67 changes: 42 additions & 25 deletions on-chain-verification/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions on-chain-verification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions on-chain-verification/scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions on-chain-verification/scripts/deployValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ async function main() {
const validators = [
{
verifierAddress: "0x357Bb671fEb5577d310410eab93291B4De04a834",
validatorContractName: "CredentialAtomicQueryMTPValidator",
validatorContractName: "CredentialAtomicQueryMTPV2Validator",
},
{
verifierAddress: "0xf635aCA4E8B5268aA9Bf8E226907C27383fC9686",
validatorContractName: "CredentialAtomicQuerySigValidator",
validatorContractName: "CredentialAtomicQuerySigV2Validator",
},
];
const deployInfo = [];
Expand Down

0 comments on commit de37f7b

Please sign in to comment.