6#ifndef OPENCBDC_TX_SRC_TRANSACTION_VALIDATION_H_
7#define OPENCBDC_TX_SRC_TRANSACTION_VALIDATION_H_
15#include <secp256k1_schnorrsig.h>
25 static constexpr auto p2pk_witness_prog_len
27 static constexpr auto p2pk_witness_len = p2pk_witness_prog_len + sig_len;
114 variant<input_error, output_error, witness_error, tx_error_code>;
124 -> std::optional<tx_error>;
126 std::pair<input_error_code, std::optional<output_error_code>>>;
128 -> std::optional<tx_error>;
132 -> std::optional<witness_error_code>;
134 -> std::optional<witness_error_code>;
136 -> std::optional<witness_error_code>;
139 -> std::optional<witness_error_code>;
142 -> std::optional<witness_error_code>;
144 -> std::optional<tx_error>;
146 -> std::optional<tx_error>;
148 -> std::optional<tx_error>;
150 -> std::optional<tx_error>;
152 -> std::optional<output_error_code>;
165 const std::unordered_set<pubkey_t, hashing::null>& pubkeys,
166 size_t threshold) -> bool;
auto check_input_structure(const cbdc::transaction::input &inp) -> std::optional< std::pair< input_error_code, std::optional< output_error_code > > >
auto check_p2pk_witness_commitment(const cbdc::transaction::full_tx &tx, size_t idx) -> std::optional< witness_error_code >
auto check_input_set(const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
auto get_p2pk_witness_commitment(const pubkey_t &payee) -> hash_t
std:: variant< input_error, output_error, witness_error, tx_error_code > tx_error
An error that may occur when sentinels or clients statically validate a transaction.
auto to_string(cbdc::transaction::validation::tx_error_code err) -> std::string
auto check_tx(const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
Runs static validation checks on the given transaction.
auto check_attestations(const transaction::compact_tx &tx, const std::unordered_set< pubkey_t, hashing::null > &pubkeys, size_t threshold) -> bool
Validates the sentinel attestations attached to a compact transaction.
auto check_output_count(const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
auto check_witness_count(const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
tx_error_code
Types of errors that may occur when a sentinel statically validates a transaction.
@ no_inputs
There are no inputs.
@ no_outputs
There are no outputs.
@ missing_witness
The number of witnesses and inputs do not match.
@ value_overflow
The total value of inputs/outputs overflows a 64-bit integer.
@ asymmetric_values
The total values of inputs and outputs do not match.
auto check_p2pk_witness(const cbdc::transaction::full_tx &tx, size_t idx) -> std::optional< witness_error_code >
auto check_output_value(const cbdc::transaction::output &out) -> std::optional< output_error_code >
auto check_input_count(const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
witness_error_code
Types of errors that may occur when sentinels validate witness commitments.
@ invalid_signature
The witness's signature is invalid.
@ malformed
The witness's format appears invalid.
@ unknown_witness_program_type
The validation system does not recognize the provided witness_program_type.
@ invalid_public_key
The witness's public key is invalid.
@ program_mismatch
The witness's specified program doesn't match its commitment.
@ missing_witness_program_type
The witness did not provide a witness_program_type.
witness_program_type
Specifies how validators should interpret the witness program.
output_error_code
A transaction input validation error.
@ zero_value
The output's value is 0.
auto check_tx_structure(const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
auto check_p2pk_witness_signature(const cbdc::transaction::full_tx &tx, size_t idx) -> std::optional< witness_error_code >
auto check_p2pk_witness_len(const cbdc::transaction::full_tx &tx, size_t idx) -> std::optional< witness_error_code >
auto check_witness(const cbdc::transaction::full_tx &tx, size_t idx) -> std::optional< witness_error_code >
input_error_code
Types of input validation errors.
@ duplicate
More than one transaction input contains the same output.
@ data_error
A transaction input includes invalid output data.
auto check_in_out_set(const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
std::array< unsigned char, pubkey_len > pubkey_t
A public key of a public/private keypair.
A condensed, hash-only transaction representation.
An output of a transaction.
An error that may occur when sentinels validate transaction outputs.
uint64_t m_idx
The index of the output in the transaction.
auto operator==(const output_error &rhs) const -> bool
output_error_code m_code
The type of output error.
An error that may occur when sentinels validate witness commitments.
auto operator==(const witness_error &rhs) const -> bool
uint64_t m_idx
The index of the witness in the transaction.
witness_error_code m_code
The type of witness error.