Unirep
  • 👏Welcome
  • 🧩Introduction
  • 🎮Getting Started
    • Install & build 🛠
    • Start with cli commands 🔌
      • 0. Install and build
      • 1. Spin up the testing chain
      • 2. Deploy Unirep contract
      • 3. User generates semaphore identity
      • 4. User signs up
      • 5. Attester signs up
      • 6. User generates epoch key and epoch key proof
      • 7. Attesters/Users verify epoch key proof
      • 8. Submit epoch key proof to Unirep smart contract
      • 9. Attester attest to epoch key
      • 10. Epoch transition
      • 11. User state transition
      • 12. User generates reputation proof
      • 13. Attesters/ Users verify the reputation proof
      • 14. User generates sign up proof
      • 15. Attesters/ Users verify the sign up proof
    • Start with Typescript 📠
      • 0. Install packages
      • 1. deploy
      • 2. User signs up
      • 3. Attester signs up
      • 4. Epoch key proof
      • 5. Attest
      • 6. Epoch transition
      • 7. User state transition
      • 8. Reputation proof
    • Computation happens off-chain â„šī¸
  • â˜€ī¸Protocol
    • Glossary
      • Users and Attesters
      • Epoch
      • Epoch Key
      • Reputation
      • Trees
      • Nullifiers
      • Epoch Transition
      • User State Transition
    • Circuits
      • Epoch Key Proof
      • Reputation Proof
      • User Sign Up Proof
      • User State Transition Proof
    • Contract
      • Sign up
      • Attestations
      • Epoch transition
      • User state transition
      • Verify proofs
  • 🌈Package usage
    • @unirep/crypto
    • @unirep/circuits
    • @unirep/contracts
    • @unirep/core
    • @unirep/subgraph
    • cli
      • Deploy Unirep Contract
      • User Identity
      • User Sign Up
      • Epoch Key And Proof
      • Attestation
      • Epoch transition
      • User state transition
      • Reputation Proof
      • Airdrop Reputation
      • Spend Reputation
  • đŸŒģApplications
    • Unirep Social
Powered by GitBook
On this page
  • Set airdrop amount
  • Airdrop Epoch key
  • Submit Epoch Key Proof
  • Submit Attestation
  • Spend Reputation

Was this helpful?

Edit on GitHub
  1. Protocol
  2. Contract

Attestations

How airdrop, attestation, spending reputation happens in UniRep smart contract.

PreviousSign upNextEpoch transition

Last updated 2 years ago

Was this helpful?

Set airdrop amount

After signing up, attesters can set the airdrop amount that whoever signs up through the attester, the user can get airdropped positive reputation.

function setAirdropAmount(uint256 amount) external

source:

Airdrop Epoch key

An attester can submit the airdrop attestation to an epoch key with a . The msg.sender should match the attesterId in the publicSignals.

/**
* @dev An attester submit the airdrop attestation to an epoch key with a sign up proof
* publicSignals[0] = [ epoch ]
* publicSignals[1] = [ epochKey ]
* publicSignals[2] = [ globalStateTree ]
* publicSignals[3] = [ attesterId ]
* publicSignals[4] = [ userHasSignedUp ]
* @param publicSignals The public signals of the sign up proof
* @param proof The The proof of the sign up proof
 */
function airdropEpochKey(
    uint256[] memory publicSignals,
    uint256[8] memory proof
) external payable

Submit Epoch Key Proof

The epoch key proof should be submitted before to get attestation. Then others can verify if the attestation is given to a valid epoch key.

/**
* @dev A user should submit an epoch key proof and get a proof index
* publicSignals[0] = [ globalStateTree ]
* publicSignals[1] = [ epoch ]
* publicSignals[2] = [ epochKey ]
* @param publicSignals The public signals of the epoch key proof
* @param proof The The proof of the epoch key proof
*/
function submitEpochKeyProof(
    uint256[] memory publicSignals,
    uint256[8] memory proof
) external

Submit Attestation

function submitAttestation(
    Attestation calldata attestation,
    uint256 epochKey,
    uint256 toProofIndex,
    uint256 fromProofIndex
) external payable
function submitAttestationViaRelayer(
    address attester,
    bytes calldata signature,
    Attestation calldata attestation,
    uint256 epochKey,
    uint256 toProofIndex,
    uint256 fromProofIndex
) external payable

Spend Reputation

/**
* @dev A user spend reputation via an attester, the non-zero nullifiers will be processed as a negative attestation
* publicSignals[0: maxReputationBudget ] = [ reputationNullifiers ]
* publicSignals[maxReputationBudget    ] = [ epoch ]
* publicSignals[maxReputationBudget + 1] = [ epochKey ]
* publicSignals[maxReputationBudget + 2] = [ globalStateTree ]
* publicSignals[maxReputationBudget + 3] = [ attesterId ]
* publicSignals[maxReputationBudget + 4] = [ proveReputationAmount ]
* publicSignals[maxReputationBudget + 5] = [ minRep ]
* publicSignals[maxReputationBudget + 6] = [ proveGraffiti ]
* publicSignals[maxReputationBudget + 7] = [ graffitiPreImage ]
* @param publicSignals The public signals of the reputation proof
 * @param proof The The proof of the reputation proof
 */
function spendReputation(
    uint256[] memory publicSignals,
    uint256[8] memory proof
) external payable

The proof index can be queried by proof hash. And the proof hash can be computed by

Generate proof hash from ethers

import ethers from 'ethers'

const proofHash = ethers.utils.solidityKeccak256(
    ['uint256[]', 'uint256[8]'],
    [publicSignals, proof]
)

Generate proof hash from @unirep/contracts

import { ReputationProof } from '@unirep/contracts'

const proof = new ReputationProof(
    publicSignals,
    proof
)
const proofHash = proof.hash(()

Then call the UniRep smart contract to query the proof index

const unirepContract = new ethers.Contract(address, abi, provider)
const index = await unirepContract.getProofIndex(
    proofHash
)

source:

source:

An attester can submit the attestation with a proof index. A valid proof is either an , a or a with epoch key being one of the public signals. An attester can also submit attestations through a relayer or not.

It it is from a we should include a fromProofIndex to make sure the attestation is from a valid reputation proof, or the attestation will fail.

source:

source:

A user include a to spend reputation via an attester, the non-zero nullifiers will be processed as a negative attestation, and the spent reputation cannot be re-used.

source:

After the spendReputation event emitted, the reputation will assign a proofIndex. Then the proofIndex can be included in the fromProofIndex of .

â˜€ī¸
Unirep.sol/setAirdropAmount
sign up proof
Unirep.sol/airdropEpochKey
Unirep.sol/submitEpochKeyProof
epoch key proof
user sign up proof
reputation proof
reputation proof
Unirep.sol/submitAttestation
Unirep.sol/submitAttestationViaRelayer
reputation proof
Unirep.sol/spendReputation
submitAttestation