Skip to content
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

Drand voting dapp #216

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/contracts/voting/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "voting"
version = "0.1.0"
edition = "2024_07"

[dependencies]
garaga = { path = "../.." }
starknet = "2.8.2"

[cairo]
sierra-replace-ids = false

[[target.starknet-contract]]
casm = true
casm-add-pythonic-hints = true
60 changes: 60 additions & 0 deletions src/contracts/voting/src/drand_verifier.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use super::drand_verifier_constants::{G2_GEN, precomputed_lines};

#[starknet::interface]
trait IDrandQuicknet<TContractState> {
fn verify_round_and_get_randomness(
ref self: TContractState, full_proof_with_hints: Span<felt252>,
) -> Option<felt252>;
}

#[starknet::contract]
mod DrandQuicknet {
// use starknet::SyscallResultTrait;
use garaga::definitions::{G1Point, G1G2Pair};
use garaga::pairing_check::{multi_pairing_check_bls12_381_2P_2F, MPCheckHintBLS12_381};
// use garaga::ec_ops::{G1PointTrait, G2PointTrait};
use garaga::utils::drand::{
round_to_curve_bls12_381, DRAND_QUICKNET_PUBLIC_KEY, HashToCurveHint
};
use super::{precomputed_lines, G2_GEN};
use garaga::utils::hashing::hash_G1Point;

// const ECIP_OPS_CLASS_HASH: felt252 =
// 0x7918f484291eb154e13d0e43ba6403e62dc1f5fbb3a191d868e2e37359f8713;
// use starknet::ContractAddress;

#[storage]
struct Storage {}

#[derive(Drop, Serde)]
struct DrandHint {
round_number: u64,
signature: G1Point,
hash_to_curve_hint: HashToCurveHint,
mpcheck_hint: MPCheckHintBLS12_381,
}
#[abi(embed_v0)]
impl IDrandQuicknet of super::IDrandQuicknet<ContractState> {
fn verify_round_and_get_randomness(
ref self: ContractState, mut full_proof_with_hints: Span<felt252>,
) -> Option<felt252> {
let drand_hint: DrandHint = Serde::deserialize(ref full_proof_with_hints).unwrap();
let message = round_to_curve_bls12_381(
drand_hint.round_number, drand_hint.hash_to_curve_hint
);

let check = multi_pairing_check_bls12_381_2P_2F(
pair0: G1G2Pair { p: drand_hint.signature, q: G2_GEN },
pair1: G1G2Pair { p: message, q: DRAND_QUICKNET_PUBLIC_KEY },
lines: precomputed_lines.span(),
hint: drand_hint.mpcheck_hint,
);

match check {
true => Option::Some(hash_G1Point(message)),
false => Option::None,
}
}
}
}

Loading
Loading