OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::transaction::validation Namespace Reference

Data Structures

struct  input_error
 An error that may occur when sentinels validate inputs. More...
 
struct  output_error
 An error that may occur when sentinels validate transaction outputs. More...
 
struct  witness_error
 An error that may occur when sentinels validate witness commitments. More...
 

Typedefs

using tx_error
 An error that may occur when sentinels or clients statically validate a transaction.
 

Enumerations

enum class  witness_program_type : uint8_t { p2pk = 0x0 }
 Specifies how validators should interpret the witness program. More...
 
enum class  input_error_code : uint8_t { duplicate , data_error }
 Types of input validation errors. More...
 
enum class  output_error_code : uint8_t { zero_value }
 A transaction input validation error. More...
 
enum class  witness_error_code : uint8_t {
  missing_witness_program_type , unknown_witness_program_type , malformed , program_mismatch ,
  invalid_public_key , invalid_signature
}
 Types of errors that may occur when sentinels validate witness commitments. More...
 
enum class  tx_error_code : uint8_t {
  no_inputs , no_outputs , missing_witness , asymmetric_values ,
  value_overflow
}
 Types of errors that may occur when a sentinel statically validates a transaction. More...
 

Functions

auto check_tx (const transaction::full_tx &tx) -> std::optional< tx_error >
 Runs static validation checks on the given transaction.
 
