Skip to content

Commit

Permalink
Adds voting folder and copy of drand_quicknet contents
Browse files Browse the repository at this point in the history
  • Loading branch information
raugfer committed Oct 1, 2024
1 parent d416591 commit 1b5d018
Show file tree
Hide file tree
Showing 4 changed files with 3,648 additions and 0 deletions.
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 = "drand_quicknet"
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

0 comments on commit 1b5d018

Please sign in to comment.