25using Clock = std::chrono::steady_clock;
27double elapsed_ms(Clock::time_point start) {
28 return std::chrono::duration<double, std::milli>(Clock::now() - start).count();
31void usage(std::ostream& output, std::string_view executable) {
32 output <<
"Usage: " << executable <<
" --members N\n"
33 <<
" N must be between 1 and 100. Each run creates one proof.\n"
34 <<
" Centralized imported arithmetic-proof baseline, not MPC.\n";
37bool parse_members(std::string_view text, std::size_t& members) {
38 const auto parsed = std::from_chars(text.data(), text.data() + text.size(), members);
39 return parsed.ec == std::errc() && parsed.ptr == text.data() + text.size()
40 && members >= 1 && members <= 100;
46 std::cerr <<
"Failed at " << stage <<
": " << result.
error().
name() <<
'\n';
58int benchmark(std::size_t members) {
59 std::cerr <<
"CENTRALIZED BASELINE: all witnesses are held by one process; no MPC.\n"
60 <<
"Backend: imported legacy Bulletproof arithmetic circuit; members="
63 const auto start = Clock::now();
65 if (context ==
nullptr) {
66 std::cerr <<
"Failed to create secp context\n";
71 auto stage = Clock::now();
73 if (!succeeded(topic_cache,
"topic template"))
return 1;
74 const double template_ms = elapsed_ms(stage);
76 std::vector<purify::GeneratedKey> keys;
77 keys.reserve(members);
79 for (std::size_t i = 0; i < members; ++i) {
81 if (!succeeded(key,
"member key generation"))
return 1;
82 keys.push_back(std::move(*key));
84 const double keygen_ms = elapsed_ms(stage);
86 std::vector<purify::UInt512> hosts;
87 std::vector<purify::BulletproofAssignmentData> assignments;
88 hosts.reserve(members);
89 assignments.reserve(members);
91 for (
const auto& key : keys) {
93 if (!succeeded(witness,
"member witness generation"))
return 1;
94 hosts.push_back(witness->public_key);
95 assignments.push_back(std::move(witness->assignment));
97 const double witness_ms = elapsed_ms(stage);
100 stage = Clock::now();
101 auto circuit = topic_cache->circuit_template.instantiate_sum(hosts);
102 if (!succeeded(circuit,
"aggregate circuit construction"))
return 1;
103 const double circuit_ms = elapsed_ms(stage);
105 stage = Clock::now();
106 auto assignment = topic_cache->circuit_template.sum_assignments(hosts, assignments);
107 if (!succeeded(assignment,
"aggregate witness validation and composition"))
return 1;
108 const double composition_ms = elapsed_ms(stage);
117 if (!succeeded(entropy,
"private prover randomness"))
return 1;
120 std::cerr <<
"Generating aggregate proof\n";
121 stage = Clock::now();
123 *circuit, *assignment, nonce.bytes, value_generator, context.get(),
124 binding, {}, &prover_cache);
125 if (!succeeded(proof,
"aggregate proof generation"))
return 1;
126 const double prove_ms = elapsed_ms(stage);
127 prover_cache.
clear();
129 stage = Clock::now();
130 auto serialized = proof->serialize();
131 if (!succeeded(serialized,
"proof serialization"))
return 1;
133 if (!succeeded(parsed,
"proof deserialization"))
return 1;
134 const double serialization_ms = elapsed_ms(stage);
138 std::cerr <<
"Verifying serialized aggregate proof\n";
139 stage = Clock::now();
141 *circuit, *parsed, value_generator, context.get(), binding, &verifier_cache);
142 if (!succeeded(verified,
"aggregate proof verification"))
return 1;
144 std::cerr <<
"Aggregate proof verification rejected the generated proof\n";
147 const double verify_ms = elapsed_ms(stage);
149 std::cout << std::fixed << std::setprecision(3)
151 <<
" \"backend\": \"imported_legacy_arithmetic\",\n"
152 <<
" \"centralized\": true,\n"
153 <<
" \"mpc\": false,\n"
154 <<
" \"cold_prover_and_verifier_resources\": true,\n"
155 <<
" \"members\": " << members <<
",\n"
156 <<
" \"gates\": " << circuit->n_gates <<
",\n"
157 <<
" \"constraints\": " << circuit->c.size() <<
",\n"
158 <<
" \"public_commitments\": " << circuit->n_commitments <<
",\n"
159 <<
" \"raw_proof_bytes\": " << proof->proof.size() <<
",\n"
160 <<
" \"commitment_bytes\": " << (proof->commitments.size() * 33) <<
",\n"
161 <<
" \"framed_proof_bytes\": " << serialized->size() <<
",\n"
162 <<
" \"template_ms\": " << template_ms <<
",\n"
163 <<
" \"keygen_ms\": " << keygen_ms <<
",\n"
164 <<
" \"witness_ms\": " << witness_ms <<
",\n"
165 <<
" \"circuit_ms\": " << circuit_ms <<
",\n"
166 <<
" \"composition_ms\": " << composition_ms <<
",\n"
167 <<
" \"prove_ms\": " << prove_ms <<
",\n"
168 <<
" \"serialization_ms\": " << serialization_ms <<
",\n"
169 <<
" \"verify_ms\": " << verify_ms <<
",\n"
170 <<
" \"total_ms\": " << elapsed_ms(start) <<
",\n"
171 <<
" \"verified\": true\n"
178int main(
int argc,
char** argv) {
179 if (argc == 2 && std::string_view(argv[1]) ==
"--help") {
180 usage(std::cout, argv[0]);
183 std::size_t members = 0;
184 if (argc != 3 || std::string_view(argv[1]) !=
"--members" || !parse_members(argv[2], members)) {
185 usage(std::cerr, argv[0]);
188 return benchmark(members);
int main(int argc, char **argv)
C++ wrappers for the BPPP functionality used by Purify.
bool has_value() const noexcept
Caller-owned cache for reusable legacy Bulletproof backend resources keyed by gate count.
GeneratorBytes base_generator(purify_secp_context *secp_context)
Returns the serialized secp256k1 base generator used as the blind generator.
void secure_clear_bytes(void *data, std::size_t size) noexcept
Result< ExperimentalBulletproofProof > prove_experimental_circuit(const NativeBulletproofCircuit &circuit, const BulletproofAssignmentData &assignment, const BulletproofScalarBytes &nonce, const BulletproofGeneratorBytes &value_generator, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, std::span< const BulletproofScalarBytes > blinds={}, ExperimentalBulletproofBackendCache *backend_cache=nullptr)
Proves a native circuit with the experimental imported Bulletproof circuit backend.
Result< BulletproofWitnessData > prove_assignment_data(const Bytes &message, const SecretKey &secret)
Computes the native Purify witness for a message and secret.
Result< GeneratedKey > generate_key()
Generates a random Purify keypair using the built-in OS RNG.
Result< bool > verify_experimental_circuit(const NativeBulletproofCircuit &circuit, const ExperimentalBulletproofProof &proof, const BulletproofGeneratorBytes &value_generator, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding={}, ExperimentalBulletproofBackendCache *backend_cache=nullptr)
Verifies a proof produced by prove_experimental_circuit against the same native circuit and ordered o...
Bytes bytes_from_ascii(std::string_view input)
Encodes an ASCII string as a byte vector.
SecpContextPtr make_secp_context() noexcept
Expected< T, Error > Result
Expected-returning convenience alias for Purify value-producing APIs.
std::array< unsigned char, 32 > BulletproofScalarBytes
Status fill_secure_random(std::span< unsigned char > bytes) noexcept
Fills a buffer with operating-system randomness.
Umbrella header that re-exports the public Purify API.
constexpr std::string_view name() const noexcept
static Result< ExperimentalBulletproofProof > deserialize(std::span< const unsigned char > bytes)
static Result< TopicProofCache > build(std::span< const unsigned char > topic)
Builds a reusable verifier template for one exact topic.