Skip to content

Commit 83f0b1b

Browse files
authored
Merge pull request #58 from lambdaclass/improve_mina_docs
Improve Mina verifier documentation
2 parents 8755559 + 10fe27c commit 83f0b1b

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

operator/mina/lib/src/consensus_state.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ const GRACE_PERIOD_END: u32 = 1440;
1313
const SUB_WINDOWS_PER_WINDOW: u32 = 11;
1414
const SLOTS_PER_SUB_WINDOW: u32 = 7;
1515

16+
/// The result of the comparison of security between chains done in the `select_secure_chain`
17+
/// function.
1618
#[derive(Debug, PartialEq)]
1719
pub enum ChainResult {
1820
Bridge,
1921
Candidate,
2022
}
2123

24+
/// Given two Mina chains, `candidate` and `tip`, returns an enum variant `ChainResult` that
25+
/// indicates which chain is more secure.
26+
/// Returns `ChainResult::Bridge` if `tip` is the most secure chain. `ChainResult::Candidate`
27+
/// otherwise.
2228
pub fn select_secure_chain(
2329
candidate: &MinaProtocolState,
2430
tip: &MinaProtocolState,

operator/mina/lib/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ fn inner_verify_mina_state_ffi(
7575
verify_mina_state(proof_bytes, pub_input_bytes)
7676
}
7777

78+
/// Verifies that the Mina state included in `proof_bytes` is valid.
79+
/// This includes checking that:
80+
///
81+
/// - The Mina state corresponds to the tip of the most secure chain
82+
/// - The corresponding Pickles proof is valid
7883
pub fn verify_mina_state(proof_bytes: &[u8], pub_input_bytes: &[u8]) -> bool {
7984
let proof: MinaStateProof = match bincode::deserialize(proof_bytes) {
8085
Ok(proof) => proof,

operator/mina_account/lib/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ fn inner_verify_account_inclusion_ffi(
5050
verify_account_inclusion(proof_bytes, pub_input_bytes)
5151
}
5252

53+
/// Verifies a Mina account inclusion.
54+
/// Verifies that exists a Merkle path composed of:
55+
///
56+
/// - The hash of the Mina account as the leaf
57+
/// - The ledger hash as the root
58+
/// - Some intermediate nodes
59+
///
60+
/// Returns `true` if the Mina account is included in the ledger hash. `false` otherwise.
5361
pub fn verify_account_inclusion(proof_bytes: &[u8], pub_input_bytes: &[u8]) -> bool {
5462
let MinaAccountProof {
5563
merkle_path,

operator/mina_account/lib/src/merkle_verifier.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ use mina_curves::pasta::Fp;
44
use mina_p2p_messages::v2::hash_with_kimchi;
55
use std::fmt::Write;
66

7+
/// Verifies a Merkle Proof.
8+
/// This means that `merkle_leaf`, `merkle_path` and `merkle_root` conform one of the paths of a Merkle tree
9+
/// where `merkle_leaf` is the first node of the path, `merkle_root` is the last one and `merkle_path` is a
10+
/// vector of all the intermediate nodes.
11+
/// Returns `true` if the Merkle proof is valid. `false` otherwise.
12+
///
713
/// Based on OpenMina's implementation
814
/// https://github.com/openmina/openmina/blob/d790af59a8bd815893f7773f659351b79ed87648/ledger/src/account/account.rs#L1444
915
pub fn verify_merkle_proof(merkle_leaf: Fp, merkle_path: Vec<MerkleNode>, merkle_root: Fp) -> bool {

0 commit comments

Comments
 (0)