-
Notifications
You must be signed in to change notification settings - Fork 0
[Proof Of Concept] Zero-Collateral Lotteries #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The lottery is simulating the game logic in the following way: ImprovementHasn't integrated with the actual Ark wallet so
TODO:
|
|
Gameflow Demonstration: |
c14c6c1 to
8c620c5
Compare
| pub fn from_hash(hash: Vec<u8>) -> Self { | ||
| Self { hash, secret: None } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the impl From<Vec>``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a full zero-collateral lottery system with both a CLI client and a reusable Rust library.
- Introduces a
coinflip-clibinary that manages game lifecycle (create, join, bet, commit, reveal, status, list) and persists state locally. - Implements a new
arkive-lotterycrate withTwoPlayerGame,Player, and a hash‐based commit/reveal scheme. - Updates the workspace manifest to include the new crates and their dependencies.
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| coinflip-cli/src/main.rs | CLI entrypoint using clap and dispatching subcommands |
| coinflip-cli/src/commands/mod.rs | Command handlers, JSON-based game storage, and user prompts |
| coinflip-cli/Cargo.toml | Defines the coinflip-cli package and its dependencies |
| arkive-lottery/src/lib.rs | Public re-exports and helper functions for the lottery crate |
| arkive-lottery/src/game.rs | Core TwoPlayerGame logic for player management, betting, and payouts |
| arkive-lottery/src/player.rs | Player struct with commitment and betting methods |
| arkive-lottery/src/commitment/scheme.rs | Commitment trait implementation and struct |
| arkive-lottery/src/commitment/mod.rs | HashCommitment implementation and helper functions |
| arkive-lottery/src/error.rs | LotteryError definitions |
| arkive-lottery/Cargo.toml | Defines the arkive-lottery package and its dependencies |
| Cargo.toml | Adds coinflip-cli and arkive-lottery to the workspace |
Comments suppressed due to low confidence (4)
coinflip-cli/src/commands/mod.rs:548
- [nitpick] The
????in the error message is unclear. Simplify to something likePayout failed: {}to make it more professional and user-friendly.
println!("Payout failed ????: {}", e);
arkive-lottery/src/game.rs:29
- [nitpick] There are no unit tests for
TwoPlayerGameflows (bet placement, commitment, reveal, payout). Adding tests will help ensure protocol correctness and guard against regressions.
pub struct TwoPlayerGame {
coinflip-cli/src/commands/mod.rs:587
chrono::DateTimedoes not have afrom_timestampconstructor. UseUtc.timestamp(deadline, 0)orNaiveDateTime::from_timestampfollowed byDateTime::from_utcinstead.
let dt = chrono::DateTime::from_timestamp(deadline, 0).unwrap();
arkive-lottery/src/commitment/scheme.rs:27
- Calling
RngCore::fill_bytesonrand::thread_rng()won’t compile. Instead, dolet mut rng = rand::thread_rng(); rng.fill_bytes(&mut nonce);
rand::RngCore::fill_bytes(&mut rand::thread_rng(), &mut nonce);
| @@ -0,0 +1,698 @@ | |||
| #![allow(unused_variables)] | |||
Copilot
AI
Jun 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This allow attribute silences all unused-variable warnings; consider removing it and addressing any unused bindings explicitly to keep the code clean.
| #![allow(unused_variables)] |
| let game_data = GameData { | ||
| id: game_id.to_string(), | ||
| bet_amount: amount, | ||
| state: format!("{:?}", info.state), |
Copilot
AI
Jun 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing the game state as a formatted string and later matching on that string is brittle. Consider serializing the GameState enum directly or storing it as an enum in the JSON for type safety.
| state: format!("{:?}", info.state), | |
| state: info.state, |
| } | ||
|
|
||
| let pot_address = pot_wallet.get_ark_address().await?; | ||
| println!("DEBUG: Pot address: '{}'", pot_address.address); |
Copilot
AI
Jun 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Raw debug prints can clutter user output; consider using a logging framework (e.g., log::debug!) or removing these debug statements in production.
vincenzopalazzo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass, rust code looks really good!
I need to validate code logic but for now the structure is fine.
Are you planning to have integration testing that allow to test the code in the CI? probably if you have the core package you can do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not create a new cli, use the arkive-cli
I'm thinking to add jonhoo's rust-ci-config and have opened an issue for it too (#5 ). But I was thinking to first fix ark round participation logic before doing that. for other issues I've not done |
Signed-off-by: Dikshant <dikshant.073@gmail.com>
Signed-off-by: Dikshant <dikshant.073@gmail.com>
8c620c5 to
06d90cf
Compare
|
This PR is not to be merged. It's a proof of work for #18 |
Overview
This PR implements a Zero-Collateral Lottery system (2-player lottery only):
Why?
Traditional online gambling suffers from:
This implementation eliminates these issues through:
The zero-collateral lottery paper by Miller et al. demonstrated the theoretical possibility of fair lotteries without security deposits. However, the paper focused on cryptographic protocols without addressing practical value transfer mechanisms. This implementation bridges that gap by:
refer: https://arxiv.org/pdf/1612.05390
Features
Bet Collection & Escrow
Pot Management
Game State Management