auto check_tx_structure (const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
 
auto check_input_structure (const cbdc::transaction::input &inp) -> std::optional< std::pair< input_error_code, std::optional< output_error_code > > >
 
auto check_in_out_set (const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
 
auto check_witness (const cbdc::transaction::full_tx &tx, size_t idx) -> std::optional< witness_error_code >
 
auto check_p2pk_witness (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_p2pk_witness_commitment (const cbdc::transaction::full_tx &tx, size_t idx) -> std::optional< witness_error_code >
 
auto check_p2pk_witness_signature (const cbdc::transaction::full_tx &tx, size_t idx) -> std::optional< witness_error_code >
 
auto check_input_count (const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
 
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 >
 
auto check_input_set (const cbdc::transaction::full_tx &tx) -> std::optional< tx_error >
 
auto check_output_value (const cbdc::transaction::output &out) -> std::optional< output_error_code >
 
auto get_p2pk_witness_commitment (const pubkey_t &payee) -> hash_t
 
auto to_string (cbdc::transaction::validation::tx_error_code err) -> std::string
 
auto to_string (cbdc::transaction::validation::input_error_code err) -> std::string
 
auto to_string (cbdc::transaction::validation::output_error_code err) -> std::string
 
auto to_string (const cbdc::transaction::validation::input_error &err) -> std::string
 
auto to_string (cbdc::transaction::validation::witness_error_code err) -> std::string
 
auto to_string (const witness_error &err) -> std::string
 
auto to_string (const output_error &err) -> std::string
 
auto to_string (const tx_error &err) -> std::string
 
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.
 

Typedef Documentation

◆ tx_error

Initial value:
std::
variant<input_error, output_error, witness_error, tx_error_code>

An error that may occur when sentinels or clients statically validate a transaction.

A transaction can fail validation because of an error in the inputs, outputs, witnesses, or because the transaction-local invariants do not hold.

Definition at line 113 of file validation.hpp.

Enumeration Type Documentation

◆ input_error_code

Types of input validation errors.

Enumerator
duplicate 

More than one transaction input contains the same output.

data_error 

A transaction input includes invalid output data.

Definition at line 30 of file validation.hpp.

◆ output_error_code

A transaction input validation error.

Enumerator
zero_value 

The output's value is 0.

Definition at line 37 of file validation.hpp.

◆ tx_error_code

enum class cbdc::transaction::validation::tx_error_code : uint8_t
strong

Types of errors that may occur when a sentinel statically validates a transaction.

Enumerator
no_inputs 

There are no inputs.

no_outputs 

There are no outputs.

missing_witness 

The number of witnesses and inputs do not match.

asymmetric_values 

The total values of inputs and outputs do not match.

value_overflow 

The total value of inputs/outputs overflows a 64-bit integer.

Definition at line 75 of file validation.hpp.

◆ witness_error_code

Types of errors that may occur when sentinels validate witness commitments.

Enumerator
missing_witness_program_type 

The witness did not provide a witness_program_type.

unknown_witness_program_type 

The validation system does not recognize the provided witness_program_type.

malformed 

The witness's format appears invalid.

program_mismatch 

The witness's specified program doesn't match its commitment.

invalid_public_key 

The witness's public key is invalid.

invalid_signature 

The witness's signature is invalid.

Definition at line 60 of file validation.hpp.

◆ witness_program_type

Specifies how validators should interpret the witness program.

Enumerator
p2pk 

Pay to Public Key.

Definition at line 21 of file validation.hpp.

Function Documentation

◆ check_attestations()

auto cbdc::transaction::validation::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.

Parameters
txcompact transaction to validate.
pubkeysset of public keys whose attestations will be accepted.
thresholdnumber of attestations required for a transaction to be considered valid.
Returns
true if the required number of unique attestations are attached to the compact transaction.

Definition at line 407 of file validation.cpp.

Referenced by cbdc::coordinator::controller::execute_transaction(), and cbdc::atomizer::atomizer_raft::tx_notify().

◆ check_in_out_set()

auto cbdc::transaction::validation::check_in_out_set ( const cbdc::transaction::full_tx & tx) -> std::optional< tx_error >

Definition at line 111 of file validation.cpp.

References asymmetric_values, and value_overflow.

Referenced by check_tx().

◆ check_input_count()

auto cbdc::transaction::validation::check_input_count ( const cbdc::transaction::full_tx & tx) -> std::optional< tx_error >

Definition at line 243 of file validation.cpp.

References no_inputs.

Referenced by check_tx_structure().

◆ check_input_set()

auto cbdc::transaction::validation::check_input_set ( const cbdc::transaction::full_tx & tx) -> std::optional< tx_error >

Definition at line 270 of file validation.cpp.

References duplicate.

Referenced by check_tx_structure().

◆ check_input_structure()

auto cbdc::transaction::validation::check_input_structure ( const cbdc::transaction::input & inp) -> std::optional< std::pair< input_error_code, std::optional< output_error_code > > >

Definition at line 100 of file validation.cpp.

References check_output_value(), and data_error.

Referenced by check_tx().

Here is the call graph for this function:

◆ check_output_count()

auto cbdc::transaction::validation::check_output_count ( const cbdc::transaction::full_tx & tx) -> std::optional< tx_error >

Definition at line 252 of file validation.cpp.

References no_outputs.

Referenced by check_tx_structure().

◆ check_output_value()

auto cbdc::transaction::validation::check_output_value ( const cbdc::transaction::output & out) -> std::optional< output_error_code >

Definition at line 288 of file validation.cpp.

References zero_value.

Referenced by check_input_structure(), and check_tx().

◆ check_p2pk_witness()

auto cbdc::transaction::validation::check_p2pk_witness ( const cbdc::transaction::full_tx & tx,
size_t idx ) -> std::optional< witness_error_code >

Definition at line 158 of file validation.cpp.

References check_p2pk_witness_commitment(), check_p2pk_witness_len(), and check_p2pk_witness_signature().

Referenced by check_witness().

Here is the call graph for this function:

◆ check_p2pk_witness_commitment()

auto cbdc::transaction::validation::check_p2pk_witness_commitment ( const cbdc::transaction::full_tx & tx,
size_t idx ) -> std::optional< witness_error_code >

Definition at line 190 of file validation.cpp.

References cbdc::hash_data(), and program_mismatch.

Referenced by check_p2pk_witness().

Here is the call graph for this function:

◆ check_p2pk_witness_len()

auto cbdc::transaction::validation::check_p2pk_witness_len ( const cbdc::transaction::full_tx & tx,
size_t idx ) -> std::optional< witness_error_code >

Definition at line 179 of file validation.cpp.

References malformed.

Referenced by check_p2pk_witness().

◆ check_p2pk_witness_signature()

auto cbdc::transaction::validation::check_p2pk_witness_signature ( const cbdc::transaction::full_tx & tx,
size_t idx ) -> std::optional< witness_error_code >

Definition at line 207 of file validation.cpp.

References invalid_public_key, invalid_signature, and cbdc::transaction::tx_id().

Referenced by check_p2pk_witness().

Here is the call graph for this function:

◆ check_tx()

auto cbdc::transaction::validation::check_tx ( const transaction::full_tx & tx) -> std::optional< tx_error >

Runs static validation checks on the given transaction.

Note
This function returns immediately on the first-found error.
Parameters
txtransaction to validate
Returns
null if transaction is valid, otherwise error information

Definition at line 36 of file validation.cpp.

References check_in_out_set(), check_input_structure(), check_output_value(), check_tx_structure(), and check_witness().

Referenced by cbdc::sentinel::controller::execute_transaction(), cbdc::sentinel_2pc::controller::execute_transaction(), cbdc::sentinel::controller::validate_transaction(), and cbdc::sentinel_2pc::controller::validate_transaction().

Here is the call graph for this function:

◆ check_tx_structure()

auto cbdc::transaction::validation::check_tx_structure ( const cbdc::transaction::full_tx & tx) -> std::optional< tx_error >

Definition at line 75 of file validation.cpp.

References check_input_count(), check_input_set(), check_output_count(), and check_witness_count().

Referenced by check_tx().

Here is the call graph for this function:

◆ check_witness()

auto cbdc::transaction::validation::check_witness ( const cbdc::transaction::full_tx & tx,
size_t idx ) -> std::optional< witness_error_code >

Definition at line 138 of file validation.cpp.

References check_p2pk_witness(), missing_witness_program_type, p2pk, and unknown_witness_program_type.

Referenced by check_tx().

Here is the call graph for this function:

◆ check_witness_count()

auto cbdc::transaction::validation::check_witness_count ( const cbdc::transaction::full_tx & tx) -> std::optional< tx_error >

Definition at line 261 of file validation.cpp.

References missing_witness.

Referenced by check_tx_structure().

◆ get_p2pk_witness_commitment()

◆ to_string() [1/8]

auto cbdc::transaction::validation::to_string ( cbdc::transaction::validation::input_error_code err) -> std::string

Definition at line 328 of file validation.cpp.

References data_error, and duplicate.

◆ to_string() [2/8]

auto cbdc::transaction::validation::to_string ( cbdc::transaction::validation::output_error_code err) -> std::string

Definition at line 340 of file validation.cpp.

References zero_value.

◆ to_string() [3/8]

◆ to_string() [4/8]

auto cbdc::transaction::validation::to_string ( cbdc::transaction::validation::witness_error_code err) -> std::string

◆ to_string() [5/8]

auto cbdc::transaction::validation::to_string ( const cbdc::transaction::validation::input_error & err) -> std::string

Definition at line 350 of file validation.cpp.

References to_string().

Here is the call graph for this function:

◆ to_string() [6/8]

auto cbdc::transaction::validation::to_string ( const output_error & err) -> std::string

Definition at line 390 of file validation.cpp.

References to_string().

Here is the call graph for this function:

◆ to_string() [7/8]

auto cbdc::transaction::validation::to_string ( const tx_error & err) -> std::string

Definition at line 395 of file validation.cpp.

References to_string().

Here is the call graph for this function:

◆ to_string() [8/8]

auto cbdc::transaction::validation::to_string ( const witness_error & err) -> std::string

Definition at line 385 of file validation.cpp.

References to_string().

Here is the call graph for this function: