Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
4618dc6
init registration scripts
volodymyr-basiuk May 24, 2024
18be05c
cleanup
volodymyr-basiuk May 24, 2024
dd9f4ec
cleanup attest-tx
volodymyr-basiuk May 24, 2024
e5ee0f8
rm msg sender check
volodymyr-basiuk May 24, 2024
1aaf58e
set portal info
volodymyr-basiuk May 27, 2024
8ff8ecc
VeraxZKPVerifier
volodymyr-basiuk May 27, 2024
eff013f
Merge branch 'main' into poc/verax
volodymyr-basiuk May 27, 2024
943a7ae
import ZKPVerifierBase
volodymyr-basiuk May 27, 2024
a7656e4
move to verax folder and unique check
volodymyr-basiuk May 27, 2024
933282f
move setPortalInfo
volodymyr-basiuk May 27, 2024
361fd39
isNullifierAttested & readme
volodymyr-basiuk May 27, 2024
34f316b
add diagram
volodymyr-basiuk May 28, 2024
0b98432
full path diagram
volodymyr-basiuk May 28, 2024
ffe0e0b
add note
volodymyr-basiuk May 28, 2024
4d737d1
set expiration from inputs
volodymyr-basiuk May 28, 2024
a3bbb31
add state contract for genesis states only
volodymyr-basiuk May 31, 2024
c343c62
deploy
volodymyr-basiuk Jun 4, 2024
40c34cc
add set-requests for Anima
volodymyr-basiuk Jun 4, 2024
4460bff
fix eq true
volodymyr-basiuk Jun 5, 2024
a7d6670
request
volodymyr-basiuk Jun 5, 2024
88a031e
2003
volodymyr-basiuk Jun 5, 2024
bbb4073
jsonld-merklization
volodymyr-basiuk Jun 5, 2024
33348c2
PoL
volodymyr-basiuk Jun 5, 2024
00c96b0
package-lock
volodymyr-basiuk Jun 5, 2024
59f014e
AnimaProofOfLife set request
volodymyr-basiuk Jun 5, 2024
07ff6be
iden3 method
volodymyr-basiuk Jun 6, 2024
e820a09
allowedIssuers
volodymyr-basiuk Jun 6, 2024
96f248f
split PoU/PoL
volodymyr-basiuk Jun 12, 2024
26d8314
POU fix and request
volodymyr-basiuk Jun 12, 2024
f5f35ca
add run script
volodymyr-basiuk Jun 12, 2024
581d733
allowed issuer
volodymyr-basiuk Jun 12, 2024
d6ae9df
q
volodymyr-basiuk Jun 12, 2024
b5341cb
fix storage location
volodymyr-basiuk Jun 12, 2024
7fd6afa
replace indexes to named inputs
volodymyr-basiuk Jun 12, 2024
8ea7616
rename readonly state
volodymyr-basiuk Jun 12, 2024
bb399fb
clear comments
volodymyr-basiuk Jun 12, 2024
430e204
deploy artifacts after review
volodymyr-basiuk Jun 12, 2024
b0cdf3e
add verifications
volodymyr-basiuk Jun 13, 2024
c35f0d6
fix verify constructor args
volodymyr-basiuk Jun 13, 2024
1b53397
add linea config
volodymyr-basiuk Jun 13, 2024
8186a70
add defoult id type to linea
volodymyr-basiuk Jun 13, 2024
9f0419c
add msg.sender to ok event
volodymyr-basiuk Jun 13, 2024
3d031b9
changes after deploy to main
vmidyllic Jun 13, 2024
2f42747
add verifier upgrade
volodymyr-basiuk Jun 18, 2024
96b222d
fix attestation expiration
volodymyr-basiuk Jun 18, 2024
0735dc0
artifacts
vmidyllic Jun 18, 2024
f7f3ade
Merge pull request #45 from 0xPolygonID/poc/attestation-exp-fix
vmidyllic Jun 18, 2024
cfd650f
fix issuer
vmidyllic Jun 28, 2024
c793e0d
Merge branch 'main' into poc/verax-genesis-states
volodymyr-basiuk Jul 6, 2024
64aa7ca
upgrade to 2.0.4
vmidyllic Jul 6, 2024
233c96e
get reputation lvl count script
volodymyr-basiuk Jul 26, 2024
d8aa8fd
read all atestation till end
volodymyr-basiuk Aug 14, 2024
7758cf8
Merge branch 'main' into poc/verax-genesis-states
vmidyllic Aug 19, 2024
9c1fdf9
Merge branch 'main' into poc/verax-genesis-states
vmidyllic Aug 19, 2024
e25f29c
upgraded v3
vmidyllic Aug 19, 2024
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
2,010 changes: 2,010 additions & 0 deletions .openzeppelin/unknown-59141.json

Large diffs are not rendered by default.

1,961 changes: 1,961 additions & 0 deletions .openzeppelin/unknown-59144.json

Large diffs are not rendered by default.

475 changes: 475 additions & 0 deletions contracts/examples/ReadonlyState.sol

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions contracts/examples/verax/VeraxZKPVerifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {Attestation, AttestationPayload} from './types/Structs.sol';
import {ZKPVerifierBase} from '@iden3/contracts/verifiers/ZKPVerifierBase.sol';
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {IZKPVerifier} from '@iden3/contracts/interfaces/IZKPVerifier.sol';

interface IPortal {
function attest(AttestationPayload memory attestationPayload, bytes[] memory validationPayloads) external payable;
function attestationRegistry() external view returns (address);
}

interface AttestationRegistry {
function getAttestationIdCounter() external view returns (uint32);
event AttestationRegistered(bytes32 indexed attestationId);
function getAttestation(bytes32 attestationId) external view returns (Attestation memory);
}

contract VeraxZKPVerifier is Ownable2StepUpgradeable, ZKPVerifierBase {
event AttestOk(string message, address indexed sender);

enum AttestationSchemaType { PoU, PoL }

struct PortalInfo {
IPortal attestationPortalContract;
bytes32 schemaId;
AttestationSchemaType schemaType;
}
/// @custom:storage-location erc7201:polygonid.storage.VeraxZKPVerifier
struct VeraxZKPVerifierStorage {
mapping (uint64 requestId => PortalInfo portalInfo) portalInfoForReq;
}

// keccak256(abi.encode(uint256(keccak256("polygonid.storage.VeraxZKPVerifier")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant VeraxZKPVerifierStorageLocation =
0xf2a0fb5adce57cdd20ffa282dfdeffa5cf790754d88eeeedb507a130ec7f2900;

/**
* @dev Version of contract
*/
string public constant VERSION = "1.0.3";

function _getVeraxZKPVerifierStorage() private pure returns (VeraxZKPVerifierStorage storage $) {
assembly {
$.slot := VeraxZKPVerifierStorageLocation
}
}

function initialize() public initializer {
__Ownable_init(_msgSender());
}

function setPortalInfo(uint64 requestId, address portalAddress, bytes32 schemaId, AttestationSchemaType schemaType) public onlyOwner {
VeraxZKPVerifierStorage storage $ = _getVeraxZKPVerifierStorage();
$.portalInfoForReq[requestId] = PortalInfo(IPortal(portalAddress), schemaId, schemaType);
}

function _attest(uint64 requestId,
uint256[] calldata inputs,
uint256[2] calldata a,
uint256[2][2] calldata b,
uint256[2] calldata c) internal {
VeraxZKPVerifierStorage storage $ = _getVeraxZKPVerifierStorage();
PortalInfo memory portalInfo = $.portalInfoForReq[requestId];
if (portalInfo.attestationPortalContract == IPortal(address(0))) {
revert("Attestation portal not found for request");
}
bytes memory attestationPayload;

IZKPVerifier.ZKPRequest memory request = getZKPRequest(requestId);

uint64 attestationExpiration;
if (portalInfo.schemaType == AttestationSchemaType.PoL) {
attestationExpiration = 30 days * 6;
attestationPayload = abi.encode(requestId, inputs[request.validator.inputIndexOf('nullifier')]);
} else {
uint256 reputationLevel = inputs[request.validator.inputIndexOf('operatorOutput')];
if (reputationLevel >= 2) {
attestationExpiration = 30 days * 6;
} else {
attestationExpiration = 2 weeks;
}
attestationPayload = abi.encode(requestId, inputs[request.validator.inputIndexOf('nullifier')], reputationLevel);
}
AttestationPayload memory payload = AttestationPayload(
bytes32(portalInfo.schemaId),
uint64(inputs[request.validator.inputIndexOf('timestamp')]) + attestationExpiration, // expiration
abi.encode(msg.sender), // message sender
attestationPayload
);
bytes memory validationData = abi.encode(requestId, inputs, a, b, c);
bytes[] memory validationPayload = new bytes[](1);
validationPayload[0] = validationData;
portalInfo.attestationPortalContract.attest(payload, validationPayload) ;
emit AttestOk("attestation done", msg.sender);

}

/// @dev Submits a ZKP response and updates proof status
/// @param requestId The ID of the ZKP request
/// @param inputs The input data for the proof
/// @param a The first component of the proof
/// @param b The second component of the proof
/// @param c The third component of the proof
function submitZKPResponse(
uint64 requestId,
uint256[] calldata inputs,
uint256[2] calldata a,
uint256[2][2] calldata b,
uint256[2] calldata c
) public virtual override {
_attest(requestId, inputs, a, b ,c);
}

}
53 changes: 53 additions & 0 deletions contracts/examples/verax/ZKPVerifyModulePoL.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import { AttestationPayload } from "./types/Structs.sol";
import { AbstractModule } from "./abstracts/AbstractModule.sol";
import { IZKPVerifier } from '@iden3/contracts/interfaces/IZKPVerifier.sol';
import { ICircuitValidator } from '@iden3/contracts/interfaces/ICircuitValidator.sol';

contract ZKPVerifyModulePoL is AbstractModule {
IZKPVerifier public zkpVerifier;

mapping (uint256 nullifierSessionID => bool) isNullifierAttested;

constructor(address _zkpVerifier) {
zkpVerifier = IZKPVerifier(_zkpVerifier);
}

function _verifyAttestationPayload(AttestationPayload memory attestationPayload, uint256[] memory inputs, ICircuitValidator validator) internal view {
(uint64 attestationRequestId, uint256 attestationNullifierSessionID) =
abi.decode(attestationPayload.attestationData, (uint64, uint256));

require(attestationRequestId == inputs[validator.inputIndexOf('requestID')], "request Id doesn't match");
require(attestationNullifierSessionID == inputs[validator.inputIndexOf('nullifier')], "nullifier doesn't match");
}

function run(
AttestationPayload memory attestationPayload,
bytes memory validationPayload,
address txSender,
uint256 /*value*/
) public override {
(uint64 requestId, uint256[] memory inputs, uint256[2] memory a, uint256[2][2] memory b, uint256[2] memory c) =
abi.decode(validationPayload, (uint64, uint256[], uint256[2], uint256[2][2], uint256[2]));

IZKPVerifier.ZKPRequest memory request = zkpVerifier.getZKPRequest(requestId);
ICircuitValidator validator = request.validator;
validator.verify(
inputs,
a,
b,
c,
request.data,
txSender);

uint256 nullifierSessionId = inputs[validator.inputIndexOf('nullifier')];
require(!isNullifierAttested[nullifierSessionId], "attestation for nullifier already provided");

_verifyAttestationPayload(attestationPayload, inputs, validator);

isNullifierAttested[nullifierSessionId] = true;
}

}
64 changes: 64 additions & 0 deletions contracts/examples/verax/ZKPVerifyModulePoU.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import { AttestationPayload } from "./types/Structs.sol";
import { AbstractModule } from "./abstracts/AbstractModule.sol";
import { IZKPVerifier } from '@iden3/contracts/interfaces/IZKPVerifier.sol';
import { ICircuitValidator } from '@iden3/contracts/interfaces/ICircuitValidator.sol';

