Skip to content

sigma_protocol_statement_builder - [devnet]

A builder for Statement<P> that eliminates manual parallel-vector construction.

Instead of manually maintaining two parallel vectors (points and compressed_points) that must stay in sync, callers add points via builder methods that handle both vectors internally.

CRITICAL: Builder order must match index constants

Points must be added in exactly the order the index constants define:

  • IDX_H = 0 → first add_point call adds H
  • IDX_EK = 1 → second add_point call adds ek
  • etc.

The assert_*_statement_is_well_formed() check catches size mismatches but NOT ordering mistakes. The builder does NOT change the index layout.

- [CRITICAL: Builder order must match index constants](#@CRITICAL:_Builder_order_must_match_index_constants_0)
use 0x1::ristretto255;
use 0x1::sigma_protocol_statement;

Structs

StatementBuilder

struct StatementBuilder<P> has drop
Fields
points: vector<ristretto255::RistrettoPoint>
compressed_points: vector<ristretto255::CompressedRistretto>
scalars: vector<ristretto255::Scalar>

Functions

new_builder

public(friend) fun new_builder<P>(): sigma_protocol_statement_builder::StatementBuilder<P>
Implementation
public(friend) fun new_builder<P>(): StatementBuilder<P> {
StatementBuilder {
points: vector[],
compressed_points: vector[],
scalars: vector[],
}
}

add_point

Add a compressed point; decompresses internally. Returns the index.

public(friend) fun add_point<P>(self: &mut sigma_protocol_statement_builder::StatementBuilder<P>, p: ristretto255::CompressedRistretto): u64
Implementation
public(friend) fun add_point<P>(self: &mut StatementBuilder<P>, p: CompressedRistretto): u64 {
let idx = self.points.length();
self.points.push_back(p.point_decompress());
self.compressed_points.push_back(p);
idx
}

add_points

Add a vector of compressed points; decompresses all internally. Returns the starting index.

public(friend) fun add_points<P>(self: &mut sigma_protocol_statement_builder::StatementBuilder<P>, v: &vector<ristretto255::CompressedRistretto>): u64
Implementation
public(friend) fun add_points<P>(self: &mut StatementBuilder<P>, v: &vector<CompressedRistretto>): u64 {
let start = self.points.length();
v.for_each_ref(|p| {
let p_val = *p;
self.points.push_back(p_val.point_decompress());
self.compressed_points.push_back(p_val);
});
start
}

add_points_cloned

Like add_points, but also returns clones of the decompressed points. Useful when the caller needs the decompressed points for other purposes (e.g., range proofs).

public(friend) fun add_points_cloned<P>(self: &mut sigma_protocol_statement_builder::StatementBuilder<P>, v: &vector<ristretto255::CompressedRistretto>): (u64, vector<ristretto255::RistrettoPoint>)
Implementation
public(friend) fun add_points_cloned<P>(self: &mut StatementBuilder<P>, v: &vector<CompressedRistretto>): (u64, vector<RistrettoPoint>) {
let start = self.points.length();
let cloned = vector[];
v.for_each_ref(|p| {
let p_val = *p;
let decompressed = p_val.point_decompress();
cloned.push_back(decompressed.point_clone());
self.points.push_back(decompressed);
self.compressed_points.push_back(p_val);
});
(start, cloned)
}

add_scalar

public(friend) fun add_scalar<P>(self: &mut sigma_protocol_statement_builder::StatementBuilder<P>, s: ristretto255::Scalar): u64
Implementation
public(friend) fun add_scalar<P>(self: &mut StatementBuilder<P>, s: Scalar): u64 {
let idx = self.scalars.length();
self.scalars.push_back(s);
idx
}

build

public(friend) fun build<P>(self: sigma_protocol_statement_builder::StatementBuilder<P>): sigma_protocol_statement::Statement<P>
Implementation
public(friend) fun build<P>(self: StatementBuilder<P>): Statement<P> {
let StatementBuilder { points, compressed_points, scalars } = self;
sigma_protocol_statement::new_statement(points, compressed_points, scalars)
}