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
  • Submit start transition proof
  • Submit process attestations proofs
  • Submit user state transition proof
  • Verify UniRep state

Was this helpful?

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

7. User state transition

Previous6. Epoch transitionNext8. Reputation proof

Last updated 2 years ago

Was this helpful?

See how to generate a user state: . Then use the user state to generate user state transition proofs.

const {
    startTransitionProof,
    processAttestationProofs,
    finalTransitionProof,
} = await userState.genUserStateTransitionProofs()

Submit start transition proof

const tx = await contract.startUserStateTransition(
    startTransitionProof.publicSignals,
    startTransitionProof.proof
)

Get the proof index of startTransitionProof

const proofIndexes: ethers.BigNumber[] = []
await tx.wait() // should wait until the transaction is confirmed
const proofHash = startTransitionProof.hash()
const proofIndex = await contract.getProofIndex(proofHash)
proofIndexes.push(proofIndex)

Submit process attestations proofs

Submit all process attestations proofs and get the proof indexes.

for (let i = 0; i < processAttestationProofs.length; i++) {
    const tx = await contract.processAttestations(
        processAttestationProofs[i].publicSignals,
        processAttestationProofs[i].proof
    )
    await tx.wait() // wait until the transaction is confirmed
    
    const proofHash = processAttestationProofs[i].hash()
    const proofIndex = await contract.getProofIndex(proofHash)
    proofIndexes.push(proofIndex)
}

Submit user state transition proof

const tx = await contract.updateUserStateRoot(
    finalTransitionProof.publicSignals,
    finalTransitionProof.proof,
    proofIndexes
)

Verify UniRep state

Check if global state tree root exists in the current UniRep state

const fromEpoch = Number(finalTransitionProof.transitionFromEpoch)
const GSTRoot = finalTransitionProof.fromGlobalStateTree.toString()
const isGSTRootExisted = await userState.GSTRootExists(
    GSTRoot, 
    fromEpoch
)
console.log(isGSTRootExisted) // false then the proof will be invalid 

Check if epoch tree root matches the epoch

const fromEpoch = Number(finalTransitionProof.transitionFromEpoch)
const epochTreeRoot = finalTransitionProof.fromEpochTree.toString()
const isEpochTreeExisted = await userState.epochTreeRootExists(
    epochTreeRoot, 
    fromEpoch
)
console.log(isEpochTreeExisted) // false then the proof will be invalid

Check epoch key nullifiers are not existed

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

It can be checked with either a Synchronizer object or a UserState object. See: .

🎮
4. Epoch key proof
4. Epoch Key Proof