circuits/TransactionValidator.cpp¶
Functions¶
| Name | |
|---|---|
| pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type | GeneratePointFromSeedAndTotp(pallas::scalar_field_type::value_type seed, pallas::scalar_field_type::value_type provided_totp, typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type generator) Generates a point from the seed, TOTP and generator. |
| bool | ValidateTransactionValues(uint64_t balance, uint64_t amount, pallas::scalar_field_type::value_type balance_scalar, pallas::scalar_field_type::value_type amount_scalar, typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type balance_commitment, typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type amount_commitment, typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type expected_new_balance_commitment, typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type generator, std::array< pallas::scalar_field_type::value_type, MAX_RANGES > ranges) Validates the transaction values. |
Detailed Description¶
Date: 2025-01-29 Henrique A. Klein ([email protected])
Functions Documentation¶
function GeneratePointFromSeedAndTotp¶
pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type GeneratePointFromSeedAndTotp(
pallas::scalar_field_type::value_type seed,
pallas::scalar_field_type::value_type provided_totp,
typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type generator
)
Generates a point from the seed, TOTP and generator.
Parameters:
- seed The seed to be used
- provided_totp The TOTP to be used
- generator The generator point to be used
Return: A point that represents the mapping of TOTP and seed combined
function ValidateTransactionValues¶
bool ValidateTransactionValues(
uint64_t balance,
uint64_t amount,
pallas::scalar_field_type::value_type balance_scalar,
pallas::scalar_field_type::value_type amount_scalar,
typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type balance_commitment,
typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type amount_commitment,
typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type expected_new_balance_commitment,
typename pallas::template g1_type< nil::crypto3::algebra::curves::coordinates::affine >::value_type generator,
std::array< pallas::scalar_field_type::value_type, MAX_RANGES > ranges
)
Validates the transaction values.
Parameters:
- balance The raw balance in integer form
- amount The raw amount in integer form
- balance_scalar The raw balance in scalar form
- amount_scalar The raw amount in scalar form
- balance_commitment The balance multiplied by a generator (mapped to a curve)
- amount_commitment The amount multiplied by a generator (mapped to a curve)
- expected_new_balance_commitment The new balance multiplied by a generator (mapped to a curve)
- generator The generator that is used to map values to the curve
- ranges Array of possible ranges of the amount
Return: True if transaction values are valid, false otherwise
Source code¶
#include "TransactionValidator.hpp"
using namespace nil::crypto3::algebra::curves;
// Function to create a point on the curve from the seed and TOTP
typename pallas::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type GeneratePointFromSeedAndTotp(
pallas::scalar_field_type::value_type seed, // The base seed for TOTP as a field element
pallas::scalar_field_type::value_type provided_totp, // Provided TOTP to validate
typename pallas::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type generator // The curve generator
)
{
// Create a point on the curve using the seed
typename pallas::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type point = seed * generator; // Seed as a point
// Use provided TOTP directly to create an offset
typename pallas::scalar_field_type::value_type totp_offset = provided_totp; // Use by value
// Adjust the point with TOTP offset
point = point + ( totp_offset * generator ); // Add TOTP offset to the point
return point; // Return the new point
}
bool ValidateTransactionValues(
uint64_t balance, //
uint64_t amount, //
pallas::scalar_field_type::value_type balance_scalar, //
pallas::scalar_field_type::value_type amount_scalar, //
typename pallas::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type balance_commitment, //
typename pallas::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type amount_commitment, //
typename pallas::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type expected_new_balance_commitment, //
typename pallas::template g1_type<nil::crypto3::algebra::curves::coordinates::affine>::value_type generator, //
std::array<pallas::scalar_field_type::value_type, MAX_RANGES> ranges // Public parameter for upper bounds
)
{
//TODO Arithmetic operations are not supported with scalar_field_type and curve multiplication is not supported with int
// Initialize low bounds
//typename pallas::scalar_field_type::value_type lowBounds = 0;
// Determine the transfer amount range
//for ( uint64_t i = 0; i < MAX_RANGES; i++ )
//{
// if ((amount_scalar >= lowBounds) && (amount_scalar < ranges[i])) {
// break; // Exit loop once the range is found
// }
//lowBounds = ranges[i]; // Update low bounds for the next range check
//}
//typename pallas::template g1_type<coordinates::affine>::value_type generator( X_generator, Y_generator );
//The
auto calculated_balance_point = balance_scalar * generator;
auto calculated_amount_point = amount_scalar * generator;
if ( balance >= amount )
{
//TODO - Circuits don't allow for subtraction of scalars or point multiplication for integers.
//auto new_balance = balance_scalar - amount_scalar;
// Verify that the commitments match the expected values
bool valid_balance_commitment = ( calculated_balance_point == balance_commitment );
bool valid_amount_commitment = ( calculated_amount_point == amount_commitment );
//bool valid_new_balance_commitment = ( expected_new_balance_commitment == ( generator * new_balance ) );
if ( valid_balance_commitment && valid_amount_commitment /* && valid_new_balance_commitment*/ )
{
return true;
}
}
return false;
}
Updated on 2026-04-13 at 23:22:46 -0700