27const TaggedHash kRandomnessStatementHash(
28 "Purify/Accountable/AnchorEscrowRandomnessStatement/v4");
29const TaggedHash kRandomnessMasterHash(
30 "Purify/Accountable/AnchorEscrowRandomnessMaster/v4");
31const TaggedHash kEphemeralHash(
32 "Purify/Accountable/AnchorEscrowEphemeral/v4");
33const TaggedHash kProofSeedHash(
34 "Purify/Accountable/AnchorEscrowProofSeed/v4");
36Status require_anchor_v4_hash_suite(
const char* label) {
37#if PURIFY_USE_LEGACY_FIELD_HASHES
45using ::purify::detail::WipeOnDestruction;
47using SecretBytes32 = ::purify::detail::Secret<bppp::ScalarBytes>;
50 const GeneratedKey& ephemeral;
51 const FieldElement& punishment_scalar;
57 std::copy(key.xonly().begin(), key.xonly().end(), out.begin() + 1);
63 if (roster.members().empty()) {
69Status require_distinct_anchor_root(
71 const UInt512& advertised_anchor_root,
73 if (advertised_anchor_root == recovery_root) {
82 "anchor_escrow:shared_secret");
86 "anchor_escrow:shared_peer");
89 curve1().mul_secret_affine(points.first, scalars.first),
90 "anchor_escrow:shared_first");
94 curve2().mul_secret_affine(points.second, scalars.second),
95 "anchor_escrow:shared_second");
97 return combine(first.x, second.x);
101 const UInt512& recipient,
const EscrowOpening& opening) {
104 shared_pad(opening.ephemeral.secret, recipient),
105 "anchor_escrow:encrypt_pad");
109 out.masked_scalar = opening.punishment_scalar + pad;
114 Transcript& transcript,
const UInt512& recipient,
116 const EscrowOpening* opening) {
118 const auto& receiver,
120 "anchor_escrow:recipient");
123 "anchor_escrow:ephemeral");
125 const auto ephemeral_coords,
127 "anchor_escrow:ephemeral_coords");
129 std::array<std::vector<int>, 2> values{
130 std::vector<int>(255, -1), std::vector<int>(255, -1)};
133 if (opening !=
nullptr) {
137 "anchor_escrow:ephemeral_secret");
141 "anchor_escrow:ephemeral_first_bits");
144 "anchor_escrow:ephemeral_second_bits");
146 std::array<std::vector<Expr>, 2> ephemeral_bits;
147 for (std::size_t component = 0; component < 2; ++component) {
148 auto& bits = ephemeral_bits[component];
150 for (
const int&
bit : values[component]) {
153 ? std::optional<FieldElement>{}
154 : std::optional<FieldElement>(
157 bits.push_back(transcript.boolean(
158 transcript.secret(bit_value)));
162 auto punishment_value =
164 ? std::optional<FieldElement>{}
165 : std::optional<FieldElement>(opening->punishment_scalar);
167 const Expr punishment = transcript.secret(punishment_value);
179 curve1(), transcript, receiver.first, ephemeral_bits[0]);
181 curve2(), transcript, receiver.second, ephemeral_bits[1]);
184 transcript, shared_first, shared_second),
185 Expr(ciphertext.masked_scalar));
191 Transcript transcript;
194 escrow_relation(transcript, recipient, ciphertext,
nullptr),
195 "anchor_escrow:relation");
196 BulletproofTranscript bp;
198 "anchor_escrow:lower");
200 bp.bind_output_to_commitment(output),
201 "anchor_escrow:bind_punishment");
202 return bp.native_circuit();
207 const EscrowOpening& opening) {
208 Transcript transcript;
211 escrow_relation(transcript, recipient, ciphertext, &opening),
212 "anchor_escrow:witness_relation");
213 BulletproofTranscript bp;
215 "anchor_escrow:lower_witness");
217 bp.bind_output_to_commitment(output),
218 "anchor_escrow:bind_punishment_witness");
219 return bp.assignment_data(transcript.varmap(),
220 opening.punishment_scalar);
226 const auto ephemeral = ciphertext.ephemeral_key.to_bytes_be();
227 const auto masked = ciphertext.masked_scalar.to_bytes_be();
228 out.insert(out.end(), ephemeral.begin(), ephemeral.end());
229 out.insert(out.end(), masked.begin(), masked.end());
237 std::copy(roster.signing_key().begin(), roster.signing_key().end(),
244 const UInt512& advertised_anchor_root,
248 "anchor_escrow:empty_roster"),
249 "anchor_escrow:randomness_roster");
251 require_distinct_anchor_root(
252 roster.recovery_root(), advertised_anchor_root,
253 "anchor_escrow:recovery_root_alias"),
254 "anchor_escrow:randomness_anchor_root");
257 "anchor_escrow:randomness_anchor_root");
258 const auto recovery_root = roster.recovery_root().to_bytes_be();
259 const auto anchor_root = advertised_anchor_root.to_bytes_be();
260 const auto signing_key = roster_point(roster);
261 const auto punishment = punishment_point(punishment_key);
262 return kRandomnessStatementHash.digest_many<8>({
263 signing_key, roster.key_list_hash(), roster.coalition_core_digest(),
264 roster.nonce_host_commitment(), recovery_root, anchor_root,
265 punishment, context_digest,
272 const UInt512& advertised_anchor_root,
277 "anchor_escrow:empty_roster"),
278 "anchor_escrow:roster");
280 require_distinct_anchor_root(
281 recovery_root, advertised_anchor_root,
282 "anchor_escrow:recovery_root_alias"),
283 "anchor_escrow:binding_anchor_root");
286 "anchor_escrow:binding_anchor_root");
287 const auto recovery_root_bytes = recovery_root.to_bytes_be();
288 const auto anchor_root = advertised_anchor_root.to_bytes_be();
289 const auto encrypted = ciphertext_bytes(ciphertext);
290 const auto signing_key = roster_point(roster);
291 const auto punishment = punishment_point(punishment_key);
292 static const TaggedHash hash(
"Purify/Accountable/AnchorEscrow/v4");
293 const auto digest = hash.digest_many<9>({
294 signing_key, roster.key_list_hash(), roster.coalition_core_digest(),
295 roster.nonce_host_commitment(), recovery_root_bytes, anchor_root,
297 punishment, context_digest,
299 return Bytes(digest.begin(), digest.end());
304 const UInt512& advertised_anchor_root,
308 return escrow_binding(roster, roster.recovery_root(),
309 advertised_anchor_root, punishment_key,
310 context_digest, ciphertext);
314 const GeneratedKey& recipient,
320 shared_pad(recipient.secret, ciphertext.ephemeral_key),
321 "anchor_escrow:decrypt_pad");
323 auto plaintext = (ciphertext.masked_scalar - pad).
to_bytes_be();
328 "anchor_escrow:decrypt_plaintext");
329 if (recovered.bip340_key().seckey != plaintext) {
331 "anchor_escrow:noncanonical_plaintext");
333 if (recovered.public_key() != punishment_key) {
335 "anchor_escrow:wrong_plaintext");
343 const std::array<unsigned char, 32>&
xonly,
347 "anchor_escrow:punishment_public_key"),
348 "anchor_escrow:punishment_public_key");
352 "anchor_escrow:punishment_public_key");
358 std::array<unsigned char, 32> secret,
363 "anchor_escrow:punishment_secret"),
364 "anchor_escrow:punishment_secret");
370 "anchor_escrow:punishment_secret");
380 require_anchor_v4_hash_suite(
"anchor_escrow:shape_hash_suite"),
381 "anchor_escrow:shape_hash_suite");
385 escrow_relation(transcript, recipient, ciphertext,
nullptr),
386 "anchor_escrow:shape_relation");
387 const auto relation_multiplications = transcript.
muls().size();
390 "anchor_escrow:shape_lower");
393 "anchor_escrow:shape_bind");
398Status AnchorEscrowRecord::validate_encoding(
402 "anchor_escrow:record");
405 "anchor_escrow:ciphertext_ephemeral");
406 static constexpr std::size_t kRoundCount = 14;
409 raw_commitment_, mask_commitment_, t2_,
410 public_commitment_dlog_nonce_,
411 public_commitment_dlog_response_, norm_proof_};
415 kRoundCount, secp_context);
421 "anchor_escrow:serialize");
425 const auto encrypted = ciphertext_bytes(ciphertext_);
426 out.insert(out.end(), encrypted.begin(), encrypted.end());
427 out.insert(out.end(), raw_commitment_.begin(), raw_commitment_.end());
428 out.insert(out.end(), mask_commitment_.begin(), mask_commitment_.end());
429 out.insert(out.end(), t2_.begin(), t2_.end());
430 out.insert(out.end(), public_commitment_dlog_nonce_.begin(),
431 public_commitment_dlog_nonce_.end());
432 out.insert(out.end(), public_commitment_dlog_response_.begin(),
433 public_commitment_dlog_response_.end());
434 out.insert(out.end(), norm_proof_.begin(), norm_proof_.end());
440 std::span<const unsigned char> encoded,
444 "anchor_escrow:deserialize_size");
448 "anchor_escrow:deserialize_version");
451 std::size_t offset = 1;
455 std::array<unsigned char, 32> masked{};
456 std::copy_n(encoded.begin() + offset, masked.size(), masked.begin());
457 offset += masked.size();
461 "anchor_escrow:deserialize_masked");
462 std::copy_n(encoded.begin() + offset, out.raw_commitment_.size(),
463 out.raw_commitment_.begin());
464 offset += out.raw_commitment_.size();
465 std::copy_n(encoded.begin() + offset, out.mask_commitment_.size(),
466 out.mask_commitment_.begin());
467 offset += out.mask_commitment_.size();
468 std::copy_n(encoded.begin() + offset, out.t2_.size(),
470 offset += out.t2_.size();
471 std::copy_n(encoded.begin() + offset,
472 out.public_commitment_dlog_nonce_.size(),
473 out.public_commitment_dlog_nonce_.begin());
474 offset += out.public_commitment_dlog_nonce_.size();
475 std::copy_n(encoded.begin() + offset,
476 out.public_commitment_dlog_response_.size(),
477 out.public_commitment_dlog_response_.begin());
478 offset += out.public_commitment_dlog_response_.size();
479 out.norm_proof_.assign(encoded.begin() + offset, encoded.end());
481 "anchor_escrow:deserialize");
487 const UInt512& advertised_anchor_root,
493 require_anchor_v4_hash_suite(
"anchor_escrow:create_hash_suite"),
494 "anchor_escrow:create_hash_suite");
497 "anchor_escrow:create");
498 SecretBytes32 auxiliary_randomness;
500 "anchor_escrow:auxiliary_randomness");
502 roster, advertised_anchor_root, punishment_key, context_digest,
503 auxiliary_randomness.value, secp_context, cache);
508 : bytes_(other.bytes_) {
514 if (
this != &other) {
516 bytes_ = other.bytes_;
526void AnchorEscrowAuxiliaryScalar::clear() noexcept {
533 if (!scalar.has_value()) {
535 "anchor_escrow:auxiliary_scalar_encoding");
538 if (scalar->is_zero()) {
540 "anchor_escrow:auxiliary_scalar_zero");
547 const UInt512& advertised_anchor_root,
554 roster, advertised_anchor_root, punishment_key, context_digest,
555 auxiliary_scalar.bytes_, secp_context, cache);
560 const UInt512& advertised_anchor_root,
567 require_anchor_v4_hash_suite(
568 "anchor_escrow:create_aux_hash_suite"),
569 "anchor_escrow:create_aux_hash_suite");
572 "anchor_escrow:create_aux");
574 "anchor_escrow:empty_roster"),
575 "anchor_escrow:create_roster");
577 const auto& randomness_statement,
578 escrow_randomness_statement(roster,
579 advertised_anchor_root,
582 "anchor_escrow:randomness_statement");
585 auto punishment_scalar,
587 "anchor_escrow:punishment_scalar");
589 SecretBytes32 randomness_master;
591 auto digest = kRandomnessMasterHash.digest_many<3>({
592 auxiliary_randomness, punishment_secret, randomness_statement});
594 randomness_master.value = digest;
596 SecretBytes32 ephemeral_seed;
598 auto digest = kEphemeralHash.digest(randomness_master.value);
600 ephemeral_seed.value = digest;
604 "anchor_escrow:ephemeral");
605 EscrowOpening opening{
612 "anchor_escrow:encrypt");
616 "anchor_escrow:public_circuit");
620 "anchor_escrow:assignment");
623 escrow_binding(roster, advertised_anchor_root,
626 "anchor_escrow:binding");
627 SecretBytes32 prover_seed;
629 auto digest = kProofSeedHash.digest_many<2>({
630 randomness_master.value, binding});
632 prover_seed.value = digest;
634 const std::array<PointBytes, 1> outputs{
635 punishment_point(punishment_key.
public_key())};
639 prove_circuit_zk_norm_arg_v4_with_public_commitments(
640 circuit, assignment, prover_seed.value, outputs,
641 secp_context, binding, cache),
642 "anchor_escrow:prove");
645 record.raw_commitment_ = publication.proof.raw_commitment;
646 record.mask_commitment_ = publication.proof.mask_commitment;
647 record.t2_ = publication.proof.t2;
648 record.public_commitment_dlog_nonce_ =
649 publication.proof.public_commitment_dlog_nonce;
650 record.public_commitment_dlog_response_ =
651 publication.proof.public_commitment_dlog_response;
652 record.norm_proof_ = std::move(publication.proof.norm_proof);
654 "anchor_escrow:proof_encoding");
660 const UInt512& advertised_anchor_root,
667 require_anchor_v4_hash_suite(
"anchor_escrow:verify_hash_suite"),
668 "anchor_escrow:verify_hash_suite");
671 "anchor_escrow:verify");
673 "anchor_escrow:empty_roster"),
674 "anchor_escrow:verify_roster");
676 "anchor_escrow:verify_record");
679 public_escrow_circuit(roster.
recovery_root(), record.ciphertext_),
680 "anchor_escrow:verify_circuit");
683 escrow_binding(roster, advertised_anchor_root, punishment_key,
684 context_digest, record.ciphertext_),
685 "anchor_escrow:verify_binding");
686 const std::array<PointBytes, 1> outputs{
687 punishment_point(punishment_key)};
689 record.raw_commitment_, record.mask_commitment_, record.t2_,
690 record.public_commitment_dlog_nonce_,
691 record.public_commitment_dlog_response_, record.norm_proof_};
695 reconstruct_circuit_zk_norm_arg_publication_v4_with_public_commitments(
696 circuit, std::move(proof), outputs, secp_context, binding),
697 "anchor_escrow:publication");
700 circuit, publication, outputs, secp_context, binding, cache);
712 "Purify/Accountable/ConstructionLeafAccumulation/v1",
714 "construction_leaf_accumulation:basis");
721 const UInt512& advertised_anchor_root,
729 punishment_key, context_digest, ciphertext,
730 circuit_precommitment, secp_context);
737 const UInt512& advertised_anchor_root,
744 require_anchor_v4_hash_suite(
745 "anchor_escrow_parent:hash_suite"),
746 "anchor_escrow_parent:hash_suite");
749 "anchor_escrow_parent:context");
751 require_roster(roster,
"anchor_escrow_parent:empty_roster"),
752 "anchor_escrow_parent:roster");
754 const auto precommitment,
756 circuit_precommitment),
757 "anchor_escrow_parent:precommitment");
760 public_escrow_circuit(recovery_root, ciphertext),
761 "anchor_escrow_parent:circuit");
764 escrow_binding(roster, recovery_root, advertised_anchor_root,
765 punishment_key, context_digest, ciphertext),
766 "anchor_escrow_parent:binding");
767 const std::array<PointBytes, 1> outputs{
768 punishment_point(punishment_key)};
772 derive_circuit_norm_parent_constants_v4_with_public_commitments(
773 circuit, precommitment, outputs, secp_context, binding),
774 "anchor_escrow_parent:derive");
776 std::move(constants.circuit_binding_digest),
777 std::move(constants.raw_generator_digest),
778 std::move(constants.coefficient_commitment),
779 std::move(constants.anchored_offset)};
785 const UInt512& advertised_anchor_root,
792 require_anchor_v4_hash_suite(
793 "anchor_escrow_accumulation:prepare_hash_suite"),
794 "anchor_escrow_accumulation:prepare_hash_suite");
797 "anchor_escrow_accumulation:prepare"),
798 "anchor_escrow_accumulation:prepare");
800 require_roster(roster,
"anchor_escrow_accumulation:empty_roster"),
801 "anchor_escrow_accumulation:roster");
803 "anchor_escrow_accumulation:record");
806 public_escrow_circuit(roster.
recovery_root(), record.ciphertext_),
807 "anchor_escrow_accumulation:circuit");
810 escrow_binding(roster, advertised_anchor_root, punishment_key,
811 context_digest, record.ciphertext_),
812 "anchor_escrow_accumulation:binding");
813 const std::array<PointBytes, 1> outputs{
814 punishment_point(punishment_key)};
816 record.raw_commitment_, record.mask_commitment_, record.t2_,
817 record.public_commitment_dlog_nonce_,
818 record.public_commitment_dlog_response_, record.norm_proof_};
822 reconstruct_circuit_zk_norm_arg_publication_v4_with_public_commitments(
823 circuit, std::move(proof), outputs, secp_context, binding),
824 "anchor_escrow_accumulation:publication");
825 const auto circuit_precommitment =
826 publication.precommitment.bytes();
830 prepare_circuit_zk_norm_arg_v4_with_public_commitments(
831 circuit, publication, outputs, secp_context, binding,
833 "anchor_escrow_accumulation:outer");
834 if (!prepared.has_value()) {
836 "anchor_escrow_accumulation:outer");
841 prepare_v4_circuit_norm_for_algebraic_reduction(
842 basis_, std::move(*prepared), secp_context),
843 "anchor_escrow_accumulation:norm");
850 const UInt512& advertised_anchor_root,
857 require_anchor_v4_hash_suite(
"anchor_escrow:recover_hash_suite"),
858 "anchor_escrow:recover_hash_suite");
860 const auto& recipient,
863 "anchor_escrow:recover_recipient");
865 const auto& accepted,
867 punishment_key, context_digest, record,
868 secp_context, cache),
869 "anchor_escrow:recover_verify");
872 "anchor_escrow:invalid_proof");
875 recipient, punishment_key, record.
ciphertext(), secp_context);
881 const UInt512& advertised_anchor_root,
888 require_anchor_v4_hash_suite(
889 "anchor_escrow:recover_distributed_hash_suite"),
890 "anchor_escrow:recover_distributed_hash_suite");
892 const auto& recipient,
896 "anchor_escrow:recover_distributed_recipient");
900 setup.
roster(), advertised_anchor_root, punishment_key,
901 context_digest, record, secp_context, cache),
902 "anchor_escrow:recover_distributed_verify");
906 "anchor_escrow:recover_distributed_proof");
909 recipient, punishment_key, record.
ciphertext(), secp_context);
918 require_anchor_v4_hash_suite(
919 "anchor_escrow:recover_authenticated_hash_suite"),
920 "anchor_escrow:recover_authenticated_hash_suite");
921 return decrypt_punishment(recovered_recipient, punishment_key,
922 ciphertext, secp_context);
Lowering helper that converts a symbolic transcript into native Bulletproof witness and circuit forms...
Status from_transcript(const Transcript &transcript, std::size_t n_bits, std::size_t minimum_gate_count=1)
Imports a symbolic transcript with a fixed power-of-two gate floor.
Status bind_output_to_commitment(Expr output)
Binds a scalar expression to public commitment slot zero.
NativeBulletproofCircuit native_circuit() const
Builds the native sparse circuit object from the lowered assignments and constraints.
Field element modulo the backend scalar field used by this implementation.
static FieldElement from_uint256(const UInt256 &value)
Converts a 256-bit unsigned integer into the scalar field representation.
static Result< FieldElement > try_from_bytes32(const std::array< unsigned char, 32 > &bytes)
Decodes a canonical 32-byte big-endian field element.
static FieldElement from_int(std::int64_t value)
Constructs a field element from a signed integer, reducing negatives modulo the field.
Mutable transcript used to record symbolic multiplication, division, and boolean constraints.
const std::vector< MulConstraint > & muls() const
Returns the multiplication and division constraints accumulated so far.
AnchorEscrowAuxiliaryScalar()=delete
AnchorEscrowAuxiliaryScalar & operator=(const AnchorEscrowAuxiliaryScalar &)=delete
static Result< AnchorEscrowAuxiliaryScalar > from_bytes(const Bytes &encoded)
~AnchorEscrowAuxiliaryScalar()
Result< Bytes > serialize(purify_secp_context *secp_context) const
AnchorEscrowRecord(const AnchorEscrowRecord &)=default
const AnchorEscrowCiphertext & ciphertext() const noexcept
static constexpr std::size_t kSerializedSize
static constexpr std::size_t kNormProofSize
static constexpr unsigned char kSerializationVersion
static Result< AnchorEscrowRecord > deserialize(std::span< const unsigned char > encoded, purify_secp_context *secp_context)
const AnchorPunishmentPublicKey & public_key() const noexcept
AnchorPunishmentKey(const AnchorPunishmentKey &)=delete
static Result< AnchorPunishmentKey > from_secret(std::array< unsigned char, 32 > secret, purify_secp_context *secp_context)
const Bip340Key & bip340_key() const noexcept
AnchorPunishmentPublicKey(const AnchorPunishmentPublicKey &)=default
const std::array< unsigned char, 32 > & xonly() const noexcept
static Result< AnchorPunishmentPublicKey > create(const std::array< unsigned char, 32 > &xonly, purify_secp_context *secp_context)
Result< ConstructionLeafParentConstants > derive_parent_constants(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowCiphertext &ciphertext, const bppp::ScalarBytes &circuit_precommitment, purify_secp_context *secp_context) const
static Result< ConstructionLeafAccumulator > create(purify_secp_context *secp_context)
const bppp::accumulation::Basis & basis() const noexcept
Result< PreparedConstructionLeaf > prepare(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowRecord &record, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr) const
ConstructionLeafAccumulator(const ConstructionLeafAccumulator &)=delete
static constexpr std::size_t kNormVectorLength
Result< ConstructionLeafParentConstants > derive_pending_anchor_parent_constants(const NonceHostBoundSigningRoster &roster, const UInt512 &recovery_root, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowCiphertext &ciphertext, const bppp::ScalarBytes &circuit_precommitment, purify_secp_context *secp_context) const
An ordered signing roster bound to one core and nonce-host list.
A nonce-host-bound roster with an authorized recovery-root relation.
const UInt512 & recovery_root() const
static constexpr std::size_t kNormProofSize
const RecoveryBoundSigningRoster & roster() const noexcept
const RecoveryRootShareAggregate & aggregate() const noexcept
Common interface for reusable experimental BPPP backend state.
static Result< Basis > create(std::size_t n_vec_len, std::size_t l_vec_len, std::string_view semantic_domain, purify_secp_context *context)
static Result< CircuitPrecommitmentDigestV4 > parse(const ScalarBytes &encoded)
#define PURIFY_RETURN_IF_ERROR(expr, context)
Evaluates an expected-like expression and returns the wrapped error on failure.
#define PURIFY_ASSIGN_OR_RETURN(lhs, expr, context)
Evaluates an expected-like expression, binds the value to lhs, and propagates errors.
Result< GeneratedKey > recover_aggregated_recovery_root(const NonceHostBoundSigningRoster &roster, const RecoveryRootShareAggregate &aggregate, const FieldElement &exposed_signing_scalar, purify_secp_context *secp_context)
Result< AnchorPunishmentKey > recover_distributed_escrowed_anchor(const VerifiedDistributedRecoverySetup &setup, const FieldElement &exposed_signing_scalar, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowRecord &record, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
Result< AnchorEscrowRecord > create_anchor_escrow_deterministic(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowAuxiliaryScalar &auxiliary_scalar, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
std::array< unsigned char, 32 > AnchorEscrowContextDigest
Result< AnchorPunishmentKey > recover_authenticated_anchor_ciphertext(const GeneratedKey &recovered_recipient, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowCiphertext &ciphertext, purify_secp_context *secp_context)
Result< AnchorEscrowRecord > create_anchor_escrow_with_aux_randomness(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const bppp::ScalarBytes &auxiliary_randomness, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache)
Result< AnchorEscrowRecord > create_anchor_escrow(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentKey &punishment_key, const AnchorEscrowContextDigest &context_digest, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
Result< AnchorPunishmentKey > recover_escrowed_anchor(const RecoveryBoundSigningRoster &roster, const FieldElement &exposed_signing_scalar, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowRecord &record, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
Result< AnchorEscrowCircuitShape > anchor_escrow_circuit_shape_for_testing(const UInt512 &recipient, const AnchorEscrowCiphertext &ciphertext)
Result< GeneratedKey > recover_registered_root(const RecoveryBoundSigningRoster &roster, const FieldElement &exposed_signing_scalar, purify_secp_context *secp_context)
Result< bool > verify_anchor_escrow(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowRecord &record, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
Result< bool > verify_circuit_zk_norm_arg_v4_with_public_commitments(const NativeBulletproofCircuit &circuit, const CircuitZkNormArgPublicationV4 &publication, std::span< const PointBytes > public_commitments, purify_secp_context *secp_context, std::span< const unsigned char > statement_binding, ExperimentalCircuitBackend *cache=nullptr)
Status validate_circuit_zk_norm_arg_proof_v4_fixed_encoding(const CircuitZkNormArgProofV4 &proof, CircuitCommitmentModeV4 mode, std::size_t round_count, purify_secp_context *secp_context)
std::array< unsigned char, 33 > PointBytes
Compressed 33-byte curve-point encoding.
std::array< unsigned char, 32 > ScalarBytes
Big-endian 32-byte scalar encoding.
void secure_clear_bytes(void *data, std::size_t size) noexcept
Status require_secp_context(const purify_secp_context *context, const char *error_context)
const UInt256 & half_n1()
Returns floor(order_n1 / 2).
constexpr Unexpected< Error > unexpected_error(ErrorCode code, const char *context=nullptr)
Constructs an unexpected Error value from a machine-readable code.
BigUInt< 8 > UInt512
512-bit unsigned integer used for private and packed public keys.
Result< std::vector< int > > key_to_bits(UInt256 n, const UInt256 &max_value)
Encodes a scalar into the signed 3-bit window bit schedule used by the circuit.
Result< GeneratedKey > generate_key()
Generates a random Purify keypair using the built-in OS RNG.
Result< std::pair< UInt256, UInt256 > > unpack_public(const UInt512 &packed)
Splits a packed public key into its two x-coordinates.
const UInt256 & half_n2()
Returns floor(order_n2 / 2).
Expr circuit_combine(Transcript &transcript, const Expr &x1, const Expr &x2)
Builds the symbolic Purify output combiner over two x-coordinates.
const EllipticCurve & curve1()
Returns the first Purify curve instance.
Expr circuit_ec_multiply_x(const EllipticCurve &curve, Transcript &transcript, const JacobianPoint &point, const std::vector< Expr > &bits)
Builds the symbolic x-coordinate multiplication gadget for one curve point.
Expected< T, Error > Result
Expected-returning convenience alias for Purify value-producing APIs.
const JacobianPoint & generator1()
Returns the fixed generator for the first curve.
Result< std::pair< UInt256, UInt256 > > unpack_secret(const UInt512 &z)
Splits a packed private key into its two per-curve secret scalars.
Expected< void, Error > Status
Expected-returning convenience alias for Purify status-only APIs.
Result< std::pair< JacobianPoint, JacobianPoint > > unpack_public_points(const UInt512 &packed)
Decodes and validates both curve points in a packed public key.
std::vector< unsigned char > Bytes
Dynamically sized byte string used for messages, serialized witnesses, and proofs.
const EllipticCurve & curve2()
Returns the second Purify curve instance.
const JacobianPoint & generator2()
Returns the fixed generator for the second curve.
FieldElement combine(const FieldElement &x1, const FieldElement &x2)
Applies the Purify curve-combination map to two x-coordinates.
Status fill_secure_random(std::span< unsigned char > bytes) noexcept
Fills a buffer with operating-system randomness.
Status validate_public_points(const UInt512 &packed)
Validates both curve points in a packed public key.
Narrow C ABI exposing secp256k1 scalar and HMAC helpers to the C++ headers.
int purify_bip340_key_from_seckey(purify_secp_context *context, unsigned char seckey32[32], unsigned char xonly_pubkey32[32])
Canonicalizes a valid secp256k1 secret key for BIP340 and derives its x-only public key.
int purify_bip340_validate_xonly_pubkey(purify_secp_context *context, const unsigned char xonly_pubkey32[32])
Returns nonzero when the x-only public key encoding parses successfully.
struct purify_secp_context purify_secp_context
Caller-owned reusable secp256k1 context handle shared across Purify C and C++ APIs.
static BigUInt from_bytes_be(const unsigned char *data, std::size_t size)
Canonical BIP340 keypair derived deterministically from a packed Purify secret.
std::array< unsigned char, 32 > seckey
std::array< unsigned char, 32 > xonly_pubkey
Derived Purify keypair bundle with an owned packed secret and its matching public key.
FieldElement masked_scalar
static constexpr std::size_t kSerializedSize
void PURIFY_UINT_FN to_bytes_be(unsigned char out[PURIFY_UINT_WORDS *8], const uint64_t value[PURIFY_UINT_WORDS])
int PURIFY_UINT_FN bit(const uint64_t value[PURIFY_UINT_WORDS], size_t index)