Quadratic voting example showcasing libraries#30
Open
mohammadfawaz wants to merge 1 commit intomainfrom
Open
Conversation
67ae9f8 to
2c8312f
Compare
f192ea7 to
d512558
Compare
d512558 to
8fd99ff
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
quadratic_voteis a governance example that demonstrates Leo library packages and library submodules.Two reusable libraries handle all the math:
sqrt_mathisqrt— integer square root via Newton's methodvote_mathsqrt_math)governance.aleoUnder Quadratic Voting (QV), a participant's vote weight equals ⌊√(token_balance)⌋ and casting k votes costs k² credits. This makes influence grow with the square root of wealth rather than linearly — fairer to smaller holders.
Noteworthy Features
sqrt_mathandvote_mathhave no.aleoprogram name, are never deployed on their own, and only take effect when included by a program package..leofile undersrc/becomes a named module; no declaration needed.vote_math::cost::build_profilecallsvote_math::weight::compute;sqrt_math::checks::is_perfect_squarecallssqrt_math::newton::isqrt.vote_math::weight::computereaches directly intosqrt_math::newton::isqrt, demonstrating the full dependency chain (governance → vote_math → sqrt_math).sqrt_math::ISQRT_MAX,vote_math::MAX_WEIGHT, andvote_math::MIN_BALANCEare defined inlib.leoand referenced by name from within submodules.vote_math::cost::VoterProfileis defined in a submodule and used as a variable type insidegovernance.aleo.Voterecord is private; the token balance that drove the weight computation is never revealed on-chain.Test plan
cd quadratic_vote/sqrt_math && leo buildcd quadratic_vote/vote_math && leo buildcd quadratic_vote/governance && leo buildcd quadratic_vote/governance && leo test→ 18/18 passcd quadratic_vote && bash run.sh→ all steps produce expected output