Freedom Tool: Smart contracts reference
ProposalsState
A facade for voting creation and management by creator. It is responsible for counting votes and adding voters to SMT by nullifier.
Deployments
Chain | ChainID | Address |
---|---|---|
Rarimo | 7368 | 0x9C4b84a940C9D3140a1F40859b3d4367DC8d099a |
Interface
/contracts/state/ProposalsState.sol
contract ProposalsState is OwnableUpgradeable, AccessControlUpgradeable, UUPSUpgradeable {
uint256 public lastProposalId;
uint256 public minFundingAmount;
struct ProposalConfig {
uint64 startTimestamp;
uint64 duration;
uint256 multichoice;
uint256[] acceptedOptions;
string description;
address[] votingWhitelist; // must be sorted
bytes[] votingWhitelistData; // data per voting whitelist
}
enum ProposalStatus {
None,
Waiting,
Started,
Ended,
DoNotShow
}
struct ProposalInfo {
address proposalSMT;
ProposalStatus status;
ProposalConfig config;
uint256[MAXIMUM_CHOICES_PER_OPTION][] votingResults;
}
function createProposal(
ProposalConfig calldata proposalConfig_
) external payable {
// ...
}
function addFundsToProposal(
uint256 proposalId_
) external payable {
// ...
}
function changeProposalDuration(
uint256 proposalId_,
uint64 newDuration_
) external onlyProposalCreator(proposalId_) {
// ...
}
function hideProposal(
uint256 proposalId_
) external onlyProposalCreator(proposalId_) {
// ...
}
function getProposalEventId(
uint256 proposalId_
) external view returns (uint256) {
// ...
}
function getProposalInfo(
uint256 proposalId_
) external view returns (ProposalInfo memory info_) {
// ...
}
}
createProposal()
— creates a new voting with initial amount (more thanminFundingAmount
) to cover fees per each user;addFundsToProposal()
— allows to top up a voting to cover more voting transactions;changeProposalDuration()
— allows voting prolongation. Only callable by the proposal creator;hideProposal()
— allows to hide proposal (switch status toDoNotShow
). There is no way to make it visible again;getProposalEventId()
— returns unique number which is used to calculate nullifier;getProposalInfo()
— allows voting prolongation. Only callable by the proposal creator;
See ProposalsState.sol for the full implementation.
BioPassportVoting
Responsible for the Biometric Passport query proof verification and pub signal validation.
Deployments
Chain | ChainID | Address |
---|---|---|
Rarimo | 7368 | 0x8Dea8065888A14F66ba9Fb944353d898663863cf |
Interface
/contracts/voting/BioPassportVoting.sol
contract BioPassportVoting is BaseVoting {
function vote(
bytes32 registrationRoot_,
uint256 currentDate_,
uint256 proposalId_,
uint256[] memory vote_,
UserData memory userData_,
VerifierHelper.ProofPoints memory zkPoints_
) external override {
// ...
}
}
vote()
— verifies query proof and callsvote()
function ofProposalState
smart contract;
See BioPassportVoting.sol for the full implementation.
Voting
Responsible for the National ID Card query proof verification and pub signal validation.
Interface
/contracts/voting/Voting.sol
contract Voting is BaseVoting {
function vote(
bytes32 registrationRoot_,
uint256 currentDate_,
uint256 proposalId_,
uint256[] memory vote_,
UserData memory userData_,
VerifierHelper.ProofPoints memory zkPoints_
) external override {
// ...
}
}
vote()
— verifies query proof and callsvote()
function ofProposalState
smart contract;
See Voting.sol for the full implementation.
BaseVoting
This abstract contract encapsulates common logic for both BioPassportVoting
and Voting
.
Interface
/contracts/voting/BaseVoting.sol
abstract contract BaseVoting is OwnableUpgradeable, UUPSUpgradeable {
uint256 public constant ZERO_DATE = 0x303030303030;
struct UserData {
uint256 nullifier;
uint256 citizenship;
uint256 identityCreationTimestamp;
}
struct ProposalRules {
uint256 selector;
uint256[] citizenshipWhitelist;
uint256 identityCreationTimestampUpperBound;
uint256 identityCounterUpperBound;
uint256 sex;
uint256 birthDateLowerbound;
uint256 birthDateUpperbound;
uint256 expirationDateLowerBound;
}
address public registrationSMT;
address public proposalsState;
address public votingVerifier;
}
registrationSMT
— address of Sparse Merkle Tree with registered identities;
See BaseVoting.sol for the full implementation.
RegistrationSMTReplicator
Use it instead of registrationSMT
unless your contracts on Rarimo.
Interface
/contracts/replication/RegistrationSMTReplicator.sol
contract RegistrationSMTReplicator is MultiOwnable, UUPSUpgradeable {
uint256 public constant ROOT_VALIDITY = 1 hours;
bytes32 public latestRoot;
uint256 public latestTimestamp;
function transitionRoot(
bytes32 newRoot_,
uint256 transitionTimestamp_,
bytes calldata proof_
) external virtual onlyOwner {
// ...
}
function isRootValid(bytes32 root_) external view virtual returns (bool) {
// ...
}
function isRootLatest(bytes32 root_) public view virtual returns (bool) {
// ...
}
}
See RegistrationSMTReplicator.sol for the full implementation.