Skip to main content
Version: v1.2

Subsidy

This contract is used to verify that the subsidy calculations are correct. It is also used to update the subsidy commitment if the proof is valid.

rbi​

uint256 rbi

cbi​

uint256 cbi

sbCommitment​

uint256 sbCommitment

subsidyCommitment​

uint256 subsidyCommitment

verifier​

contract IVerifier verifier

vkRegistry​

contract IVkRegistry vkRegistry

poll​

contract IPoll poll

mp​

contract IMessageProcessor mp

ProcessingNotComplete​

error ProcessingNotComplete()

InvalidSubsidyProof​

error InvalidSubsidyProof()

AllSubsidyCalculated​

error AllSubsidyCalculated()

VkNotSet​

error VkNotSet()

NumSignUpsTooLarge​

error NumSignUpsTooLarge()

RbiTooLarge​

error RbiTooLarge()

CbiTooLarge​

error CbiTooLarge()

constructor​

constructor(address _verifier, address _vkRegistry, address _poll, address _mp) public payable

Create a new Subsidy contract

Parameters​

NameTypeDescription
_verifieraddressThe Verifier contract
_vkRegistryaddressThe VkRegistry contract
_polladdressThe Poll contract
_mpaddressThe MessageProcessor contract

updateSbCommitment​

function updateSbCommitment() public

Update the currentSbCommitment if the proof is valid.

currentSbCommitment is the commitment to the state and ballot roots

genSubsidyPackedVals​

function genSubsidyPackedVals(uint256 _numSignUps) public view returns (uint256 result)

Generate the packed values for the subsidy proof

Parameters​

NameTypeDescription
_numSignUpsuint256The number of signups

Return Values​

NameTypeDescription
resultuint256The packed values

genSubsidyPublicInputHash​

function genSubsidyPublicInputHash(uint256 _numSignUps, uint256 _newSubsidyCommitment) public view returns (uint256 inputHash)

Generate the public input hash for the subsidy proof

Parameters​

NameTypeDescription
_numSignUpsuint256The number of signups
_newSubsidyCommitmentuint256The new subsidy commitment

Return Values​

NameTypeDescription
inputHashuint256The public input hash

updateSubsidy​

function updateSubsidy(uint256 _newSubsidyCommitment, uint256[8] _proof) external

Update the subsidy commitment if the proof is valid

Parameters​

NameTypeDescription
_newSubsidyCommitmentuint256The new subsidy commitment
_proofuint256[8]The proof

increaseSubsidyIndex​

function increaseSubsidyIndex(uint256 batchSize, uint256 numLeaves) internal

Increase the subsidy batch index (rbi, cbi) to next, it will try to cbi++ if the whole batch can fit into numLeaves otherwise it will increase row index: rbi++. Each batch for subsidy calculation is 2 dimensional: batchSize*batchSize

Parameters​

NameTypeDescription
batchSizeuint256the size of 1 dimensional batch over the signup users
numLeavesuint256total number of leaves in stateTree, i.e. number of signup users

verifySubsidyProof​

function verifySubsidyProof(uint256[8] _proof, uint256 _numSignUps, uint256 _newSubsidyCommitment) public view returns (bool isValid)

Verify the subsidy proof using the Groth16 on chain verifier

Parameters​

NameTypeDescription
_proofuint256[8]The proof
_numSignUpsuint256The number of signups
_newSubsidyCommitmentuint256The new subsidy commitment

Return Values​

NameTypeDescription
isValidboolTrue if the proof is valid