purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
construction_parent_verifier.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Judica, Inc.
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or https://opensource.org/license/mit/.
4
6
7#include <array>
8#include <cstddef>
9#include <cstdint>
10#include <utility>
11#include <vector>
12
17
18namespace purify::accountable {
19namespace {
20
27
28Unexpected<Error> load_error(
30 switch (status) {
33 "construction_parent:artifact_path");
36 "construction_parent:artifact_open");
39 "construction_parent:artifact_identity");
42 "construction_parent:artifact_snapshot");
48 "construction_parent:artifact_backend");
49 }
51 "construction_parent:artifact_status");
52}
53
54Unexpected<Error> verify_error(
56 switch (status) {
59 "construction_parent:malformed");
62 "construction_parent:proof");
70 "construction_parent:backend");
71 }
73 "construction_parent:status");
74}
75
76} // namespace
77
88
90 std::unique_ptr<Impl> impl)
91 : impl_(std::move(impl)) {}
92
94 ConstructionParentVerifier&&) noexcept = default;
95
97 ConstructionParentVerifier&&) noexcept = default;
98
100
101Result<AnchorPunishmentKey> VerifiedConstructionReceipt::recover_anchor(
102 const FieldElement& exposed_signing_scalar,
103 std::size_t anchor_index,
104 purify_secp_context* secp_context) const {
105 if (entries_.size() != resolved_entries_.size() ||
106 entries_.size() != anchor_count_) {
107 return unexpected_error(ErrorCode::InternalMismatch,
108 "construction_parent:receipt_entries");
109 }
110 if (anchor_index >= entries_.size()) {
111 return unexpected_error(ErrorCode::IndexOutOfRange,
112 "construction_parent:anchor_index");
113 }
115 const auto& recipient,
117 roster_, aggregate_, exposed_signing_scalar, secp_context),
118 "construction_parent:recover_recipient");
119 const auto& entry = entries_[anchor_index];
120 const auto& resolved = resolved_entries_[anchor_index];
122 recipient, resolved.punishment_key, entry.ciphertext,
123 secp_context);
124}
125
127 std::string_view artifact_path) {
128 if (artifact_path.empty() ||
129 artifact_path.find('\0') != std::string_view::npos) {
131 "construction_parent:artifact_path");
132 }
135 reinterpret_cast<const std::uint8_t*>(artifact_path.data()),
136 artifact_path.size(), &verifier);
137 if (status != PURIFY_CONSTRUCTION_PARENT_OK) {
138 return load_error(status);
139 }
140 if (verifier == nullptr) {
142 "construction_parent:artifact_owner");
143 }
145 std::make_unique<Impl>(verifier));
146}
147
149 const ResolvedConstructionSetup& setup,
150 const ConstructionReceiptEnvelope& envelope,
151 std::span<const ResolvedConstructionReceiptEntry> resolved_entries,
152 const ConstructionLeafAccumulator& leaves,
153 purify_secp_context* secp_context) const {
154 if (!impl_ || impl_->verifier == nullptr) {
156 "construction_parent:verifier");
157 }
158
159 const auto& payload = envelope.payload();
160 const auto anchor_entries = payload.anchor_entries();
162 auto inputs,
164 setup, payload, resolved_entries, leaves, secp_context),
165 "construction_parent:public_inputs");
166 std::array<unsigned char,
168 pending_root{};
169 const auto& basis_digest = leaves.basis().digest();
170 const auto recovery_root = setup.recovery_root().to_bytes_be();
171 const Bytes& proof = envelope.parent_proof();
172 const auto status = purify_construction_parent_verify(
173 impl_->verifier, inputs.statement_digest.data(),
174 setup.resolved_digest().bytes().data(), recovery_root.data(),
175 basis_digest.data(), inputs.raw_generator_digest.data(),
176 inputs.setup_count, inputs.anchor_count, inputs.descriptors.data(),
177 inputs.descriptors.size(), proof.data(), proof.size(),
178 pending_root.data(), pending_root.size());
179 if (status != PURIFY_CONSTRUCTION_PARENT_OK) {
180 return verify_error(status);
181 }
182
184 auto final_claim,
186 leaves.basis(), pending_root, secp_context),
187 "construction_parent:parse_root");
190 leaves.basis(), final_claim, secp_context),
191 "construction_parent:decide");
193 inputs.statement_digest, setup.roster(),
194 std::move(inputs.aggregate),
195 std::vector<ConstructionReceiptAnchorEntry>(
196 anchor_entries.begin(), anchor_entries.end()),
197 std::vector<ResolvedConstructionReceiptEntry>(
198 resolved_entries.begin(), resolved_entries.end()));
199}
200
201} // namespace purify::accountable
Field element modulo the backend scalar field used by this implementation.
Definition numeric.hpp:834
const bppp::accumulation::Basis & basis() const noexcept
ConstructionParentVerifier(const ConstructionParentVerifier &)=delete
Result< VerifiedConstructionReceipt > verify(const ResolvedConstructionSetup &setup, const ConstructionReceiptEnvelope &envelope, std::span< const ResolvedConstructionReceiptEntry > resolved_entries, const ConstructionLeafAccumulator &leaves, purify_secp_context *secp_context) const
static Result< ConstructionParentVerifier > load(std::string_view artifact_path)
const ConstructionReceiptPayload & payload() const noexcept
std::span< const ConstructionReceiptAnchorEntry > anchor_entries() const noexcept
const ResolvedConstructionSetupDigestBytes & bytes() const noexcept
const ResolvedConstructionSetupDigest & resolved_digest() const noexcept
const NonceHostBoundSigningRoster & roster() const noexcept
Result< AnchorPunishmentKey > recover_anchor(const FieldElement &exposed_signing_scalar, std::size_t anchor_index, purify_secp_context *secp_context) const
const Digest & digest() const
void purify_construction_parent_verifier_destroy(purify_construction_parent_verifier *verifier)
purify_construction_parent_status purify_construction_parent_verify(const purify_construction_parent_verifier *verifier, const uint8_t construction_statement_digest[32], const uint8_t resolved_setup_record_digest[32], const uint8_t recovery_root[64], const uint8_t native_basis_digest[32], const uint8_t native_raw_generator_digest[32], uint32_t setup_count, uint32_t anchor_count, const uint8_t *leaf_descriptors, size_t leaf_descriptors_length, const uint8_t *proof, size_t proof_length, uint8_t *pending_root_output, size_t pending_root_capacity)
@ PURIFY_CONSTRUCTION_PARENT_ROOT_SIZE
@ PURIFY_CONSTRUCTION_PARENT_DESCRIPTOR_SIZE
@ PURIFY_CONSTRUCTION_PARENT_PROOF_SIZE
struct purify_construction_parent_verifier purify_construction_parent_verifier
purify_construction_parent_status
@ PURIFY_CONSTRUCTION_PARENT_ARTIFACT_SNAPSHOT_FAILED
@ PURIFY_CONSTRUCTION_PARENT_INTERNAL_ERROR
@ PURIFY_CONSTRUCTION_PARENT_ARTIFACT_OPEN_FAILED
@ PURIFY_CONSTRUCTION_PARENT_ARTIFACT_REJECTED
@ PURIFY_CONSTRUCTION_PARENT_OK
@ PURIFY_CONSTRUCTION_PARENT_MALFORMED
@ PURIFY_CONSTRUCTION_PARENT_BUFFER_TOO_SMALL
@ PURIFY_CONSTRUCTION_PARENT_PROOF_REJECTED
purify_construction_parent_status purify_construction_parent_verifier_load(const uint8_t *artifact_path, size_t artifact_path_length, purify_construction_parent_verifier **verifier_output)
Locally verified construction receipts under the selected suite.
#define PURIFY_RETURN_IF_ERROR(expr, context)
Evaluates an expected-like expression and returns the wrapped error on failure.
Definition error.hpp:329
#define PURIFY_ASSIGN_OR_RETURN(lhs, expr, context)
Evaluates an expected-like expression, binds the value to lhs, and propagates errors.
Definition error.hpp:338
Result< ResolvedConstructionParentPublicInputs > resolve_construction_parent_public_inputs(const ResolvedConstructionSetup &setup, const ConstructionReceiptPayload &payload, std::span< const ResolvedConstructionReceiptEntry > resolved_entries, const ConstructionLeafAccumulator &leaves, purify_secp_context *secp_context)
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_authenticated_anchor_ciphertext(const GeneratedKey &recovered_recipient, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowCiphertext &ciphertext, purify_secp_context *secp_context)
Result< PendingClaim > parse_root_claim(const Basis &basis, std::span< const unsigned char > encoded, purify_secp_context *context)
Status decide(const Basis &basis, const PendingClaim &claim, purify_secp_context *context)
constexpr Unexpected< Error > unexpected_error(ErrorCode code, const char *context=nullptr)
Constructs an unexpected Error value from a machine-readable code.
Definition error.hpp:293
Result< std::string > verifier(const Bytes &message, const UInt512 &pubkey)
Builds the legacy serialized verifier description for a message and public key.
Definition api.cpp:197
Expected< T, Error > Result
Expected-returning convenience alias for Purify value-producing APIs.
Definition error.hpp:99
std::vector< unsigned char > Bytes
Dynamically sized byte string used for messages, serialized witnesses, and proofs.
Definition common.hpp:99
std::array< unsigned char, Words *8 > to_bytes_be() const
Serializes the value to a fixed-width big-endian byte array.
Definition numeric.hpp:640
Impl(purify_construction_parent_verifier *verifier_in)