-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds voting folder and copy of drand_quicknet contents
- Loading branch information
Showing
4 changed files
with
3,648 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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
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, | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.