mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 23:45:51 +00:00
enable smart escrow and change variables
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
// If you add an amendment here, then do not forget to increment `numFeatures`
|
||||
// in include/xrpl/protocol/Feature.h.
|
||||
|
||||
XRPL_FEATURE(SmartEscrow, Supported::no, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(SmartEscrow, Supported::yes, VoteBehavior::DefaultYes)
|
||||
XRPL_FIX (IncludeKeyletFields, Supported::yes, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(DynamicMPT, Supported::no, VoteBehavior::DefaultNo)
|
||||
XRPL_FIX (TokenEscrowV1, Supported::yes, VoteBehavior::DefaultNo)
|
||||
|
||||
@@ -3155,95 +3155,95 @@ struct HostFuncImpl_test : public beast::unit_test::suite
|
||||
std::memcpy(par_vec_ic, vk_bytes + 448, 384);
|
||||
|
||||
// IC[0]
|
||||
uint8_t add_buf[IC_LEN] = {0};
|
||||
std::memcpy(add_buf, par_vec_ic + 0, IC_LEN);
|
||||
uint8_t add_buf[IC_LENGTH] = {0};
|
||||
std::memcpy(add_buf, par_vec_ic + 0, IC_LENGTH);
|
||||
// Temp for mul result
|
||||
uint8_t mul_buf[IC_LEN] = {0};
|
||||
uint8_t mul_buf[IC_LENGTH] = {0};
|
||||
// Iterate public inputs in 32-byte chunks
|
||||
const size_t n_inputs = sizeof(public_bytes) / SCALAR_LEN;
|
||||
const size_t n_inputs = sizeof(public_bytes) / SCALAR_LENGTH;
|
||||
|
||||
// Linear combination to caculate acc
|
||||
for (size_t i = 0; i < n_inputs; ++i) {
|
||||
const uint8_t* input_bytes = public_bytes + i * SCALAR_LEN;
|
||||
const uint8_t* input_bytes = public_bytes + i * SCALAR_LENGTH;
|
||||
|
||||
const size_t start = IC_LEN * (i + 1);
|
||||
const size_t end = start + IC_LEN;
|
||||
const size_t start = IC_LENGTH * (i + 1);
|
||||
const size_t end = start + IC_LENGTH;
|
||||
if (end > sizeof(par_vec_ic)) {
|
||||
return;
|
||||
}
|
||||
const uint8_t* ic_bytes = par_vec_ic + start;
|
||||
|
||||
auto mulRes = hfs.bn254MulHelper(
|
||||
Slice{ic_bytes, IC_LEN},
|
||||
Slice{input_bytes, SCALAR_LEN});
|
||||
Slice{ic_bytes, IC_LENGTH},
|
||||
Slice{input_bytes, SCALAR_LENGTH});
|
||||
BEAST_EXPECT(mulRes.has_value());
|
||||
std::memcpy(mul_buf, mulRes->data(), IC_LEN);
|
||||
std::memcpy(mul_buf, mulRes->data(), IC_LENGTH);
|
||||
|
||||
auto addRes = hfs.bn254AddHelper(
|
||||
Slice{add_buf, IC_LEN},
|
||||
Slice{mul_buf, IC_LEN});
|
||||
Slice{add_buf, IC_LENGTH},
|
||||
Slice{mul_buf, IC_LENGTH});
|
||||
BEAST_EXPECT(addRes.has_value());
|
||||
std::memcpy(add_buf, addRes->data(), IC_LEN);
|
||||
std::memcpy(add_buf, addRes->data(), IC_LENGTH);
|
||||
}
|
||||
const uint8_t* vk_x_bytes = add_buf;
|
||||
|
||||
// Split proof into (a, b, c)
|
||||
const uint8_t* proof_a_bytes = proof_bytes;
|
||||
const uint8_t* proof_b_bytes = proof_bytes + G1_LEN;
|
||||
const uint8_t* proof_c_bytes = proof_bytes + G1_LEN + G2_LEN;
|
||||
const uint8_t* proof_b_bytes = proof_bytes + G1_LENGTH;
|
||||
const uint8_t* proof_c_bytes = proof_bytes + G1_LENGTH + G2_LENGTH;
|
||||
|
||||
// Negate proof.a
|
||||
uint8_t proof_a_buf[G1_LEN];
|
||||
std::memcpy(proof_a_buf, proof_a_bytes, G1_LEN);
|
||||
uint8_t neg_proof_a_bytes[G1_LEN] = {0};
|
||||
uint8_t proof_a_buf[G1_LENGTH];
|
||||
std::memcpy(proof_a_buf, proof_a_bytes, G1_LENGTH);
|
||||
uint8_t neg_proof_a_bytes[G1_LENGTH] = {0};
|
||||
{
|
||||
auto negRes = hfs.bn254NegHelper(Slice{proof_a_buf, G1_LEN});
|
||||
auto negRes = hfs.bn254NegHelper(Slice{proof_a_buf, G1_LENGTH});
|
||||
BEAST_EXPECT(negRes.has_value());
|
||||
std::memcpy(neg_proof_a_bytes, negRes->data(), G1_LEN);
|
||||
std::memcpy(neg_proof_a_bytes, negRes->data(), G1_LENGTH);
|
||||
}
|
||||
|
||||
uint8_t alpha_bytes[G1_LEN];
|
||||
uint8_t beta_bytes[G2_LEN];
|
||||
uint8_t gamma_bytes[G2_LEN];
|
||||
uint8_t delta_bytes[G2_LEN];
|
||||
uint8_t alpha_bytes[G1_LENGTH];
|
||||
uint8_t beta_bytes[G2_LENGTH];
|
||||
uint8_t gamma_bytes[G2_LENGTH];
|
||||
uint8_t delta_bytes[G2_LENGTH];
|
||||
|
||||
// Extract alpha, beta, gamma, delta
|
||||
std::memcpy(alpha_bytes, vk_bytes, G1_LEN);
|
||||
std::memcpy(beta_bytes, vk_bytes + G1_LEN, G2_LEN);
|
||||
std::memcpy(gamma_bytes, vk_bytes + G1_LEN + G2_LEN, G2_LEN);
|
||||
std::memcpy(delta_bytes, vk_bytes + G1_LEN + 2 * G2_LEN, G2_LEN);
|
||||
std::memcpy(alpha_bytes, vk_bytes, G1_LENGTH);
|
||||
std::memcpy(beta_bytes, vk_bytes + G1_LENGTH, G2_LENGTH);
|
||||
std::memcpy(gamma_bytes, vk_bytes + G1_LENGTH + G2_LENGTH, G2_LENGTH);
|
||||
std::memcpy(delta_bytes, vk_bytes + G1_LENGTH + 2 * G2_LENGTH, G2_LENGTH);
|
||||
|
||||
// Prepare input for pairing check
|
||||
// input_pairs = [(−a, b), (alpha, beta), (vk_x, gamma), (c, delta)]
|
||||
uint8_t input_pairs[GROTH16_PAIR_LEN];
|
||||
uint8_t input_pairs[GROTH16_PAIR_LENGTH];
|
||||
size_t offset = 0;
|
||||
|
||||
// 1. (-a, b)
|
||||
std::memcpy(input_pairs + offset, neg_proof_a_bytes, G1_LEN);
|
||||
offset += G1_LEN;
|
||||
std::memcpy(input_pairs + offset, proof_b_bytes, G2_LEN);
|
||||
offset += G2_LEN;
|
||||
std::memcpy(input_pairs + offset, neg_proof_a_bytes, G1_LENGTH);
|
||||
offset += G1_LENGTH;
|
||||
std::memcpy(input_pairs + offset, proof_b_bytes, G2_LENGTH);
|
||||
offset += G2_LENGTH;
|
||||
|
||||
// 2. (alpha, beta)
|
||||
std::memcpy(input_pairs + offset, alpha_bytes, G1_LEN);
|
||||
offset += G1_LEN;
|
||||
std::memcpy(input_pairs + offset, beta_bytes, G2_LEN);
|
||||
offset += G2_LEN;
|
||||
std::memcpy(input_pairs + offset, alpha_bytes, G1_LENGTH);
|
||||
offset += G1_LENGTH;
|
||||
std::memcpy(input_pairs + offset, beta_bytes, G2_LENGTH);
|
||||
offset += G2_LENGTH;
|
||||
|
||||
// 3. (vk_x, gamma)
|
||||
std::memcpy(input_pairs + offset, vk_x_bytes, G1_LEN);
|
||||
offset += G1_LEN;
|
||||
std::memcpy(input_pairs + offset, gamma_bytes, G2_LEN);
|
||||
offset += G2_LEN;
|
||||
std::memcpy(input_pairs + offset, vk_x_bytes, G1_LENGTH);
|
||||
offset += G1_LENGTH;
|
||||
std::memcpy(input_pairs + offset, gamma_bytes, G2_LENGTH);
|
||||
offset += G2_LENGTH;
|
||||
|
||||
// 4. (c, delta)
|
||||
std::memcpy(input_pairs + offset, proof_c_bytes, G1_LEN);
|
||||
offset += G1_LEN;
|
||||
std::memcpy(input_pairs + offset, delta_bytes, G2_LEN);
|
||||
std::memcpy(input_pairs + offset, proof_c_bytes, G1_LENGTH);
|
||||
offset += G1_LENGTH;
|
||||
std::memcpy(input_pairs + offset, delta_bytes, G2_LENGTH);
|
||||
|
||||
size_t num = 1;
|
||||
for (size_t i = 0; i < num; ++i) {
|
||||
auto result = hfs.bn254PairingHelper(Slice{input_pairs, GROTH16_PAIR_LEN});
|
||||
auto result = hfs.bn254PairingHelper(Slice{input_pairs, GROTH16_PAIR_LENGTH});
|
||||
BEAST_EXPECT(result) && BEAST_EXPECT(*result == 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -586,7 +586,7 @@ public:
|
||||
libff::alt_bn128_pp::init_public_params();
|
||||
|
||||
try{
|
||||
if (p1_uncompressed_be64.size() != G1_LEN || scalar_uncompressed_be32.size() != SCALAR_LEN)
|
||||
if (p1_uncompressed_be64.size() != G1_LENGTH || scalar_uncompressed_be32.size() != SCALAR_LENGTH)
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
libff::alt_bn128_G1 p1;
|
||||
@@ -599,7 +599,7 @@ public:
|
||||
|
||||
libff::alt_bn128_G1 result = s * p1;
|
||||
|
||||
Bytes out(G1_LEN);
|
||||
Bytes out(G1_LENGTH);
|
||||
if (!g1_to_uncompressed_be(result, out.data()))
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
|
||||
@@ -620,7 +620,7 @@ public:
|
||||
libff::alt_bn128_pp::init_public_params();
|
||||
|
||||
try{
|
||||
if (p1_uncompressed_be64.size() != G1_LEN || p2_uncompressed_be64.size() != G1_LEN)
|
||||
if (p1_uncompressed_be64.size() != G1_LENGTH || p2_uncompressed_be64.size() != G1_LENGTH)
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
libff::alt_bn128_G1 p1, p2;
|
||||
@@ -630,7 +630,7 @@ public:
|
||||
|
||||
libff::alt_bn128_G1 result = p1 + p2;
|
||||
|
||||
Bytes out(G1_LEN);
|
||||
Bytes out(G1_LENGTH);
|
||||
if (!g1_to_uncompressed_be(result, out.data()))
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
|
||||
@@ -651,7 +651,7 @@ public:
|
||||
libff::alt_bn128_pp::init_public_params();
|
||||
|
||||
try{
|
||||
if (p1_uncompressed_be64.size() != G1_LEN)
|
||||
if (p1_uncompressed_be64.size() != G1_LENGTH)
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
libff::alt_bn128_G1 p1;
|
||||
@@ -660,7 +660,7 @@ public:
|
||||
|
||||
libff::alt_bn128_G1 result = -p1;
|
||||
|
||||
Bytes out(G1_LEN);
|
||||
Bytes out(G1_LENGTH);
|
||||
if (!g1_to_uncompressed_be(result, out.data()))
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
|
||||
@@ -685,14 +685,14 @@ public:
|
||||
libff::alt_bn128_pp::init_public_params();
|
||||
|
||||
try{
|
||||
if (pairs.size() % PAIR_LEN != 0)
|
||||
if (pairs.size() % PAIR_LENGTH != 0)
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
libff::alt_bn128_Fq12 acc = libff::alt_bn128_Fq12::one();
|
||||
size_t const npairs = pairs.size() / PAIR_LEN;
|
||||
size_t const npairs = pairs.size() / PAIR_LENGTH;
|
||||
|
||||
for (std::size_t i = 0; i < npairs; ++i) {
|
||||
auto const* base = pairs.data() + i * PAIR_LEN;
|
||||
auto const* base = pairs.data() + i * PAIR_LENGTH;
|
||||
|
||||
libff::alt_bn128_G1 P;
|
||||
libff::alt_bn128_G2 Q;
|
||||
@@ -700,7 +700,7 @@ public:
|
||||
if (!g1_from_uncompressed_be(base + 0, P))
|
||||
return Unexpected(HostFunctionError::DECODING);
|
||||
|
||||
if (!g2_from_uncompressed_be(base + G1_LEN, Q))
|
||||
if (!g2_from_uncompressed_be(base + G1_LENGTH, Q))
|
||||
return Unexpected(HostFunctionError::DECODING);
|
||||
|
||||
if (P.is_zero() || Q.is_zero())
|
||||
|
||||
@@ -27,19 +27,19 @@ namespace ripple {
|
||||
/**
|
||||
* Fixed sizes for BN254 encodings and pair packing.
|
||||
*
|
||||
* - G1_LEN: uncompressed G1 (x||y), big-endian, 32B each (64B total)
|
||||
* - G2_LEN: uncompressed G2 (x_c1||x_c0||y_c1||y_c0), big-endian (128B)
|
||||
* - IC_LEN: generic 64B element container (e.g., G1 coord pair)
|
||||
* - SCALAR_LEN: scalar field element in 32B big-endian
|
||||
* - PAIR_LEN: bytes for one (G1,G2) uncompressed pair
|
||||
* - GROTH16_PAIR_LEN: space for 4 pairs (common in multi-pair checks)
|
||||
* - G1_LENGTH: uncompressed G1 (x||y), big-endian, 32B each (64B total)
|
||||
* - G2_LENGTH: uncompressed G2 (x_c1||x_c0||y_c1||y_c0), big-endian (128B)
|
||||
* - IC_LENGTH: generic 64B element container (e.g., G1 coord pair)
|
||||
* - SCALAR_LENGTH: scalar field element in 32B big-endian
|
||||
* - PAIR_LENGTH: bytes for one (G1,G2) uncompressed pair
|
||||
* - GROTH16_PAIR_LENGTH: space for 4 pairs (common in multi-pair checks)
|
||||
*/
|
||||
constexpr std::size_t G1_LEN = 64;
|
||||
constexpr std::size_t G2_LEN = 128;
|
||||
constexpr std::size_t IC_LEN = 64;
|
||||
constexpr std::size_t SCALAR_LEN = 32;
|
||||
constexpr std::size_t PAIR_LEN = G1_LEN + G2_LEN;
|
||||
constexpr std::size_t GROTH16_PAIR_LEN = 4 * (G1_LEN + G2_LEN);
|
||||
constexpr std::size_t G1_LENGTH = 64;
|
||||
constexpr std::size_t G2_LENGTH = 128;
|
||||
constexpr std::size_t IC_LENGTH = 64;
|
||||
constexpr std::size_t SCALAR_LENGTH = 32;
|
||||
constexpr std::size_t PAIR_LENGTH = G1_LENGTH + G2_LENGTH;
|
||||
constexpr std::size_t GROTH16_PAIR_LENGTH = 4 * (G1_LENGTH + G2_LENGTH);
|
||||
|
||||
/**
|
||||
* Reverse a 32-byte big-endian limb into little-endian order.
|
||||
|
||||
@@ -912,7 +912,7 @@ WasmHostFunctionsImpl::bn254AddHelper(
|
||||
ensure_bn254_init();
|
||||
|
||||
try{
|
||||
if (p1_uncompressed_be64.size() != G1_LEN || p2_uncompressed_be64.size() != G1_LEN)
|
||||
if (p1_uncompressed_be64.size() != G1_LENGTH || p2_uncompressed_be64.size() != G1_LENGTH)
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
libff::alt_bn128_G1 p1, p2;
|
||||
@@ -942,7 +942,7 @@ WasmHostFunctionsImpl::bn254MulHelper(
|
||||
ensure_bn254_init();
|
||||
|
||||
try{
|
||||
if (p1_uncompressed_be64.size() != G1_LEN || scalar_uncompressed_be32.size() != SCALAR_LEN)
|
||||
if (p1_uncompressed_be64.size() != G1_LENGTH || scalar_uncompressed_be32.size() != SCALAR_LENGTH)
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
libff::alt_bn128_G1 p1;
|
||||
@@ -955,7 +955,7 @@ WasmHostFunctionsImpl::bn254MulHelper(
|
||||
|
||||
libff::alt_bn128_G1 result = s * p1;
|
||||
|
||||
Bytes out(G1_LEN);
|
||||
Bytes out(G1_LENGTH);
|
||||
if (!g1_to_uncompressed_be(result, out.data()))
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
|
||||
@@ -974,7 +974,7 @@ WasmHostFunctionsImpl::bn254NegHelper(
|
||||
ensure_bn254_init();
|
||||
|
||||
try{
|
||||
if (p1_uncompressed_be64.size() != G1_LEN)
|
||||
if (p1_uncompressed_be64.size() != G1_LENGTH)
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
libff::alt_bn128_G1 p1;
|
||||
@@ -983,7 +983,7 @@ WasmHostFunctionsImpl::bn254NegHelper(
|
||||
|
||||
libff::alt_bn128_G1 result = -p1;
|
||||
|
||||
Bytes out(G1_LEN);
|
||||
Bytes out(G1_LENGTH);
|
||||
if (!g1_to_uncompressed_be(result, out.data()))
|
||||
return Unexpected(HostFunctionError::INTERNAL);
|
||||
|
||||
@@ -1005,14 +1005,14 @@ WasmHostFunctionsImpl::bn254PairingHelper(
|
||||
ensure_bn254_init();
|
||||
|
||||
try{
|
||||
if (pairs.size() % PAIR_LEN != 0)
|
||||
if (pairs.size() % PAIR_LENGTH != 0)
|
||||
return Unexpected(HostFunctionError::INVALID_PARAMS);
|
||||
|
||||
libff::alt_bn128_Fq12 acc = libff::alt_bn128_Fq12::one();
|
||||
size_t const npairs = pairs.size() / PAIR_LEN;
|
||||
size_t const npairs = pairs.size() / PAIR_LENGTH;
|
||||
|
||||
for (std::size_t i = 0; i < npairs; ++i) {
|
||||
auto const* base = pairs.data() + i * PAIR_LEN;
|
||||
auto const* base = pairs.data() + i * PAIR_LENGTH;
|
||||
|
||||
libff::alt_bn128_G1 P;
|
||||
libff::alt_bn128_G2 Q;
|
||||
@@ -1020,7 +1020,7 @@ WasmHostFunctionsImpl::bn254PairingHelper(
|
||||
if (!g1_from_uncompressed_be(base + 0, P))
|
||||
return Unexpected(HostFunctionError::DECODING);
|
||||
|
||||
if (!g2_from_uncompressed_be(base + G1_LEN, Q))
|
||||
if (!g2_from_uncompressed_be(base + G1_LENGTH, Q))
|
||||
return Unexpected(HostFunctionError::DECODING);
|
||||
|
||||
if (P.is_zero() || Q.is_zero())
|
||||
|
||||
Reference in New Issue
Block a user