contract ZKPVerifyModulePoU is AbstractModule {
IZKPVerifier public zkpVerifier;
struct PoUData {
address sender;
uint256 reputationLevel;
}

mapping (uint256 nullifierSessionID => PoUData data) nullifierAttestedData;

constructor(address _zkpVerifier) {
zkpVerifier = IZKPVerifier(_zkpVerifier);
}

function _verifyAttestationPayload(AttestationPayload memory attestationPayload, uint256[] memory inputs, ICircuitValidator validator) internal view {
(uint64 attestationRequestId, uint256 attestationNullifierSessionID, uint256 reputationLevel) =
abi.decode(attestationPayload.attestationData, (uint64, uint256, uint256));

require(attestationRequestId == inputs[validator.inputIndexOf('requestID')], "request Id doesn't match");
require(attestationNullifierSessionID == inputs[validator.inputIndexOf('nullifier')], "nullifier doesn't match");
}

function run(
AttestationPayload memory attestationPayload,
bytes memory validationPayload,
address txSender,
uint256 /*value*/
) public override {
(uint64 requestId, uint256[] memory inputs, uint256[2] memory a, uint256[2][2] memory b, uint256[2] memory c) =
abi.decode(validationPayload, (uint64, uint256[], uint256[2], uint256[2][2], uint256[2]));

IZKPVerifier.ZKPRequest memory request = zkpVerifier.getZKPRequest(requestId);

PoUData memory prevAttestationData = nullifierAttestedData[inputs[request.validator.inputIndexOf('nullifier')]];
if (prevAttestationData.sender != address(0)) {
if (prevAttestationData.sender != txSender) {
revert("sender of the previous attestation for this nullifier doesn't match");
}
if (prevAttestationData.reputationLevel >= inputs[request.validator.inputIndexOf('operatorOutput')]) {
revert("reputation level not increased");
}
}

request.validator.verify(
inputs,
a,
b,
c,
request.data,
txSender);

_verifyAttestationPayload(attestationPayload, inputs, request.validator);

nullifierAttestedData[inputs[request.validator.inputIndexOf('nullifier')]] = PoUData(txSender, inputs[request.validator.inputIndexOf('operatorOutput')]);
}

}
39 changes: 39 additions & 0 deletions contracts/examples/verax/abstracts/AbstractModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
// copied from https://github.com/Consensys/linea-attestation-registry/blob/dev/contracts/src/abstracts/AbstractModule.sol
pragma solidity 0.8.20;

import { AttestationPayload } from "../types/Structs.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
* @title Abstract Module
* @author Consensys
* @notice Defines the minimal Module interface
*/
abstract contract AbstractModule is IERC165 {
/// @notice Error thrown when someone else than the portal's owner is trying to revoke
error OnlyPortalOwner();

/**
* @notice Executes the module's custom logic.
* @param attestationPayload The incoming attestation data.
* @param validationPayload Additional data required for verification.
* @param txSender The transaction sender's address.
* @param value The transaction value.
*/
function run(
AttestationPayload memory attestationPayload,
bytes memory validationPayload,
address txSender,
uint256 value
) public virtual;

/**
* @notice Checks if the contract implements the Module interface.
* @param interfaceID The ID of the interface to check.
* @return A boolean indicating interface support.
*/
function supportsInterface(bytes4 interfaceID) public pure virtual override returns (bool) {
return interfaceID == type(AbstractModule).interfaceId || interfaceID == type(IERC165).interfaceId;
}
}
48 changes: 48 additions & 0 deletions contracts/examples/verax/types/Structs.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT
// copied from https://github.com/Consensys/linea-attestation-registry/blob/dev/contracts/src/types/Structs.sol
pragma solidity 0.8.20;

struct AttestationPayload {
bytes32 schemaId; // The identifier of the schema this attestation adheres to.
uint64 expirationDate; // The expiration date of the attestation.
bytes subject; // The ID of the attestee, EVM address, DID, URL etc.
bytes attestationData; // The attestation data.
}

struct Attestation {
bytes32 attestationId; // The unique identifier of the attestation.
bytes32 schemaId; // The identifier of the schema this attestation adheres to.
bytes32 replacedBy; // Whether the attestation was replaced by a new one.
address attester; // The address issuing the attestation to the subject.
address portal; // The id of the portal that created the attestation.
uint64 attestedDate; // The date the attestation is issued.
uint64 expirationDate; // The expiration date of the attestation.
uint64 revocationDate; // The date when the attestation was revoked.
uint16 version; // Version of the registry when the attestation was created.
bool revoked; // Whether the attestation is revoked or not.
bytes subject; // The ID of the attestee, EVM address, DID, URL etc.
bytes attestationData; // The attestation data.
}

struct Schema {
string name; // The name of the schema.
string description; // A description of the schema.
string context; // The context of the schema.
string schema; // The schema definition.
}

struct Portal {
address id; // The unique identifier of the portal.
address ownerAddress; // The address of the owner of this portal.
address[] modules; // Addresses of modules implemented by the portal.
bool isRevocable; // Whether attestations issued can be revoked.
string name; // The name of the portal.
string description; // A description of the portal.
string ownerName; // The name of the owner of this portal.
}

struct Module {
address moduleAddress; // The address of the module.
string name; // The name of the module.
string description; // A description of the module.
}
Loading