Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/unifersal verifier as public service #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion contracts/examples/ERC20LinkedUniversalVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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(
Expand Down
13 changes: 0 additions & 13 deletions contracts/examples/ERC20Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down