Vote By Signature

Vote through an offline signature for cold wallets.

The castVoteBySig function allows an offline signer to participate in Onyx governance voting by submitting a digitally signed vote. Unlike the castVote function, which requires the voter to be online and execute the transaction, this function enables voting via an EIP-712-compliant signature, making it useful for delegated and gasless voting.

Function Implementation in CHNGovernance

The castVoteBySig() function ensures that votes can be cast securely and efficiently using off-chain signatures, reducing the need for direct blockchain interaction while maintaining the integrity of the voting process.

Function Signature

function castVoteBySig(
    uint proposalId,
    bool support,
    uint8 v,
    bytes32 r,
    bytes32 s
) public

Parameters

  • proposalId: The unique identifier of the governance proposal on which the vote is being cast.

  • support: A boolean value indicating the vote choice:

    • true → Vote in favor of the proposal (Yes)

    • false → Vote against the proposal (No)

  • v: The recovery byte of the signature, used for ECDSA signature verification.

  • r: First half of the ECDSA signature pair.

  • s: Second half of the ECDSA signature pair.

  • RETURN:The function does not return a value. If the proposal ID is invalid or the signature is not valid, the transaction reverts with an error.

Example Solidity Implementation

To cast a vote using Solidity, the castVoteBySig() function can be called from an instance of the CHNGovernance contract:

CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.castVoteBySig(proposalId, true, v, r, s); // Voting in favor using an offline signature

Web3.js Implementation (v1.2.6)

For interacting with the CHNGovernance contract using Web3.js, the following example demonstrates how to cast a vote by signature:

const tx = await gov.methods.castVoteBySig(proposalId, false, v, r, s).send({}); // Voting against using an offline signature

Technical Considerations

  • The castVoteBySig() function is state-modifying and will incur gas costs.

  • Votes are weighted based on the voting power at the moment the proposal became Active.

  • EIP-712-compliant signatures ensure the security and authenticity of the vote.

  • If the signature is invalid or does not match the voter's address, the transaction reverts with an error.

  • This function allows users to sign a vote offline and have another address submit the vote on-chain, enabling gasless voting if subsidized by a third party.

  • Governance interfaces and voting dashboards should support offline signing workflows to increase accessibility and voter participation.

Last updated