Skip to content

[ACADEMY] Sharded Voting Example#664

Merged
gitshreevatsa merged 4 commits intoNilFoundation:mainfrom
JoE11-y:feature-sharded-voting-example
Apr 2, 2025
Merged

[ACADEMY] Sharded Voting Example#664
gitshreevatsa merged 4 commits intoNilFoundation:mainfrom
JoE11-y:feature-sharded-voting-example

Conversation

@JoE11-y
Copy link
Copy Markdown
Contributor

@JoE11-y JoE11-y commented Mar 26, 2025

Closes #607

📦 Description

This PR introduces the smart contract implementation for a Sharded Voting Protocol built on the =nil; blockchain. The system is designed to efficiently handle large-scale voting by distributing vote storage and logic across multiple shards.

🔧 Key Components

  • VoteManager.sol

    • Deploys VoteShard contracts deterministically using Nil.asyncDeploy
    • Supports voting directly or via the manager using voteFromManager
    • Handles asynchronous vote tallying from each shard using Nil.sendRequest
  • VoteShard.sol

    • Stores per-voter data, tracks votes by choice
    • Supports secure vote casting either directly or via the manager
    • Exposes a tallyVotes() function that returns vote totals for aggregation

✅ Completed

  • Sharded voting logic split across VoteManager and VoteShard
  • Asynchronous shard deployment and communication using Nil.sol
  • Vote validation (one vote per address)
  • Aggregation of vote results after the voting period
  • Implement runtime test script to:

@JoE11-y JoE11-y marked this pull request as ready for review March 26, 2025 21:35
@0xAleksaOpacic 0xAleksaOpacic added the ODHack12 Tag for issues which are suitable for ODHack week label Mar 27, 2025
Copy link
Copy Markdown
Contributor

@idea404 idea404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits

1. 📥 Clone the repository:

```sh
git clone https://github.com/NilFoundation/nil-voting-protocol.git
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git clone https://github.com/NilFoundation/nil-voting-protocol.git
git clone https://github.com/NilFoundation/nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

2. 📂 Navigate to the directory and install dependencies:

```sh
cd nil-voting-protocol
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cd nil-voting-protocol
cd academy/sharded-voting-protocol

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return { startTime, endTime };
}

task("e2e", "🔁 End-to-end test for sharded voting").setAction(async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
task("e2e", "🔁 End-to-end test for sharded voting").setAction(async () => {
task("run-voting-protocol", "🔁 End-to-end test for sharded voting").setAction(async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@JoE11-y JoE11-y requested a review from idea404 March 31, 2025 17:25
@JoE11-y
Copy link
Copy Markdown
Contributor Author

JoE11-y commented Mar 31, 2025

@idea404 Done with the edits

Copy link
Copy Markdown
Contributor

@gitshreevatsa gitshreevatsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening the PR. Things work fine! Just one small change as mentioned.

@@ -0,0 +1,25 @@
{
"name": "sharded-voting-protocol",
"description": "This is an example repository to showcase how a lending protocol can be built on top of =nil;",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to voting protocol currently it is lending protocol.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gezort Gezort force-pushed the feature-sharded-voting-example branch from 4d6d5c8 to bbf9ab5 Compare April 1, 2025 11:26
@Gezort Gezort force-pushed the feature-sharded-voting-example branch from bbf9ab5 to 107773e Compare April 1, 2025 11:29
@gitshreevatsa
Copy link
Copy Markdown
Contributor

@JoE11-y
Can you please take a look at the conflicts of the files mentioned(.gitignore, package.json and ./github/workflows/publish_npm.yaml). I see they are very minor one line changes. If they were made unintentionally, please revert those changes, if there are any significances, please explain the changes made to these 3 files.

@JoE11-y
Copy link
Copy Markdown
Contributor Author

JoE11-y commented Apr 1, 2025

@gitshreevatsa no i didn't make those changes.

Maybe it's due to the rebasing.

I'll clean it up now.

@JoE11-y
Copy link
Copy Markdown
Contributor Author

JoE11-y commented Apr 1, 2025

Ready to go now @gitshreevatsa

@JoE11-y
Copy link
Copy Markdown
Contributor Author

JoE11-y commented Apr 1, 2025

Or should i make the pr again, for a cleaner history?

@gitshreevatsa
Copy link
Copy Markdown
Contributor

It is alright, don't need to open another PR. For cleaner history you can try squashing commits instead.

@Gezort Gezort force-pushed the feature-sharded-voting-example branch from f1745a3 to 24a7538 Compare April 2, 2025 06:40
@gitshreevatsa
Copy link
Copy Markdown
Contributor

@JoE11-y Thanks a lot for your contribution! 🙌

@gitshreevatsa gitshreevatsa added this pull request to the merge queue Apr 2, 2025
Merged via the queue into NilFoundation:main with commit 06afb78 Apr 2, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ODHack12 Tag for issues which are suitable for ODHack week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[academy] Implement Parallel Cross-Shard Voting Tally Example

5 participants