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
  • Generate a reputation proof
  • Spend reputation
  • Verify the proof
  • Verify UniRep state

Was this helpful?

Edit on GitHub
  1. Getting Started
  2. Start with Typescript 📠

8. Reputation proof

Previous7. User state transitionNextComputation happens off-chain â„šī¸

Last updated 2 years ago

Was this helpful?

Generate a reputation proof

See to know how to generate a current user state.

Specify what will be included in the reputation proof:

  1. Prove the minimum posRep-negRep that an attester gives: minRep

  2. Prove the : nonceList

  3. Prove the graffiti pre-image: graffitiPreImage

User should also specify the attesterId and epochKeyNonce to generate an output epoch key.

const attesterID = await contract.attesters(attester.address)
const epkNonce = 0
const rep = userState.getRepByAttester(BigInt(attesterId))
const minRep = Number(rep.posRep) - Number(rep.negRep)
const proveGraffiti = 0 // 0 then it will not prove the pre-image
const nonceList = 0 // 0 or [-1,..,-1] with length 'maxReputationBudget' means the proof will not generate reputation nullifiers.

const proof = await userState.genProveReputationProof(
    attesterId,
    epkNonce,
    minRep,
    proveGraffiti,
    graffitiPreImage,
    nonceList
)

Spend reputation

Call the spendReputation in UniRep smart contract

const tx = await contract.spendReputation(
    proof.publicSignals,
    proof.proof,
    {
        value: attestingFee,
    }
)

Get the proof index

const fromIndex = await contract.getProofIndex(
    proof.hash()
)
const tx = await unirepContract
    .connect(attester)
    .submitAttestation(
        attestation, 
        epochKey, 
        index, 
        fromIndex, 
        {
            value: attestingFee,
        }
    )

Verify the proof

with UniRep smart contract:

const isValid = await contract.verifyReputation(
    proof.publicSignals,
    proof.proof
)

with a prover:

const isValid = await proof.verify()

Verify UniRep state

Check global state tree root exits.

const isGSTRootExisted = await unirepState.GSTRootExists(
    proof.globalStateTree,
    proof.epoch
)
console.log(isGSTRootExisted) // false then the proof will be invalid

Verify reputation nullifiers.

const repNullifiers = proof.repNullifiers.map((i) => i.toString())
for (const nullifier of repNullifiers) {
    if (await unirepState.nullifierExist(nullifier)) {
        return false // then the proof will be invalid
    }
}

Use the reputation proof to attest others. To construct another attestation, epochKey, and index, see

🎮
5. Attest
reputation nullifiers
4. Epoch key proof