From fde84a68e735e939c574d701cfbb194beb40b42a Mon Sep 17 00:00:00 2001 From: MauroFab Date: Wed, 9 Sep 2026 16:08:53 -0300 Subject: [PATCH] refactor(stark): the grinding factor is not "security_bits" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three local bindings read `proof_options.grinding_factor` and named it `security_bits`, then passed it to functions whose own parameter is `grinding_factor`: prover.rs:2286 let security_bits = air.context().proof_options.grinding_factor; verifier.rs:1582 let security_bits = air.context().proof_options.grinding_factor; verifier.rs:1665 let security_bits = air.context().proof_options.grinding_factor; Grinding is not the security level. It is one term in the query round's error, and it cannot move the commit-phase term at all — so a reader who takes these bindings at their word concludes the proof carries 20 bits of security, or that raising the grinding factor raises security generally. Neither follows. `grinding_factor` is what every function behind these call sites already calls the argument (`grinding::is_valid_nonce`, `generate_nonce`, `generate_nonce_maybe_gpu`), so the rename removes a mismatch rather than introducing a new convention. Nothing is shadowed: the name appeared in these two files only as the struct field being read. Eight identifier occurrences, no behaviour, no field moved. The one operator- facing message in the area already says the right thing — `error!("Grinding factor not satisfied")` — so no text needed correcting alongside the names. --- crypto/stark/src/prover.rs | 6 +++--- crypto/stark/src/verifier.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crypto/stark/src/prover.rs b/crypto/stark/src/prover.rs index 5078ce290..faf512a72 100644 --- a/crypto/stark/src/prover.rs +++ b/crypto/stark/src/prover.rs @@ -2283,11 +2283,11 @@ pub trait IsStarkProver< // grinding: generate nonce and append it to the transcript #[cfg(feature = "instruments")] let t_sub = Instant::now(); - let security_bits = air.context().proof_options.grinding_factor; + let grinding_factor = air.context().proof_options.grinding_factor; let mut nonce = None; - if security_bits > 0 { + if grinding_factor > 0 { let nonce_value = - grinding::generate_nonce_maybe_gpu(&transcript.state(), security_bits) + grinding::generate_nonce_maybe_gpu(&transcript.state(), grinding_factor) .expect("nonce not found"); transcript.append_bytes(&nonce_value.to_be_bytes()); nonce = Some(nonce_value); diff --git a/crypto/stark/src/verifier.rs b/crypto/stark/src/verifier.rs index ca6f15152..44add9c21 100644 --- a/crypto/stark/src/verifier.rs +++ b/crypto/stark/src/verifier.rs @@ -1579,9 +1579,9 @@ pub trait IsStarkVerifier< } // Receive grinding value - let security_bits = air.context().proof_options.grinding_factor; + let grinding_factor = air.context().proof_options.grinding_factor; let mut grinding_seed = [0u8; 32]; - if security_bits > 0 + if grinding_factor > 0 && let Some(nonce_value) = proof.nonce() { grinding_seed = transcript.state(); @@ -1662,10 +1662,10 @@ pub trait IsStarkVerifier< ); // verify grinding - let security_bits = air.context().proof_options.grinding_factor; - if security_bits > 0 { + let grinding_factor = air.context().proof_options.grinding_factor; + if grinding_factor > 0 { let nonce_is_valid = proof.nonce().is_some_and(|nonce_value| { - grinding::is_valid_nonce(&challenges.grinding_seed, nonce_value, security_bits) + grinding::is_valid_nonce(&challenges.grinding_seed, nonce_value, grinding_factor) }); if !nonce_is_valid {