mithril_stm/circuits/halo2/types.rs
1//! Halo2-facing type aliases and witness shapes for the STM SNARK circuit.
2//!
3//! This module bridges STM domain concepts (message, lottery index, Merkle proof)
4//! to circuit-oriented types consumed by the Halo2 relation and gadgets.
5
6use crate::signature_scheme::SchnorrVerificationKey;
7use ff::Field;
8
9pub use midnight_curves::{Bls12, Fq as JubjubBase, Fr as JubjubScalar, JubjubExtended as Jubjub};
10
11/// Lottery threshold value used by the circuit for signer eligibility checks.
12pub type Target = JubjubBase;
13/// Signed message value used by the circuit transcript, without any domain prefix.
14pub type SignedMessageWithoutPrefix = JubjubBase;
15/// Merkle root public input committed by the STM membership commitment tree.
16pub type MerkleRoot = JubjubBase;
17/// Lottery index (`i`) used for per-lottery checks in witness entries.
18pub type LotteryIndex = u32;
19
20/// Merkle-tree leaf material used by Halo2 witness construction.
21///
22/// The first field stores the signer's verification key, and the second
23/// field stores the lottery target value associated with that signer.
24#[derive(Debug, Copy, Clone, PartialEq, Eq)]
25pub struct MTLeaf(pub SchnorrVerificationKey, pub Target);
26
27/// Position of a sibling node relative to the current hash in a Merkle path.
28#[derive(Clone, Copy, Debug)]
29pub enum Position {
30 Left,
31 Right,
32}
33
34impl From<Position> for JubjubBase {
35 fn from(value: Position) -> Self {
36 match value {
37 Position::Left => JubjubBase::ZERO,
38 Position::Right => JubjubBase::ONE,
39 }
40 }
41}
42
43/// Merkle authentication path used by the Halo2 circuit witness.
44///
45/// Each entry stores sibling position and sibling hash value for one tree level.
46#[derive(Clone, Debug)]
47pub struct MerklePath {
48 /// Ordered list of `(position, sibling_hash)` from leaf level to root level.
49 pub siblings: Vec<(Position, JubjubBase)>,
50}
51
52impl MerklePath {
53 /// Creates a new Merkle path from ordered sibling entries.
54 pub fn new(siblings: Vec<(Position, JubjubBase)>) -> Self {
55 Self { siblings }
56 }
57}