Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5a19d81
added proof_size function
Antonio95 Oct 7, 2025
5d27960
added function that returns the proof size given the Authorization
Antonio95 Oct 7, 2025
727b65f
created Authorization::number_of_input_records(); turned authorizatio…
Antonio95 Oct 7, 2025
68defa5
added consistency check between prepare_verifier_inputs and Authoriza…
Antonio95 Oct 7, 2025
99c00bd
switched execution tests to Varuna V2 and added proof-size checks to all
Antonio95 Oct 7, 2025
47acade
added 1 to the wrapper function to account for serialized version number
Antonio95 Oct 8, 2025
32f3ea1
Merge branch 'option_serialized_size_fix' into proof_size
Antonio95 Oct 8, 2025
3191b05
comment fixed and replaced magical 8 by size_of usize
Antonio95 Oct 8, 2025
532cd3d
Merge branch 'staging' into proof_size
Antonio95 Oct 8, 2025
6841b97
Update synthesizer/process/src/stack/authorization/mod.rs
Antonio95 Oct 8, 2025
49f0a3a
added reference to serialize_compressed in the documentation of proof…
Antonio95 Oct 8, 2025
1ee7a72
Update algorithms/src/snark/varuna/data_structures/proof.rs
vicsn Oct 14, 2025
d394f44
modified interface, added Authorisation::from_unchecked, added test c…
Antonio95 Oct 16, 2025
de62b52
restricted consensus version
Antonio95 Oct 16, 2025
edac4f1
addressed PR review comments; created proof_size for synthesizer Proof
Antonio95 Oct 16, 2025
5f966ad
merged staging
Antonio95 Oct 16, 2025
795df43
improved documentation of the two proof_size methods
Antonio95 Oct 16, 2025
1988927
changed original output type into the new semantic one
Antonio95 Oct 16, 2025
d63394f
Merge branch 'staging' into proof_size
Antonio95 Oct 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions algorithms/src/snark/varuna/data_structures/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,10 @@ pub fn proof_size<E: PairingEngine>(
VarunaVersion::V2 => {
// All fields are serialised in Compressed mode The breakdown is as
// follows:
// - batch sizes (boils down to CanonicalSerialize for [usize]):
// + one u64 for the length (the number of circuits) followed that many u64,
// which is how usizes are serialized. This contains the size information
// for the vectors in all other fields, which are therefore serialised
// without their length
// - batch sizes: one `usize` (which is serialised as a `u64`) for each batch
// size, plus one `u64` for the number of batches. This contains the size
// information for the vectors in all other fields, which are therefore
// serialised without their length prefix.
// - commitments:
// + witness_commitments: n_instances commitments
// + mask_poly: 1 byte to encode the enum tag (a bool) plus one commitment if
Expand Down
15 changes: 9 additions & 6 deletions synthesizer/process/src/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ use console::{
prelude::*,
program::{FinalizeType, Identifier, LiteralType, PlaintextType},
};
use snarkvm_algorithms::snark::varuna::{VarunaVersion, proof_size};
use snarkvm_algorithms::snark::varuna::VarunaVersion;
use snarkvm_ledger_block::{Deployment, Execution, Transaction};
use snarkvm_synthesizer_program::{CastType, Command, Instruction, Operand};
use snarkvm_synthesizer_snark::proof_size;

/// Returns the deployment cost in microcredits for a given deployment.
pub fn deployment_cost<N: Network>(
Expand Down Expand Up @@ -110,12 +111,14 @@ pub fn execution_cost_for_authorization<N: Network>(
}

// Varuna is always ran in hiding (i. e. ZK) mode when proving Executions.
// If future versions of Varuna are introduced, the correct version should
// be deduced from the consensus version. The extra 1 byte comes from the
// version number.
let expected_proof_size = u64::try_from(1 + proof_size::<N::PairingCurve>(&batch_sizes, VarunaVersion::V2, true)?)?;
let hiding_mode = true;

// We cannot directly add the proof size to the storage cost due to execution_storage_cost()
// If future versions of Varuna are introduced, the correct one should be
// deduced here from the consensus version. Currently only the latest Varuna
// version V2 is supported.
let varuna_version = VarunaVersion::V2;

let expected_proof_size = u64::try_from(proof_size::<N>(&batch_sizes, varuna_version, hiding_mode)?)?;
let unproved_execution_size = reconstructed_execution.size_in_bytes()?;
let execution_size = unproved_execution_size.checked_add(expected_proof_size).ok_or(anyhow!(
"The execution size computation overflowed for an authorization when the proof was taken into account"
Expand Down
12 changes: 4 additions & 8 deletions synthesizer/process/src/stack/authorization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,10 @@ impl<N: Network> PartialEq for Authorization<N> {
impl<N: Network> Eq for Authorization<N> {}

impl<N: Network> Authorization<N> {
/// Total number of inputs to the passed `Transition`s that are of type
/// `Input::Record`.
// This method is used to ensure consistency between
// `prepare_verifier_inputs` and the batch-size calculation used in
// `Authorization::proof_size` above. The specifics of the former mean this
// method must receive an iterator of `Transition`s instead of the
// `Authorization` itself. Notably, the `transitions` argument can be
// `authorization.transitions().values()`.
/// Returns the total number of inputs to the passed `Transition`s that are of
/// type `Input::Record`.
// This method is used to ensure consistency between `prepare_verifier_inputs`
// and the batch-size calculation used in `execution_cost_for_authorization`.
#[inline]
pub fn number_of_input_records<'a>(transitions: impl ExactSizeIterator<Item = &'a Transition<N>>) -> usize {
transitions
Expand Down
2 changes: 1 addition & 1 deletion synthesizer/process/src/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl<N: Network> Trace<N> {
let batch_inclusion_inputs =
Inclusion::prepare_verifier_inputs(global_state_root, inclusion_version, transitions.clone())?;

let expected_n_inclusions = Authorization::number_of_input_records(transitions.clone());
let expected_n_inclusions = Authorization::number_of_input_records(transitions);
ensure!(
batch_inclusion_inputs.len() == expected_n_inclusions,
"Unexpected number of inclusion inputs: {} instead of {}",
Expand Down
2 changes: 1 addition & 1 deletion synthesizer/snark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod certificate;
pub use certificate::Certificate;

mod proof;
pub use proof::Proof;
pub use proof::{Proof, proof_size};

mod proving_key;
pub use proving_key::ProvingKey;
Expand Down
24 changes: 24 additions & 0 deletions synthesizer/snark/src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use snarkvm_algorithms::snark::varuna::{VarunaVersion, proof_size as varuna_proof_size};

use super::*;

mod bytes;
Expand All @@ -39,3 +41,25 @@ impl<N: Network> Deref for Proof<N> {
&self.proof
}
}

/// Predicts the size in bytes of the proof as produced by
/// `Proof::serialize_compressed` without needing to receive the proof itself.
///
/// *Arguments*:
/// - `batch_sizes`: the batch sizes of the circuits and instances being
/// proved.
/// - `varuna_version`: the version of Varuna being used
/// - `hiding`: indicates whether the proof system is run in ZK mode
///
/// *Returns*:
/// - `Ok(size)` for `VarunaVersion::V2`, where `size` is the size of the proof
/// in bytes.
/// - `Err` for `VarunaVersion::V1`.
pub fn proof_size<N: Network>(
batch_sizes: &[usize],
varuna_version: VarunaVersion,
hiding_mode: bool,
) -> Result<usize> {
// The extra 1 byte comes from the serialised version number
varuna_proof_size::<N::PairingCurve>(batch_sizes, varuna_version, hiding_mode).map(|size| 1 + size)
}