What changed, and why it matters
This commit adds the verification side of a new Monero privacy feature called FCMP++ (Full Chain Membership Proofs). It is not a fix for a known bug or vulnerability; it is new code that lets the network check FCMP++ proofs in transactions. The change also updates a Rust dependency and adds tests and performance tooling. There is no evidence in the commit message or diff that this is a security patch or that it addresses any disclosed vulnerability.
Treat as routine feature development. Review the new verification code for correctness of the cryptographic checks, FFI memory safety, and batch-verifier thread safety before relying on it in production. No urgent security patch action is indicated by the supplied materials.
Security signals we found
New cryptographic verification path added (FCMP++ proof verification)
Dependency update for monero-oxide Rust crates
New constants limiting proof inputs/outputs/layers to cap deserialization size
Extensive unit tests including negative tests for invalid proofs and batch verification
No mention of CVE, security bug, vulnerability, or fix in commit title/message
Evidence from the diff
The merge commit introduces FCMP++ proof verification tooling: a Rust/C FFI layer (fcmp_pp_rust), C++ wrappers (fcmp_pp/verify.cpp/h), batch verification in ringct (rctSigs.cpp), serialization helpers, and unit/performance tests. It bumps the monero-oxide Rust dependency from rev 31c26d96 to 77788c36 and adjusts generator source comments and Guix hashes accordingly. Constants FCMP_PLUS_PLUS_MAX_INPUTS (128), MAX_OUTPUTS (16), and MAX_LAYERS (12) are added. The code is defensive (length checks, null checks, asserts) and appears to be feature development rather than a bugfix.
Changed components
src/fcmp_pp/verify.cppsrc/fcmp_pp/verify.hsrc/fcmp_pp/fcmp_pp_rust/src/lib.rssrc/fcmp_pp/fcmp_pp_rust/fcmp++.hsrc/fcmp_pp/fcmp_pp_types.cppsrc/fcmp_pp/fcmp_pp_types.hsrc/fcmp_pp/curve_trees.cppsrc/fcmp_pp/curve_trees.hsrc/ringct/rctSigs.cppsrc/ringct/rctSigs.hsrc/cryptonote_config.hsrc/crypto/generators.cppcontrib/guix/guix-buildcontrib/guix/rust/config.tomlsrc/fcmp_pp/fcmp_pp_rust/Cargo.tomlsrc/fcmp_pp/fcmp_pp_rust/Cargo.lockInspect captured patch +1536 / −26
### contrib/guix/guix-build
@@ -275,7 +275,7 @@ mkdir -p "$LOGDIR_BASE"
# RUST_DEPS_HASH with the hash reported below, and update
# contrib/guix/rust/config.toml if the set of git sources changed
RUST_DEPS_VERSION=0
-RUST_DEPS_HASH="xcxpbdn8wv1gqy1iwgj3x8ddl7hz595s"
+RUST_DEPS_HASH="nfzkzqaxj9k93wld6s57i8v4j0sdmla7"
RUST_DEPS_ARCHIVE="rust_deps-${RUST_DEPS_VERSION}.tar.gz"
RUST_DEPS_STORE_ITEM="/gnu/store/${RUST_DEPS_HASH}-${RUST_DEPS_ARCHIVE}"
if [ ! -f "${RUST_DEPS_STORE_ITEM}" ]; then
### contrib/guix/rust/config.toml
@@ -6,9 +6,9 @@ git = "https://github.com/kayabaNerve/crypto-bigint"
branch = "c-repr"
replace-with = "vendored-sources"
-[source."git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93"]
+[source."git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01"]
git = "https://github.com/monero-oxide/monero-oxide"
-rev = "31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+rev = "77788c368145127f2dde2ac3e2ddce919f3ddd01"
replace-with = "vendored-sources"
[source.vendored-sources]
### src/crypto/generators.cpp
@@ -69,15 +69,15 @@ constexpr public_key G = bytes_to<public_key>({ 0x58, 0x66, 0x66, 0x66, 0x66, 0x
constexpr public_key H = bytes_to<public_key>({ 0x8b, 0x65, 0x59, 0x70, 0x15, 0x37, 0x99, 0xaf, 0x2a, 0xea, 0xdc, 0x9f, 0xf1,
0xad, 0xd0, 0xea, 0x6c, 0x72, 0x51, 0xd5, 0x41, 0x54, 0xcf, 0xa9, 0x2c, 0x17, 0x3a, 0x0d, 0xd3, 0x9c, 0x1f, 0x94 });
//FCMP++ generator T: unbiased_hash_to_ec(Keccak256("Monero Generator T"))
-//Source: https://github.com/monero-oxide/monero-oxide/blob/31c26d96eaadbba910ffe3613ad8b4cf9c598a93/monero-oxide/ed25519/src/compressed_point.rs#L74-L79
+//Source: https://github.com/monero-oxide/monero-oxide/blob/77788c368145127f2dde2ac3e2ddce919f3ddd01/monero-oxide/ed25519/src/compressed_point.rs#L74-L79
constexpr public_key T = bytes_to<public_key>({ 220, 66, 225, 211, 48, 123, 45, 75, 59, 2, 114, 154, 190, 87, 126, 35,
29, 121, 71, 129, 65, 203, 91, 49, 12, 169, 250, 110, 18, 118, 22, 163});
//FCMP++ generator U: unbiased_hash_to_ec(Keccak256("Monero FCMP++ Generator U"))
-//Source: https://github.com/monero-oxide/monero-oxide/blob/31c26d96eaadbba910ffe3613ad8b4cf9c598a93/monero-oxide/ringct/fcmp%2B%2B/generators/src/lib.rs#L16-L24
+//Source: https://github.com/monero-oxide/monero-oxide/blob/77788c368145127f2dde2ac3e2ddce919f3ddd01/monero-oxide/ringct/fcmp%2B%2B/generators/src/lib.rs#L16-L24
constexpr public_key U = bytes_to<public_key>({ 138, 148, 142, 40, 84, 7, 58, 160, 188, 184, 47, 134, 60, 128, 134, 91,
92, 201, 190, 23, 151, 35, 252, 28, 191, 28, 37, 184, 133, 89, 126, 84});
//FCMP++ generator V: unbiased_hash_to_ec(Keccak256("Monero FCMP++ Generator V"))
-//Source: https://github.com/monero-oxide/monero-oxide/blob/31c26d96eaadbba910ffe3613ad8b4cf9c598a93/monero-oxide/ringct/fcmp%2B%2B/generators/src/lib.rs#L26-L34
+//Source: https://github.com/monero-oxide/monero-oxide/blob/77788c368145127f2dde2ac3e2ddce919f3ddd01/monero-oxide/ringct/fcmp%2B%2B/generators/src/lib.rs#L26-L34
constexpr public_key V = bytes_to<public_key>({26, 66, 53, 9, 247, 103, 94, 145, 32, 17, 209, 75, 86, 16, 168, 87, 221,
213, 136, 115, 52, 19, 181, 21, 224, 3, 188, 64, 85, 133, 91, 241,});
static ge_p3 G_p3;
### src/cryptonote_config.h
@@ -210,6 +210,13 @@ static_assert(CURRENCY_PROTOCOL_MAX_OBJECT_REQUEST_COUNT >= BLOCKS_SYNCHRONIZING
#define BULLETPROOF_MAX_OUTPUTS 16
#define BULLETPROOF_PLUS_MAX_OUTPUTS 16
+#define FCMP_PLUS_PLUS_MAX_INPUTS 128
+#define FCMP_PLUS_PLUS_MAX_OUTPUTS 16
+
+// Limiting n layers ensures proof size is capped to a reasonable level when de-serializing a proof.
+// 12 layers means the tree can support over 100 quadrillion outputs
+#define FCMP_PLUS_PLUS_MAX_LAYERS 12
+
#define CRYPTONOTE_PRUNING_STRIPE_SIZE 4096 // the smaller, the smoother the increase
#define CRYPTONOTE_PRUNING_LOG_STRIPES 3 // the higher, the more space saved
#define CRYPTONOTE_PRUNING_TIP_BLOCKS 5500 // the smaller, the more space saved
### src/fcmp_pp/CMakeLists.txt
@@ -30,7 +30,8 @@ set(fcmp_pp_sources
curve_trees.cpp
fcmp_pp_crypto.cpp
fcmp_pp_types.cpp
- tower_cycle.cpp)
+ tower_cycle.cpp
+ verify.cpp)
monero_find_all_headers(fcmp_pp_headers "${CMAKE_CURRENT_SOURCE_DIR}")
### src/fcmp_pp/curve_trees.cpp
@@ -1168,5 +1168,18 @@ CompressedTreeExtension CurveTrees<C1, C2>::compress_tree_extension(
template CompressedTreeExtension CurveTrees<Selene, Helios>::compress_tree_extension(
typename CurveTrees<Selene, Helios>::TreeExtension &&tree_ext) const;
//----------------------------------------------------------------------------------------------------------------------
+template<>
+TreeRootShared CurveTrees<Selene, Helios>::get_tree_root_from_bytes(const std::size_t n_layers,
+ const crypto::ec_point &tree_root) const
+{
+ if (n_layers == 0)
+ return nullptr;
+
+ if ((n_layers % 2) == 0)
+ return fcmp_pp::helios_tree_root(m_c2->from_bytes(tree_root));
+ else
+ return fcmp_pp::selene_tree_root(m_c1->from_bytes(tree_root));
+}
+//----------------------------------------------------------------------------------------------------------------------
} //namespace curve_trees
} //namespace fcmp_pp
### src/fcmp_pp/curve_trees.h
@@ -177,6 +177,10 @@ class CurveTrees
// Compress all the points in the tree extension
CompressedTreeExtension compress_tree_extension(TreeExtension &&tree_extension) const;
+
+ // Get the decompressed tree root from compressed encoding
+ TreeRootShared get_tree_root_from_bytes(const std::size_t n_layers, const crypto::ec_point &tree_root) const;
+
private:
// Multithreaded helper function to convert valid outputs to leaf tuples ready for insertion to the tree & db
void outputs_to_leaves(std::vector<UnifiedOutput> &&new_outputs,
@@ -224,7 +228,7 @@ using Selene = tower_cycle::Selene;
using Helios = tower_cycle::Helios;
using CurveTreesV1 = CurveTrees<Selene, Helios>;
-// https://github.com/monero-oxide/monero-oxide/blob/31c26d96eaadbba910ffe3613ad8b4cf9c598a93/crypto/fcmps/src/lib.rs#L54-L59
+// https://github.com/monero-oxide/monero-oxide/blob/77788c368145127f2dde2ac3e2ddce919f3ddd01/crypto/fcmps/src/lib.rs#L54-L59
const std::size_t SELENE_CHUNK_WIDTH = 38;
const std::size_t HELIOS_CHUNK_WIDTH = 18;
### src/fcmp_pp/fcmp_pp_rust/Cargo.lock
@@ -206,7 +206,7 @@ dependencies = [
[[package]]
name = "ec-divisors"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"crypto-bigint",
"dalek-ff-group 0.5.0",
@@ -260,9 +260,12 @@ dependencies = [
"dalek-ff-group 0.5.0",
"ec-divisors",
"full-chain-membership-proofs",
+ "generalized-bulletproofs",
"helioselene",
"monero-fcmp-plus-plus",
"monero-fcmp-plus-plus-generators",
+ "multiexp",
+ "rand_core",
]
[[package]]
@@ -305,7 +308,7 @@ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
[[package]]
name = "full-chain-membership-proofs"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"blake2",
"ciphersuite",
@@ -331,7 +334,7 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]]
name = "generalized-bulletproofs"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"blake2",
"ciphersuite",
@@ -348,7 +351,7 @@ dependencies = [
[[package]]
name = "generalized-bulletproofs-circuit-abstraction"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"ciphersuite",
"generalized-bulletproofs",
@@ -359,7 +362,7 @@ dependencies = [
[[package]]
name = "generalized-bulletproofs-ec-gadgets"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"ciphersuite",
"generalized-bulletproofs-circuit-abstraction",
@@ -421,7 +424,7 @@ dependencies = [
[[package]]
name = "helioselene"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"blake2",
"ciphersuite",
@@ -495,7 +498,7 @@ dependencies = [
[[package]]
name = "monero-ed25519"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"blake2",
"crypto-bigint",
@@ -512,7 +515,7 @@ dependencies = [
[[package]]
name = "monero-fcmp-plus-plus"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"blake2",
"ciphersuite",
@@ -538,7 +541,7 @@ dependencies = [
[[package]]
name = "monero-fcmp-plus-plus-generators"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"ciphersuite",
"full-chain-membership-proofs",
@@ -553,15 +556,15 @@ dependencies = [
[[package]]
name = "monero-io"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"std-shims",
]
[[package]]
name = "monero-primitives"
version = "0.1.0"
-source = "git+https://github.com/monero-oxide/monero-oxide?rev=31c26d96eaadbba910ffe3613ad8b4cf9c598a93#31c26d96eaadbba910ffe3613ad8b4cf9c598a93"
+source = "git+https://github.com/monero-oxide/monero-oxide?rev=77788c368145127f2dde2ac3e2ddce919f3ddd01#77788c368145127f2dde2ac3e2ddce919f3ddd01"
dependencies = [
"blake2",
"crypto-bigint",
### src/fcmp_pp/fcmp_pp_rust/Cargo.toml
@@ -8,15 +8,19 @@ name = "fcmp_pp_rust"
crate-type = ["staticlib"]
[dependencies]
+rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
+
+multiexp = { version = "0.5", default-features = false, features = ["batch"] }
ciphersuite = { version = "0.4.2", features = ["ed25519"] }
dalek-ff-group = "0.5.0"
-helioselene = { git = "https://github.com/monero-oxide/monero-oxide", rev = "31c26d96eaadbba910ffe3613ad8b4cf9c598a93" }
+helioselene = { git = "https://github.com/monero-oxide/monero-oxide", rev = "77788c368145127f2dde2ac3e2ddce919f3ddd01" }
-ec-divisors = { git = "https://github.com/monero-oxide/monero-oxide", rev = "31c26d96eaadbba910ffe3613ad8b4cf9c598a93", features = ["ed25519"] }
-full-chain-membership-proofs = { git = "https://github.com/monero-oxide/monero-oxide", rev = "31c26d96eaadbba910ffe3613ad8b4cf9c598a93" }
+generalized-bulletproofs = { git = "https://github.com/monero-oxide/monero-oxide", rev = "77788c368145127f2dde2ac3e2ddce919f3ddd01" }
+ec-divisors = { git = "https://github.com/monero-oxide/monero-oxide", rev = "77788c368145127f2dde2ac3e2ddce919f3ddd01", features = ["ed25519"] }
+full-chain-membership-proofs = { git = "https://github.com/monero-oxide/monero-oxide", rev = "77788c368145127f2dde2ac3e2ddce919f3ddd01" }
-monero-fcmp-plus-plus-generators = { git = "https://github.com/monero-oxide/monero-oxide", rev = "31c26d96eaadbba910ffe3613ad8b4cf9c598a93" }
-monero-fcmp-plus-plus = { git = "https://github.com/monero-oxide/monero-oxide", rev = "31c26d96eaadbba910ffe3613ad8b4cf9c598a93" }
+monero-fcmp-plus-plus-generators = { git = "https://github.com/monero-oxide/monero-oxide", rev = "77788c368145127f2dde2ac3e2ddce919f3ddd01" }
+monero-fcmp-plus-plus = { git = "https://github.com/monero-oxide/monero-oxide", rev = "77788c368145127f2dde2ac3e2ddce919f3ddd01" }
[patch.crates-io]
crypto-bigint = { git = "https://github.com/kayabaNerve/crypto-bigint", branch = "c-repr" }
### src/fcmp_pp/fcmp_pp_rust/fcmp++.h
@@ -37,8 +37,12 @@
#endif
#include <stdalign.h>
+#include <stdbool.h>
#include <stdint.h>
+// https://github.com/monero-oxide/monero-oxide/blob/77788c368145127f2dde2ac3e2ddce919f3ddd01/monero-oxide/ringct/fcmp%2B%2B/src/lib.rs#L188-L189
+#define FCMP_PP_SAL_PROOF_SIZE_V1 (12*32)
+#define FCMP_PP_INPUT_TUPLE_SIZE_V1 (3*32)
// ----- deps C bindings -----
@@ -107,6 +111,23 @@ FFI_STATIC_ASSERT(sizeof(struct SeleneScalarSlice) == sizeof(struct SeleneScalar
FFI_STATIC_ASSERT(alignof(struct SeleneScalarSlice) == sizeof(uintptr_t),
"SeleneScalarSlice FFI type unexpected alignment");
+struct ObjectSlice
+{
+ const uint8_t * const *buf;
+ uintptr_t len;
+};
+
+// Tiny types that are expected to be a Rust Box of the underlying object, allocated on the Rust side.
+// These must be destroyed manually on the Rust side of the boundary.
+struct TreeRootUnsafe;
+
+struct FcmpPpVerifyInputUnsafe;
+struct FcmpPpVerifyInputSliceUnsafe
+{
+ const struct FcmpPpVerifyInputUnsafe * const *buf;
+ uintptr_t len;
+};
+
// ----- End deps C bindings -----
#ifdef __cplusplus
@@ -127,6 +148,11 @@ struct HeliosScalar helios_zero_scalar(void);
struct SeleneScalar selene_zero_scalar(void);
+int selene_tree_root(struct SelenePoint selene_point, struct TreeRootUnsafe **tree_root_out);
+int helios_tree_root(struct HeliosPoint helios_point, struct TreeRootUnsafe **tree_root_out);
+
+void destroy_tree_root(struct TreeRootUnsafe *tree_root);
+
void helios_scalar_to_bytes(const struct HeliosScalar *helios_scalar, uint8_t bytes_out[32]);
void selene_scalar_to_bytes(const struct SeleneScalar *selene_scalar, uint8_t bytes_out[32]);
@@ -151,6 +177,25 @@ int hash_grow_selene(struct SelenePoint existing_hash,
struct SeleneScalarSlice new_children,
struct SelenePoint *hash_out);
+uintptr_t membership_proof_size(uintptr_t n_inputs, uintptr_t n_tree_layers);
+
+uintptr_t fcmp_pp_proof_size(uintptr_t n_inputs, uintptr_t n_tree_layers);
+
+int fcmp_pp_verify_input_new(const uint8_t *signable_tx_hash,
+ const uint8_t *fcmp_pp_proof,
+ uintptr_t fcmp_pp_proof_len,
+ uintptr_t n_tree_layers,
+ const struct TreeRootUnsafe *tree_root,
+ struct ObjectSlice pseudo_outs,
+ struct ObjectSlice key_images,
+ struct FcmpPpVerifyInputUnsafe **fcmp_pp_verify_input_out);
+
+void destroy_fcmp_pp_verify_input(struct FcmpPpVerifyInputUnsafe *fcmp_pp_verify_input);
+
+uintptr_t fcmp_pp_n_inputs(const struct FcmpPpVerifyInputUnsafe *fcmp_pp_verify_input);
+
+bool fcmp_pp_verify(const struct FcmpPpVerifyInputSliceUnsafe fcmp_pp_verify_inputs);
+
#ifdef __cplusplus
} //extern "C"
#endif
### src/fcmp_pp/fcmp_pp_rust/src/lib.rs
@@ -1,3 +1,5 @@
+use rand_core::OsRng;
+
use ciphersuite::{
group::{
ff::{Field, PrimeField},
@@ -9,12 +11,14 @@ use ciphersuite::{
use ec_divisors::DivisorCurve;
use full_chain_membership_proofs::tree::hash_grow;
+use dalek_ff_group::{Ed25519, EdwardsPoint};
use helioselene::{
Field25519 as SeleneScalar, Helios, HeliosPoint, HelioseleneField as HeliosScalar,
Selene, SelenePoint,
};
use monero_fcmp_plus_plus::{
+ fcmps::{Fcmp, TreeRoot}, Curves, FcmpPlusPlus,
HELIOS_FCMP_GENERATORS, SELENE_FCMP_GENERATORS,
};
use monero_fcmp_plus_plus_generators::{
@@ -60,6 +64,30 @@ static_assert_alignment!(SelenePoint, size_of::<usize>());
static_assert_size_eq!(OutputTuple, 32*3);
static_assert_alignment!(OutputTuple, 1);
+//-------------------------------------------------------------------------------------- Box helpers
+
+fn new_box_raw<T>(obj: T) -> *mut T {
+ Box::into_raw(Box::new(obj))
+}
+
+// https://doc.rust-lang.org/std/boxed/struct.Box.html#method.from_raw
+fn destroy_box<T>(ptr: *mut T) {
+ let _ = unsafe { Box::from_raw(ptr) };
+}
+
+macro_rules! destroy_fn {
+ ($fn_name:ident, $type:ty) => {
+ /// # Safety
+ ///
+ /// This function assumes that the obj was allocated on the heap via
+ /// Box::into_raw(Box::new())
+ #[no_mangle]
+ pub unsafe extern "C" fn $fn_name(obj: *mut $type) {
+ destroy_box(obj);
+ }
+ };
+}
+
//-------------------------------------------------------------------------------------- Curve points
#[no_mangle]
@@ -151,6 +179,17 @@ const unsafe fn slice_from_raw_parts_0able<'a, T>(p: *const T, len: usize) -> &'
}
}
+fn ed25519_point_from_bytes(ed25519_point: *const u8) -> std::io::Result<EdwardsPoint> {
+ let mut ed25519_point = unsafe { core::slice::from_raw_parts(ed25519_point, 32) };
+ <Ed25519>::read_G(&mut ed25519_point)
+}
+
+fn hash_array_from_bytes(
+ h: *const u8,
+) -> std::result::Result<[u8; 32], std::array::TryFromSliceError> {
+ unsafe { core::slice::from_raw_parts(h, 32) }.try_into()
+}
+
#[repr(C)]
pub struct Slice<T> {
buf: *const T,
@@ -186,6 +225,42 @@ pub extern "C" fn selene_zero_scalar() -> SeleneScalar {
SeleneScalar::ZERO
}
+/// # Safety
+///
+/// This function expects a non-null pointer to TreeRootUnsafe in tree_root_out.
+#[no_mangle]
+pub unsafe extern "C" fn selene_tree_root(
+ selene_point: SelenePoint,
+ tree_root_out: *mut *mut TreeRoot<Selene, Helios>,
+) -> c_int {
+ if tree_root_out.is_null() {
+ return -1;
+ }
+
+ let tree_root = TreeRoot::<Selene, Helios>::C1(selene_point);
+ *tree_root_out = new_box_raw(tree_root);
+ 0
+}
+
+/// # Safety
+///
+/// This function expects a non-null pointer to TreeRootUnsafe in tree_root_out.
+#[no_mangle]
+pub unsafe extern "C" fn helios_tree_root(
+ helios_point: HeliosPoint,
+ tree_root_out: *mut *mut TreeRoot<Selene, Helios>,
+) -> c_int {
+ if tree_root_out.is_null() {
+ return -1;
+ }
+
+ let tree_root = TreeRoot::<Selene, Helios>::C2(helios_point);
+ *tree_root_out = new_box_raw(tree_root);
+ 0
+}
+
+destroy_fn!(destroy_tree_root, TreeRoot::<Selene, Helios>);
+
/// # Safety
///
/// This function expects a valid pointer to a HeliosPoint passed in hash_out.
@@ -248,6 +323,167 @@ pub unsafe extern "C" fn hash_grow_selene(
0
}
+#[no_mangle]
+pub extern "C" fn membership_proof_size(n_inputs: usize, n_tree_layers: usize) -> usize {
+ Fcmp::<Curves>::proof_size(n_inputs, n_tree_layers)
+}
+
+#[no_mangle]
+pub extern "C" fn fcmp_pp_proof_size(n_inputs: usize, n_tree_layers: usize) -> usize {
+ FcmpPlusPlus::proof_size(n_inputs, n_tree_layers)
+}
+
+pub struct FcmpPpVerifyInput {
+ fcmp_pp: FcmpPlusPlus,
+ tree_root: TreeRoot<Selene, Helios>,
+ n_tree_layers: usize,
+ signable_tx_hash: [u8; 32],
+ key_images: Vec<EdwardsPoint>,
+}
+
+/// # Safety
+///
+/// This function assumes that the signable tx hash is 32 bytes, the tree root is heap
+/// allocated via a CResult, and pseudo outs and key images are 32 bytes each
+///
+/// The caller is expected to ensure the tree root is on the correct layer
+/// of the expected curve, n_inputs <= FCMP_PLUS_PLUS_MAX_INPUTS,
+/// n_tree_layers <= FCMP_PLUS_PLUS_MAX_LAYERS.
+#[no_mangle]
+pub unsafe extern "C" fn fcmp_pp_verify_input_new(
+ signable_tx_hash: *const u8,
+ proof: *const u8,
+ proof_len: usize,
+ n_tree_layers: usize,
+ tree_root: *const TreeRoot<Selene, Helios>,
+ pseudo_outs: Slice<*const u8>,
+ key_images: Slice<*const u8>,
+ fcmp_pp_verify_input_out: *mut *mut FcmpPpVerifyInput,
+) -> c_int {
+ if signable_tx_hash.is_null()
+ || proof.is_null()
+ || tree_root.is_null()
+ || fcmp_pp_verify_input_out.is_null() {
+ return -1;
+ }
+
+ // Early checks
+ let n_inputs = pseudo_outs.len;
+ if n_inputs == 0 || n_tree_layers == 0 {
+ return -2;
+ }
+ if n_inputs != key_images.len {
+ return -3;
+ }
+ if proof_len != fcmp_pp_proof_size(n_inputs, n_tree_layers) {
+ return -4;
+ }
+
+ let Ok(signable_tx_hash) = hash_array_from_bytes(signable_tx_hash) else {
+ return -5;
+ };
+
+ let mut proof: &[u8] = unsafe { core::slice::from_raw_parts(proof, proof_len) };
+
+ // 32 byte pseudo outs
+ let pseudo_outs: &[*const u8] = pseudo_outs.into();
+ for &x in pseudo_outs.iter() {
+ if x.is_null() {
+ return -6;
+ }
+ }
+ let pseudo_outs: Vec<[u8; 32]> = pseudo_outs
+ .iter()
+ .map(|&x| {
+ let x = unsafe { core::slice::from_raw_parts(x, 32) };
+ let mut pseudo_out = [0u8; 32];
+ pseudo_out.copy_from_slice(x);
+ pseudo_out
+ })
+ .collect();
+
+ // Read the FCMP++ proof
+ let Ok(fcmp_plus_plus) = FcmpPlusPlus::read(&pseudo_outs, n_tree_layers, &mut proof) else {
+ return -7;
+ };
+
+ let tree_root: TreeRoot<Selene, Helios> = unsafe { *tree_root };
+
+ // Collect de-compressed key images into a Vec
+ let key_images_slice: &[*const u8] = key_images.into();
+ let mut key_images = Vec::with_capacity(key_images_slice.len());
+ for compressed_ki in key_images_slice {
+ if compressed_ki.is_null() {
+ return -8;
+ }
+ let Ok(key_image) = ed25519_point_from_bytes(*compressed_ki) else {
+ return -9;
+ };
+ key_images.push(key_image);
+ }
+
+ let fcmp_pp_verify_input = FcmpPpVerifyInput {
+ fcmp_pp: fcmp_plus_plus,
+ tree_root,
+ n_tree_layers,
+ signable_tx_hash,
+ key_images,
+ };
+
+ *fcmp_pp_verify_input_out = new_box_raw(fcmp_pp_verify_input);
+ 0
+}
+
+destroy_fn!(destroy_fcmp_pp_verify_input, FcmpPpVerifyInput);
+
+/// # Safety
+///
+/// This function assumes that the inputs are from fcmp_pp_verify_input_new
+#[no_mangle]
+pub unsafe extern "C" fn fcmp_pp_n_inputs(input: *const FcmpPpVerifyInput) -> usize {
+ assert!(!input.is_null());
+ let fcmp_pp_verify_input = &*input;
+ fcmp_pp_verify_input.key_images.len()
+}
+
+/// # Safety
+///
+/// This function assumes that the inputs are from fcmp_pp_verify_input_new
+#[no_mangle]
+pub unsafe extern "C" fn fcmp_pp_verify(inputs: Slice<*const FcmpPpVerifyInput>) -> bool {
+ let inputs: &[*const FcmpPpVerifyInput] = inputs.into();
+
+ let mut ed_verifier = multiexp::BatchVerifier::new(inputs.len());
+ let mut c1_verifier = generalized_bulletproofs::Generators::batch_verifier();
+ let mut c2_verifier = generalized_bulletproofs::Generators::batch_verifier();
+
+ for &input in inputs {
+ if input.is_null() {
+ return false;
+ }
+
+ // Use ref so the input doesn't get consumed (the caller handles de-allocating)
+ let fcmp_pp_verify_input = &*input;
+
+ let Ok(_) = fcmp_pp_verify_input.fcmp_pp.verify(
+ &mut OsRng,
+ &mut ed_verifier,
+ &mut c1_verifier,
+ &mut c2_verifier,
+ fcmp_pp_verify_input.tree_root,
+ fcmp_pp_verify_input.n_tree_layers,
+ fcmp_pp_verify_input.signable_tx_hash,
+ fcmp_pp_verify_input.key_images.clone(),
+ ) else {
+ return false;
+ };
+ }
+
+ ed_verifier.verify_vartime()
+ && SELENE_FCMP_GENERATORS.generators.verify(c1_verifier)
+ && HELIOS_FCMP_GENERATORS.generators.verify(c2_verifier)
+}
+
// https://github.com/rust-lang/rust/issues/79609
#[cfg(all(target_os = "windows", target_arch = "x86"))]
#[no_mangle]
### src/fcmp_pp/fcmp_pp_serialization.h
@@ -31,6 +31,7 @@
#include "fcmp_pp_types.h"
#include "serialization/serialization.h"
#include "serialization/binary_archive.h"
+#include "serialization/crypto.h"
#include "serialization/debug_archive.h"
#include "serialization/json_archive.h"
#include "serialization/variant.h"
### src/fcmp_pp/fcmp_pp_types.cpp
@@ -28,6 +28,7 @@
#include "fcmp_pp_types.h"
+#include "cryptonote_config.h"
#include "misc_log_ex.h"
namespace fcmp_pp
@@ -52,6 +53,94 @@ OutputTuple output_tuple_from_bytes(const crypto::ec_point &O, const crypto::ec_
}
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
+// FFI types
+//----------------------------------------------------------------------------------------------------------------------
+#define CHECK_FFI_RES(r) \
+ CHECK_AND_ASSERT_THROW_MES(r == 0, __func__ << " failed with error code " << r);
+
+//----------------------------------------------------------------------------------------------------------------------
+TreeRootShared helios_tree_root(const HeliosPoint &helios_point)
+{
+ ::TreeRootUnsafe *raw_ptr;
+ CHECK_FFI_RES(::helios_tree_root(helios_point, &raw_ptr));
+ return TreeRootShared(raw_ptr, ::destroy_tree_root);
+}
+
+TreeRootShared selene_tree_root(const SelenePoint &selene_point)
+{
+ ::TreeRootUnsafe *raw_ptr;
+ CHECK_FFI_RES(::selene_tree_root(selene_point, &raw_ptr));
+ return TreeRootShared(raw_ptr, ::destroy_tree_root);
+}
+//----------------------------------------------------------------------------------------------------------------------
+void FcmpPpVerifyInputDeleter::operator()(FcmpPpVerifyInputUnsafe *p) const noexcept
+{
+ ::destroy_fcmp_pp_verify_input(p);
+}
+
+FcmpPpVerifyInput fcmp_pp_verify_input_new(const crypto::hash &signable_tx_hash,
+ const fcmp_pp::FcmpPpProof &fcmp_pp_proof,
+ const std::size_t n_tree_layers,
+ const fcmp_pp::TreeRootShared &tree_root,
+ const std::vector<crypto::ec_point> &pseudo_outs,
+ const std::vector<crypto::key_image> &key_images)
+{
+ FcmpPpVerifyInputUnsafe *raw_ptr;
+ TRY_ENTRY();
+
+ // Cast pseudo outs to vector of const uint8_t*
+ std::vector<const uint8_t *> pseudo_outs_ptrs;
+ pseudo_outs_ptrs.reserve(pseudo_outs.size());
+ for (const auto &po : pseudo_outs)
+ pseudo_outs_ptrs.emplace_back((const uint8_t *)&po);
+
+ // Cast key images to vector const uint8_t*
+ std::vector<const uint8_t *> key_images_ptrs;
+ key_images_ptrs.reserve(key_images.size());
+ for (const auto &ki : key_images)
+ key_images_ptrs.emplace_back((const uint8_t *)&ki.data);
+
+ int r = ::fcmp_pp_verify_input_new(
+ reinterpret_cast<const uint8_t*>(&signable_tx_hash),
+ fcmp_pp_proof.data(),
+ fcmp_pp_proof.size(),
+ n_tree_layers,
+ tree_root.get(),
+ {pseudo_outs_ptrs.data(), pseudo_outs_ptrs.size()},
+ {key_images_ptrs.data(), key_images_ptrs.size()},
+ &raw_ptr
+ );
+ CHECK_FFI_RES(r);
+ CATCH_ENTRY("fcmp_pp::fcmp_pp_verify_input_new", nullptr);
+
+ return FcmpPpVerifyInput(raw_ptr);
+}
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+std::size_t membership_proof_len(const std::size_t n_inputs, const uint8_t n_layers)
+{
+ CHECK_AND_ASSERT_THROW_MES(n_inputs > 0, "n_inputs must be >0");
+ CHECK_AND_ASSERT_THROW_MES(n_layers > 0, "n_layers must be >0");
+ CHECK_AND_ASSERT_THROW_MES(n_inputs <= FCMP_PLUS_PLUS_MAX_INPUTS, "n_inputs must be <= FCMP_PLUS_PLUS_MAX_INPUTS");
+ CHECK_AND_ASSERT_THROW_MES(n_layers <= FCMP_PLUS_PLUS_MAX_LAYERS, "n_layers must be <= FCMP_PLUS_PLUS_MAX_LAYERS");
+
+ return ::membership_proof_size(n_inputs, n_layers);
+};
+
+std::size_t fcmp_pp_proof_len(const std::size_t n_inputs, const uint8_t n_layers)
+{
+ // https://github.com/monero-oxide/monero-oxide/blob/77788c368145127f2dde2ac3e2ddce919f3ddd01/monero-oxide/ringct/fcmp%2B%2B/src/lib.rs#L189
+ return membership_proof_len(n_inputs, n_layers)
+ + (n_inputs * (FCMP_PP_INPUT_TUPLE_SIZE_V1 + FCMP_PP_SAL_PROOF_SIZE_V1));
+};
+//----------------------------------------------------------------------------------------------------------------------
+std::size_t n_inputs_in_fcmp_pp(const FcmpPpVerifyInput &fcmp_pp_verify_input)
+{
+ CHECK_AND_ASSERT_THROW_MES(fcmp_pp_verify_input != nullptr, "nullptr FCMP++ verify input");
+ return ::fcmp_pp_n_inputs(fcmp_pp_verify_input.get());
+}
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
const crypto::public_key &output_pubkey_cref(const OutputPair &output_pair)
{
struct output_pair_visitor
### src/fcmp_pp/fcmp_pp_types.h
@@ -29,6 +29,7 @@
#pragma once
#include <cstring>
+#include <memory>
#include <type_traits>
#include <unordered_map>
#include <variant>
@@ -69,6 +70,36 @@ using OutputTuple = ::OutputTuple;
//----------------------------------------------------------------------------------------------------------------------
OutputTuple output_tuple_from_bytes(const crypto::ec_point &O, const crypto::ec_point &I, const crypto::ec_point &C);
//----------------------------------------------------------------------------------------------------------------------
+// Define FCMP++ prove/verify C++ type here so it can be used in FFI types
+using FcmpPpProof = std::vector<uint8_t>;
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+// FFI types
+//----------------------------------------------------------------------------------------------------------------------
+// Macro to instantiate an FFI-compatible slice from a vector of FCMP FFI type. Instantiates a vector in local scope
+// so it remains in scope while the slice points to it, making sure memory addresses remain contiguous. The slice is
+// only usable within local scope, hence "TEMP".
+#define MAKE_TEMP_FFI_SLICE(raw_t, vec, slice_name) \
+ std::vector<const raw_t##Unsafe *> raw_t##Vector; \
+ raw_t##Vector.reserve(vec.size()); \
+ for (const raw_t &elem : vec) \
+ raw_t##Vector.push_back(elem.get()); \
+ ::raw_t##SliceUnsafe slice_name{raw_t##Vector.data(), raw_t##Vector.size()};
+
+// Use a shared pointer so we can reference the same underlying tree root in multiple places
+using TreeRootShared = std::shared_ptr<TreeRootUnsafe>;
+TreeRootShared helios_tree_root(const HeliosPoint &);
+TreeRootShared selene_tree_root(const SelenePoint &);
+
+struct FcmpPpVerifyInputDeleter { void operator()(FcmpPpVerifyInputUnsafe *p) const noexcept; };
+using FcmpPpVerifyInput = std::unique_ptr<FcmpPpVerifyInputUnsafe, FcmpPpVerifyInputDeleter>;
+FcmpPpVerifyInput fcmp_pp_verify_input_new(const crypto::hash &signable_tx_hash,
+ const fcmp_pp::FcmpPpProof &fcmp_pp_proof,
+ const std::size_t n_tree_layers,
+ const fcmp_pp::TreeRootShared &tree_root,
+ const std::vector<crypto::ec_point> &pseudo_outs,
+ const std::vector<crypto::key_image> &key_images);
+//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
// C++ types
//----------------------------------------------------------------------------------------------------------------------
@@ -174,6 +205,17 @@ struct CompressedTreeExtension final
std::vector<CompressedLayerExtension> layer_extensions;
};
//----------------------------------------------------------------------------------------------------------------------
+// FCMP++ prove/verify types
+//----------------------------------------------------------------------------------------------------------------------
+// Size of the membership proof alone
+std::size_t membership_proof_len(const std::size_t n_inputs, const uint8_t n_layers);
+
+// Size of the FCMP++ proof (membership proof + spend-auth + linkability proofs & input tuples)
+std::size_t fcmp_pp_proof_len(const std::size_t n_inputs, const uint8_t n_layers);
+
+// Get the number of inputs included in the FCMP++ verify input
+std::size_t n_inputs_in_fcmp_pp(const FcmpPpVerifyInput &fcmp_pp_verify_input);
+//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
}//namespace fcmp_pp
### src/fcmp_pp/verify.cpp
@@ -0,0 +1,69 @@
+// Copyright (c) 2024, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "verify.h"
+
+#include "fcmp_pp_crypto.h"
+#include "fcmp_pp_rust/fcmp++.h"
+#include "misc_log_ex.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "fcmp_pp"
+
+namespace fcmp_pp
+{
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+bool verify(const std::vector<fcmp_pp::FcmpPpVerifyInput> &fcmp_pp_verify_inputs)
+{
+ MAKE_TEMP_FFI_SLICE(FcmpPpVerifyInput, fcmp_pp_verify_inputs, fcmp_pp_verify_inputs_slice);
+ return ::fcmp_pp_verify(fcmp_pp_verify_inputs_slice);
+}
+//----------------------------------------------------------------------------------------------------------------------
+bool verify(const crypto::hash &signable_tx_hash,
+ const fcmp_pp::FcmpPpProof &fcmp_pp_proof,
+ const std::size_t n_tree_layers,
+ const fcmp_pp::TreeRootShared &tree_root,
+ const std::vector<crypto::ec_point> &pseudo_outs,
+ const std::vector<crypto::key_image> &key_images)
+{
+ auto fcmp_pp_verify_input = fcmp_pp::fcmp_pp_verify_input_new(
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_tree_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ );
+ CHECK_AND_ASSERT_MES(fcmp_pp_verify_input != nullptr, false, "Failed to construct FCMP++ verify input");
+ std::vector<fcmp_pp::FcmpPpVerifyInput> fcmp_pp_verify_inputs;
+ fcmp_pp_verify_inputs.emplace_back(std::move(fcmp_pp_verify_input));
+ return verify(fcmp_pp_verify_inputs);
+}
+//----------------------------------------------------------------------------------------------------------------------
+}//namespace fcmp_pp
### src/fcmp_pp/verify.h
@@ -0,0 +1,50 @@
+// Copyright (c) 2026 The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <cstdint>
+#include <vector>
+
+#include "crypto/crypto.h"
+#include "crypto/hash.h"
+#include "fcmp_pp_types.h"
+
+namespace fcmp_pp
+{
+//----------------------------------------------------------------------------------------------------------------------
+bool verify(const std::vector<fcmp_pp::FcmpPpVerifyInput> &fcmp_pp_verify_inputs);
+
+bool verify(const crypto::hash &signable_tx_hash,
+ const fcmp_pp::FcmpPpProof &fcmp_pp_proof,
+ const std::size_t n_tree_layers,
+ const fcmp_pp::TreeRootShared &tree_root,
+ const std::vector<crypto::ec_point> &pseudo_outs,
+ const std::vector<crypto::key_image> &key_images);
+//----------------------------------------------------------------------------------------------------------------------
+}//namespace fcmp_pp
### src/ringct/rctSigs.cpp
@@ -39,6 +39,8 @@
#include "bulletproofs_plus.h"
#include "cryptonote_config.h"
#include "device/device.hpp"
+#include "fcmp_pp/fcmp_pp_crypto.h"
+#include "fcmp_pp/verify.h"
#include "scope_guard.h"
#include "serialization/crypto.h"
@@ -1616,4 +1618,109 @@ namespace rct {
CHECK_AND_ASSERT_MES(all_valid.load(), false, "Torsion check failed");
return true;
}
+
+ bool batchVerifyFcmpPpProofs(std::vector<fcmp_pp::FcmpPpVerifyInput> &&fcmp_pp_verify_inputs) {
+ const std::size_t n_proofs = fcmp_pp_verify_inputs.size();
+ if (n_proofs == 0)
+ return true;
+ for (const auto &ver_inp : fcmp_pp_verify_inputs)
+ CHECK_AND_ASSERT_MES(ver_inp != nullptr, false, "Invalid FCMP++ verify input");
+
+ // Sort the inputs in descending order based on input count. We will use a bin packing algo to spread the load.
+ std::sort(fcmp_pp_verify_inputs.begin(), fcmp_pp_verify_inputs.end(), [](auto &a, auto &b)
+ { return fcmp_pp::n_inputs_in_fcmp_pp(a) > fcmp_pp::n_inputs_in_fcmp_pp(b); });
+
+ tools::threadpool &tpool = tools::threadpool::getInstanceForCompute();
+ const std::size_t n_threads = std::max<std::size_t>(1, tpool.get_max_concurrency());
+ const bool multithreaded = n_threads > 1;
+
+ // 1 batch per thread
+ const std::size_t n_batches = std::min(n_threads, n_proofs);
+
+ struct ProofBatch
+ {
+ std::vector<fcmp_pp::FcmpPpVerifyInput> batch;
+ std::size_t total_inputs{0};
+ };
+
+ std::vector<ProofBatch> batches;
+ batches.reserve(n_batches);
+
+ // Spread the load based on n inputs in each proof, to make it more even.
+ for (std::size_t i = 0; i < n_proofs; ++i)
+ {
+ // Here's the proof we're adding to a batch
+ fcmp_pp::FcmpPpVerifyInput &fcmp_pp_verify_input = fcmp_pp_verify_inputs.at(i);
+ const std::size_t n_inputs = fcmp_pp::n_inputs_in_fcmp_pp(fcmp_pp_verify_input);
+
+ // Find the batch with the lowest weight
+ std::size_t min_weight_batch_idx = 0;
+ std::size_t min_weight = 0;
+ for (std::size_t j = 0; j < n_batches; ++j)
+ {
+ if (batches.size() <= j)
+ {
+ // We found an empty batch, use it
+ batches.emplace_back();
+ batches.back().batch.reserve(n_proofs - i);
+ min_weight_batch_idx = j;
+ break;
+ }
+
+ if (min_weight > 0 && batches.at(j).total_inputs >= min_weight)
+ continue;
+
+ // We found a batch with a lower weight
+ min_weight = batches.at(j).total_inputs;
+ min_weight_batch_idx = j;
+ }
+
+ // Add the proof to the min weight batch
+ auto &min_weight_batch = batches.at(min_weight_batch_idx);
+ assert(min_weight_batch.batch.size() < min_weight_batch.batch.capacity()); // if tripped, we pre-reserved wrong
+ min_weight_batch.batch.emplace_back(std::move(fcmp_pp_verify_input));
+ min_weight_batch.total_inputs += n_inputs;
+
+ MDEBUG("Placed FCMP++ tx in batch " << (min_weight_batch_idx+1)
+ << ", batch now has " << min_weight_batch.total_inputs << " total inputs");
+ }
+ CHECK_AND_ASSERT_MES(batches.size() <= n_batches, false, "Too many batches");
+
+ std::atomic<bool> all_valid{true};
+ tools::threadpool::waiter batch_verify_waiter(tpool);
+ for (std::size_t i = 0; i < batches.size(); ++i)
+ {
+ CHECK_AND_ASSERT_MES(batches[i].batch.size(), false, "Empty batch in batchVerifyFcmpPpProofs");
+
+ MDEBUG("Verifying FCMP++ batch " << (i+1) << " ("
+ << batches[i].total_inputs << " total inputs across " << batches[i].batch.size() << " txs)");
+
+ if (!multithreaded)
+ {
+ if (!fcmp_pp::verify(batches[i].batch))
+ {
+ all_valid.store(false);
+ }
+ continue;
+ }
+
+ tpool.submit(&batch_verify_waiter,
+ [&batches, &all_valid, i]()
+ {
+ if (!fcmp_pp::verify(batches[i].batch))
+ {
+ all_valid.store(false);
+ }
+ MDEBUG("Finished verifying FCMP++ batch " << (i+1) << " / " << batches.size());
+ },
+ true
+ );
+ }
+
+ if (multithreaded)
+ CHECK_AND_ASSERT_MES(batch_verify_waiter.wait(), false, "Failed to batch verify FCMP++ proofs");
+
+ CHECK_AND_ASSERT_MES(all_valid.load(), false, "FCMP++ proofs failed batch verification");
+ return true;
+ }
}
### src/ringct/rctSigs.h
@@ -46,7 +46,7 @@ extern "C" {
#include "crypto/keccak.h"
}
#include "crypto/crypto.h"
-
+#include "fcmp_pp/fcmp_pp_types.h"
#include "rctTypes.h"
#include "rctOps.h"
@@ -139,6 +139,9 @@ namespace rct {
// Make sure points are valid points, don't have torsion, and are not equal to identity
bool verPointsForTorsion(const std::vector<key> & pts);
+
+ // Split into batches and verify each batch in parallel
+ bool batchVerifyFcmpPpProofs(std::vector<fcmp_pp::FcmpPpVerifyInput> &&fcmp_pp_verify_inputs);
}
#endif /* RCTSIGS_H */
### tests/data/fcmp_pp_verify_inputs_128in.bin
[binary or diff unavailable]
### tests/data/fcmp_pp_verify_inputs_1in.bin
[binary or diff unavailable]
### tests/data/fcmp_pp_verify_inputs_2in.bin
[binary or diff unavailable]
### tests/data/fcmp_pp_verify_inputs_4in.bin
[binary or diff unavailable]
### tests/data/fcmp_pp_verify_inputs_8in.bin
[binary or diff unavailable]
### tests/performance_tests/CMakeLists.txt
@@ -36,6 +36,7 @@ set(performance_tests_headers
construct_tx.h
derive_public_key.h
derive_secret_key.h
+ fcmp_pp.h
fe_batch_invert.h
ge_frombytes_vartime.h
generate_key_derivation.h
@@ -69,6 +70,7 @@ target_link_libraries(performance_tests
common
cncrypto
epee
+ tests_common
${Boost_CHRONO_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES})
### tests/performance_tests/fcmp_pp.h
@@ -0,0 +1,82 @@
+// Copyright (c) 2025, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include "crypto/crypto.h"
+#include "crypto/hash.h"
+#include "fcmp_pp/fcmp_pp_types.h"
+#include "fcmp_pp/verify.h"
+#include "tests_common/fcmp_pp_helpers.h"
+
+#include <iosfwd>
+
+template<std::size_t n_inputs>
+class test_fcmp_pp_verify
+{
+public:
+ static constexpr size_t loop_count =
+ n_inputs < 2 ? 1000 :
+ n_inputs < 16 ? 100 :
+ /*n_inputs >= 16*/ 8;
+
+ bool init()
+ {
+ return tests_common::read_fcmp_pp_verify_input_from_file(
+ n_inputs,
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ );
+ }
+
+ bool test()
+ {
+ return fcmp_pp::verify(
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ );
+ }
+
+private:
+ crypto::hash signable_tx_hash;
+ std::vector<uint8_t> fcmp_pp_proof;
+ uint8_t n_layers;
+ fcmp_pp::TreeRootShared tree_root;
+ std::vector<crypto::ec_point> pseudo_outs;
+ std::vector<crypto::key_image> key_images;
+};
### tests/performance_tests/main.cpp
@@ -43,6 +43,7 @@
#include "derive_public_key.h"
#include "derive_secret_key.h"
#include "derive_view_tag.h"
+#include "fcmp_pp.h"
#include "fe_batch_invert.h"
#include "ge_frombytes_vartime.h"
#include "ge_tobytes.h"
@@ -67,6 +68,7 @@
#include "multiexp.h"
#include "sig_mlsag.h"
#include "sig_clsag.h"
+#include "tests_common/fcmp_pp_helpers.h"
#include "zero_commit.h"
namespace po = boost::program_options;
@@ -92,6 +94,10 @@ int main(int argc, char** argv)
command_line::add_arg(desc_options, arg_loop_multiplier);
command_line::add_arg(desc_options, arg_timings_database);
+ // the default test data directory is ../data (relative to the executable's directory)
+ const auto default_test_data_dir = boost::filesystem::canonical(argv[0]).parent_path().parent_path() / "data";
+ tests_common::data_dir = default_test_data_dir;
+
po::variables_map vm;
bool r = command_line::handle_error_helper(desc_options, [&]()
{
@@ -601,6 +607,13 @@ int main(int argc, char** argv)
TEST_PERFORMANCE1(filter, p, test_zero_commit, true); // fast
TEST_PERFORMANCE1(filter, p, test_zero_commit, false);
+ // Test with different n inputs
+ TEST_PERFORMANCE1(filter, p, test_fcmp_pp_verify, 1);
+ TEST_PERFORMANCE1(filter, p, test_fcmp_pp_verify, 2);
+ TEST_PERFORMANCE1(filter, p, test_fcmp_pp_verify, 4);
+ TEST_PERFORMANCE1(filter, p, test_fcmp_pp_verify, 8);
+ TEST_PERFORMANCE1(filter, p, test_fcmp_pp_verify, 128);
+
std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl;
return 0;
### tests/tests_common/CMakeLists.txt
@@ -27,9 +27,11 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
add_library(tests_common
+ src/fcmp_pp_helpers.cpp
src/tx_construction_helpers.cpp)
target_link_libraries(tests_common
PUBLIC
cncrypto
- cryptonote_core)
+ cryptonote_core
+ fcmp_pp)
target_include_directories(tests_common PUBLIC include)
### tests/tests_common/include/tests_common/fcmp_pp_helpers.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2025, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <boost/filesystem.hpp>
+
+#include "fcmp_pp/fcmp_pp_types.h"
+
+namespace tests_common
+{
+ extern boost::filesystem::path data_dir;
+
+ bool write_fcmp_pp_verify_input_to_file(
+ const std::size_t n_inputs,
+ const crypto::hash &signable_tx_hash,
+ const fcmp_pp::FcmpPpProof &fcmp_pp_proof,
+ const uint8_t n_layers,
+ const crypto::ec_point &tree_root_bytes,
+ const std::vector<crypto::ec_point> &pseudo_outs,
+ const std::vector<crypto::key_image> &key_images);
+
+ bool read_fcmp_pp_verify_input_from_file(
+ const std::size_t n_inputs,
+ crypto::hash &signable_tx_hash,
+ fcmp_pp::FcmpPpProof &fcmp_pp_proof,
+ uint8_t &n_layers,
+ fcmp_pp::TreeRootShared &tree_root,
+ std::vector<crypto::ec_point> &pseudo_outs,
+ std::vector<crypto::key_image> &key_images);
+}
### tests/tests_common/src/fcmp_pp_helpers.cpp
@@ -0,0 +1,154 @@
+// Copyright (c) 2025, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "tests_common/fcmp_pp_helpers.h"
+
+#include "fcmp_pp/curve_trees.h"
+#include "fcmp_pp/fcmp_pp_types.h"
+#include "serialization/binary_utils.h"
+#include "serialization/containers.h"
+#include "serialization/crypto.h"
+#include "serialization/serialization.h"
+
+#include <boost/filesystem.hpp>
+#include <iosfwd>
+
+static std::string get_fcmp_pp_filename(const std::size_t n_inputs)
+{
+ return tests_common::data_dir.string() + "/fcmp_pp_verify_inputs_" + std::to_string(n_inputs) + "in.bin";
+}
+
+// Useful struct for serializing all the components necessary to verify a FCMP++ proof
+struct SerializableFcmpPpVerify final
+{
+ crypto::hash signable_tx_hash;
+ uint8_t n_layers;
+ fcmp_pp::FcmpPpProof fcmp_pp_proof;
+ crypto::ec_point tree_root;
+ std::vector<crypto::ec_point> pseudo_outs;
+ std::vector<crypto::key_image> key_images;
+
+ BEGIN_SERIALIZE_OBJECT()
+ FIELD(signable_tx_hash)
+ FIELD(n_layers)
+ FIELD(fcmp_pp_proof)
+ FIELD(tree_root)
+ FIELD(pseudo_outs)
+ FIELD(key_images)
+ END_SERIALIZE()
+};
+
+namespace tests_common
+{
+ boost::filesystem::path data_dir;
+
+ bool write_fcmp_pp_verify_input_to_file(
+ const std::size_t n_inputs,
+ const crypto::hash &signable_tx_hash,
+ const fcmp_pp::FcmpPpProof &fcmp_pp_proof,
+ const uint8_t n_layers,
+ const crypto::ec_point &tree_root_bytes,
+ const std::vector<crypto::ec_point> &pseudo_outs,
+ const std::vector<crypto::key_image> &key_images)
+ {
+ CHECK_AND_ASSERT_MES(pseudo_outs.size() == n_inputs, false, "Unexpected size pseudo outs");
+ CHECK_AND_ASSERT_MES(key_images.size() == n_inputs, false, "Unexpected size key_images");
+ CHECK_AND_ASSERT_MES(fcmp_pp_proof.size() == fcmp_pp::fcmp_pp_proof_len(n_inputs, n_layers), false,
+ "Bad FCMP++ proof size");
+
+ // Serialize the data into a string buffer
+ SerializableFcmpPpVerify serializable_fcmp_pp_verify{
+ .signable_tx_hash = signable_tx_hash,
+ .n_layers = n_layers,
+ .fcmp_pp_proof = fcmp_pp_proof,
+ .tree_root = tree_root_bytes,
+ .pseudo_outs = pseudo_outs,
+ .key_images = key_images
+ };
+
+ std::string blob;
+ const bool r = ::serialization::dump_binary(serializable_fcmp_pp_verify, blob);
+ CHECK_AND_ASSERT_MES(r, false, "Failed to serialize proof data");
+
+ // Write to file
+ const std::string filename = get_fcmp_pp_filename(n_inputs);
+ std::ofstream file(filename, std::ios::binary);
+ CHECK_AND_ASSERT_MES(file, false, "Failed to open file");
+ file << blob;
+
+ LOG_PRINT_L0("Wrote FCMP++ proof to " << filename);
+
+ return true;
+ }
+
+ bool read_fcmp_pp_verify_input_from_file(
+ const std::size_t n_inputs,
+ crypto::hash &signable_tx_hash,
+ fcmp_pp::FcmpPpProof &fcmp_pp_proof,
+ uint8_t &n_layers,
+ fcmp_pp::TreeRootShared &tree_root,
+ std::vector<crypto::ec_point> &pseudo_outs,
+ std::vector<crypto::key_image> &key_images)
+ {
+ const std::string filename = get_fcmp_pp_filename(n_inputs);
+ std::ifstream file(filename, std::ios::binary);
+ CHECK_AND_ASSERT_MES(file, false, "Failed to open file");
+
+ // Read the file into a string buffer
+ const auto blob_size = boost::filesystem::file_size(filename);
+ std::string blob(blob_size, '\0');
+ file.read(blob.data(), blob_size);
+
+ // Parse the data and read into the return-by-refs
+ SerializableFcmpPpVerify serializable_fcmp_pp_verify;
+ const bool r = ::serialization::parse_binary(blob, serializable_fcmp_pp_verify);
+ CHECK_AND_ASSERT_MES(r, false, "Failed to de-serialize proof data");
+
+ signable_tx_hash = serializable_fcmp_pp_verify.signable_tx_hash;
+ n_layers = serializable_fcmp_pp_verify.n_layers;
+
+ const std::size_t proof_len = fcmp_pp::fcmp_pp_proof_len(n_inputs, n_layers);
+ fcmp_pp_proof = std::move(serializable_fcmp_pp_verify.fcmp_pp_proof);
+ CHECK_AND_ASSERT_MES(fcmp_pp_proof.size() == proof_len, false, "Unexpected FCMP++ proof size");
+
+ const auto curve_trees = fcmp_pp::curve_trees::curve_trees_v1();
+ const crypto::ec_point tree_root_bytes = serializable_fcmp_pp_verify.tree_root;
+ tree_root = curve_trees->get_tree_root_from_bytes(n_layers, tree_root_bytes);
+ CHECK_AND_ASSERT_MES(tree_root != nullptr, false, "Failed to get tree root from bytes");
+
+ pseudo_outs = std::move(serializable_fcmp_pp_verify.pseudo_outs);
+ key_images = std::move(serializable_fcmp_pp_verify.key_images);
+
+ MDEBUG("signable_tx_hash: " << signable_tx_hash <<
+ ", proof_size: " << proof_len <<
+ ", n_layers: " << (std::size_t)n_layers <<
+ ", tree_root_bytes: " << tree_root_bytes);
+
+ return true;
+ }
+}
### tests/unit_tests/CMakeLists.txt
@@ -54,6 +54,7 @@ set(unit_tests_sources
epee_serialization.cpp
epee_utils.cpp
expect.cpp
+ fcmp_pp.cpp
json_serialization.cpp
get_xtype_from_string.cpp
hashchain.cpp
@@ -131,6 +132,7 @@ target_link_libraries(unit_tests
serialization
wallet
p2p
+ tests_common
version
${Boost_CHRONO_LIBRARY}
${Boost_THREAD_LIBRARY}
### tests/unit_tests/fcmp_pp.cpp
@@ -0,0 +1,523 @@
+// Copyright (c) 2024, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gtest/gtest.h"
+
+#include "common/container_helpers.h"
+#include "common/threadpool.h"
+#include "crypto/crypto.h"
+#include "crypto/generators.h"
+#include "cryptonote_basic/cryptonote_format_utils.h"
+#include "cryptonote_basic/verification_context.h"
+#include "cryptonote_core/tx_verification_utils.h"
+#include "fcmp_pp/fcmp_pp_serialization.h"
+#include "fcmp_pp/fcmp_pp_types.h"
+#include "fcmp_pp/verify.h"
+#include "misc_log_ex.h"
+#include "profile_tools.h"
+#include "ringct/rctOps.h"
+#include "ringct/rctSigs.h"
+#include "serialization/binary_utils.h"
+#include "string_tools.h"
+#include "tests_common/fcmp_pp_helpers.h"
+
+#include <utility>
+#include <vector>
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "unit_tests.fcmp_pp"
+
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+TEST(fcmp_pp, verify_from_file)
+{
+ const std::size_t n_inputs = 128;
+
+ // We want a proof per thread, or 4 proofs if < 4 threads
+ tools::threadpool& tpool = tools::threadpool::getInstanceForCompute();
+ const std::size_t n_proofs = std::max<std::size_t>(4, tpool.get_max_concurrency());
+
+ // We repeat verify attempts in hopes of using all malloc arenas (glibc specific)
+ const std::size_t repeat_n_times = 10;
+
+ // Read from file
+ crypto::hash signable_tx_hash;
+ std::vector<uint8_t> fcmp_pp_proof;
+ uint8_t n_layers;
+ fcmp_pp::TreeRootShared tree_root;
+ std::vector<crypto::ec_point> pseudo_outs;
+ std::vector<crypto::key_image> key_images;
+
+ bool r = tests_common::read_fcmp_pp_verify_input_from_file(
+ n_inputs,
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images);
+ ASSERT_TRUE(r);
+
+ // Test single verification
+ LOG_PRINT_L1("Verifying (n_inputs=" << n_inputs << ")");
+ bool verify = fcmp_pp::verify(
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ );
+ ASSERT_TRUE(verify);
+ LOG_PRINT_L1("Successfully verified (n_inputs=" << n_inputs << ")");
+
+ // Repeat batch verify attempts and observe memory usage
+ for (std::size_t i = 0; i < repeat_n_times; ++i)
+ {
+ // Collect the FCMP++ verify inputs
+ std::vector<fcmp_pp::FcmpPpVerifyInput> fcmp_pp_verify_inputs;
+ fcmp_pp_verify_inputs.reserve(n_proofs);
+ for (std::size_t i = 0; i < n_proofs; ++i)
+ {
+ fcmp_pp_verify_inputs.emplace_back(fcmp_pp::fcmp_pp_verify_input_new(
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ ));
+ }
+
+ // Verify FCMP++ 128-in proofs in parallel using the batch verifier
+ LOG_PRINT_L1("Batch verifying " << n_proofs << " FCMP++ txs, attempt " << i+1);
+ ASSERT_TRUE(rct::batchVerifyFcmpPpProofs(std::move(fcmp_pp_verify_inputs)));
+ LOG_PRINT_L1("Successfully batch verified " << n_proofs << " FCMP++ txs, attempt " << i+1);
+ }
+}
+//----------------------------------------------------------------------------------------------------------------------
+TEST(fcmp_pp, verify_invalids)
+{
+ const std::size_t n_inputs = 2;
+
+ // Read from file
+ crypto::hash signable_tx_hash;
+ std::vector<uint8_t> fcmp_pp_proof;
+ uint8_t n_layers;
+ fcmp_pp::TreeRootShared tree_root;
+ std::vector<crypto::ec_point> pseudo_outs;
+ std::vector<crypto::key_image> key_images;
+
+ bool r = tests_common::read_fcmp_pp_verify_input_from_file(
+ n_inputs,
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images);
+ ASSERT_TRUE(r);
+
+ // Test single verification to confirm validity
+ LOG_PRINT_L1("Verifying (n_inputs=" << n_inputs << ")");
+ bool verify = fcmp_pp::verify(
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ );
+ ASSERT_TRUE(verify);
+ LOG_PRINT_L1("Successfully verified (n_inputs=" << n_inputs << ")");
+
+ // Case 1: bad proof
+ const auto get_bad_fcmp_pp_proof = [&]() -> std::vector<uint8_t>
+ {
+ // Bump a random byte until we have an FCMP++ proof that parses
+ // successfully. We want to make sure it's FCMP++ verification failing
+ // to verify a bad proof, and not parsing failing. As of this writing,
+ // there is only 1 byte that could cause parsing to fail if bumped, so
+ // this approach should be good for testing (bumping byte 479 causes
+ // a scalar to fail to parse).
+ std::vector<uint8_t> bad_fcmp_pp_proof = fcmp_pp_proof;
+ ++bad_fcmp_pp_proof.at(crypto::rand_idx(fcmp_pp_proof.size()));
+ size_t attempt = 0;
+ while (!fcmp_pp::fcmp_pp_verify_input_new(
+ signable_tx_hash,
+ bad_fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ ))
+ {
+ bad_fcmp_pp_proof = fcmp_pp_proof;
+ ++bad_fcmp_pp_proof.at(crypto::rand_idx(fcmp_pp_proof.size()));
+ CHECK_AND_ASSERT_THROW_MES(++attempt < 10, "too many attempts to get bad proof");
+ }
+ return bad_fcmp_pp_proof;
+ };
+ const std::vector<uint8_t> bad_fcmp_pp_proof = get_bad_fcmp_pp_proof();
+ bool failed_verify = fcmp_pp::verify(
+ signable_tx_hash,
+ bad_fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ );
+ ASSERT_FALSE(failed_verify);
+
+ // Case 2: bad signable hash
+ crypto::hash bad_signable_tx_hash = signable_tx_hash;
+ ++bad_signable_tx_hash.data[0];
+ failed_verify = fcmp_pp::verify(
+ bad_signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ );
+ ASSERT_FALSE(failed_verify);
+
+ // Bad batch verify with only invalids
+ {
+ // Collect the FCMP++ verify inputs
+ std::vector<fcmp_pp::FcmpPpVerifyInput> fcmp_pp_verify_inputs;
+ fcmp_pp_verify_inputs.reserve(2);
+
+ // Bad FCMP++ proof
+ fcmp_pp_verify_inputs.emplace_back(fcmp_pp::fcmp_pp_verify_input_new(
+ signable_tx_hash,
+ bad_fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ ));
+
+ // Bad signable hash
+ fcmp_pp_verify_inputs.emplace_back(fcmp_pp::fcmp_pp_verify_input_new(
+ bad_signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ ));
+
+ for (size_t i = 0; i < fcmp_pp_verify_inputs.size(); ++i)
+ {
+ ASSERT_TRUE(fcmp_pp_verify_inputs[i] != nullptr);
+ }
+
+ ASSERT_FALSE(fcmp_pp::verify(fcmp_pp_verify_inputs));
+ ASSERT_FALSE(rct::batchVerifyFcmpPpProofs(std::move(fcmp_pp_verify_inputs)));
+ }
+
+ // Bad batch verify with mixed valid and invalid
+ {
+ // Collect the FCMP++ verify inputs
+ std::vector<fcmp_pp::FcmpPpVerifyInput> fcmp_pp_verify_inputs;
+ fcmp_pp_verify_inputs.reserve(2);
+
+ // Valid
+ fcmp_pp_verify_inputs.emplace_back(fcmp_pp::fcmp_pp_verify_input_new(
+ signable_tx_hash,
+ fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ ));
+
+
+ // Bad FCMP++ proof
+ fcmp_pp_verify_inputs.emplace_back(fcmp_pp::fcmp_pp_verify_input_new(
+ signable_tx_hash,
+ bad_fcmp_pp_proof,
+ n_layers,
+ tree_root,
+ pseudo_outs,
+ key_images
+ ));
+
+ for (size_t i = 0; i < fcmp_pp_verify_inputs.size(); ++i)
+ {
+ ASSERT_TRUE(fcmp_pp_verify_inputs[i] != nullptr);
+ }
+
+ ASSERT_FALSE(fcmp_pp::verify(fcmp_pp_verify_inputs));
+ ASSERT_FALSE(rct::batchVerifyFcmpPpProofs(std::move(fcmp_pp_verify_inputs)));
+ }
+}
+//----------------------------------------------------------------------------------------------------------------------
+TEST(fcmp_pp, force_init_gen_u_v)
+{
+#ifdef NDEBUG
+ GTEST_SKIP() << "Generator reproduction assert statements don't trigger on Release builds";
+#endif
+
+ // these will cause assertion failures in debug mode if the seeds are wrong
+ const ge_p3 U_p3 = crypto::get_U_p3();
+ const ge_p3 V_p3 = crypto::get_V_p3();
+ const ge_cached U_cached = crypto::get_U_cached();
+ const ge_cached V_cached = crypto::get_V_cached();
+
+ (void) U_p3, (void) V_p3, (void) U_cached, (void) V_cached;
+}
+//----------------------------------------------------------------------------------------------------------------------
+TEST(fcmp_pp, proof_size_table)
+{
+ static const uint32_t PROOF_LEN_TABLE[FCMP_PLUS_PLUS_MAX_INPUTS][FCMP_PLUS_PLUS_MAX_LAYERS]
+ {
+ {3136, 3776, 4160, 4800, 5184, 5824, 6208, 6848, 6272, 5696, 5952, 6336, },
+ {4288, 5568, 4992, 6272, 6784, 6592, 7104, 7872, 7424, 6976, 7360, 7872, },
+ {3840, 5760, 6528, 6976, 6528, 6592, 7232, 8000, 8512, 9280, 9088, 8768, },
+ {4352, 6912, 6592, 7168, 7936, 8000, 8768, 9792, 9600, 9408, 10048, 10816, },
+ {4992, 6976, 6528, 7232, 8256, 9536, 9344, 9408, 10176, 11200, 11968, 12864, },
+ {3904, 6272, 7424, 8256, 8192, 8640, 9664, 10816, 11712, 12864, 13056, 13120, },
+ {4160, 6912, 7104, 8064, 9216, 9792, 10944, 12224, 12416, 12736, 13760, 14912, },
+ {4416, 7552, 7744, 8832, 10112, 10688, 11968, 13504, 13824, 14144, 15296, 16576, },
+ {4800, 7232, 7424, 8640, 10048, 11840, 12288, 12864, 14144, 15680, 16960, 18368, },
+ {5056, 7744, 7936, 9280, 10944, 12864, 13312, 14016, 15424, 17088, 18496, 20032, },
+ {3840, 6784, 8576, 10048, 10624, 11840, 13504, 15168, 16704, 18496, 20160, 20992, },
+ {3968, 7168, 9088, 10688, 11392, 12608, 14400, 16320, 17984, 19904, 20864, 21696, },
+ {4096, 7552, 9600, 11328, 12160, 13504, 15424, 17472, 19264, 20480, 21440, 23232, },
+ {4224, 7936, 9024, 10880, 12928, 14400, 16448, 18624, 19712, 20928, 22848, 24896, },
+ {4352, 8320, 9536, 11520, 13696, 15296, 17472, 19776, 20864, 22208, 24256, 26432, },
+ {4480, 8704, 9920, 12032, 14336, 15936, 18240, 20800, 22144, 23488, 25664, 27968, },
+ {4736, 8256, 9472, 11712, 14144, 16832, 18304, 20032, 22464, 24896, 27200, 29632, },
+ {4864, 8512, 9856, 12224, 14784, 17728, 19328, 21056, 23488, 26176, 28608, 31168, },
+ {4992, 8896, 10368, 12864, 15552, 18624, 20224, 22080, 24768, 27456, 30016, 32832, },
+ {5120, 9152, 10624, 13248, 16192, 19392, 21120, 23104, 25792, 28736, 31424, 34240, },
+ {5248, 9536, 11136, 13888, 15872, 19200, 22016, 24128, 27072, 30144, 32960, 35904, },
+ {3904, 8320, 11520, 14400, 16384, 19008, 22080, 25152, 28096, 31296, 34368, 36608, },
+ {3904, 8576, 11904, 14912, 17152, 19776, 22848, 26176, 29376, 32704, 34944, 37184, },
+ {4032, 8832, 12288, 15424, 17664, 20416, 23744, 27200, 30400, 33856, 36352, 38720, },
+ {4160, 9216, 12800, 16064, 18432, 21312, 24640, 28224, 31680, 35264, 37760, 40256, },
+ {4160, 9344, 13056, 16448, 18944, 21952, 25536, 29248, 32704, 35584, 38208, 41664, },
+ {4288, 9728, 13568, 17088, 19584, 22720, 26432, 30272, 33152, 36032, 39616, 43328, },
+ {4288, 9856, 12736, 16384, 20224, 23488, 27328, 31296, 34176, 37184, 40896, 44736, },
+ {4416, 10240, 13120, 16896, 20864, 24128, 28096, 32320, 35328, 38464, 42304, 46144, },
+ {4416, 10368, 13504, 17408, 21504, 25024, 29120, 33344, 36352, 39616, 43584, 47680, },
+ {4544, 10752, 13888, 17920, 22144, 25664, 29888, 34368, 37632, 40896, 44992, 49216, },
+ {4544, 10880, 14144, 18304, 22656, 26304, 30656, 35264, 38656, 42048, 46272, 50624, },
+ {4672, 10304, 13696, 17984, 22464, 27200, 30720, 34496, 38848, 43328, 47680, 52160, },
+ {4800, 10560, 13952, 18368, 22976, 27840, 31488, 35392, 40000, 44608, 49088, 53696, },
+ {4800, 10688, 14336, 18880, 23616, 28736, 32512, 36416, 41024, 45760, 50368, 55232, },
+ {4928, 10944, 14592, 19264, 24128, 29376, 33280, 37312, 42048, 47040, 51776, 56640, },
+ {4928, 11200, 14976, 19776, 24896, 30144, 34048, 38336, 43200, 48192, 53056, 58048, },
+ {5056, 11456, 15360, 20288, 25408, 30912, 34944, 39232, 44352, 49472, 54464, 59712, },
+ {5056, 11584, 15616, 20672, 25920, 31552, 35840, 40256, 45376, 50752, 55872, 61120, },
+ {5184, 11840, 15872, 21056, 26560, 32320, 36608, 41152, 46400, 51904, 57152, 62528, },
+ {5312, 12224, 16384, 21696, 26240, 32128, 37504, 42176, 47552, 53056, 58560, 64192, },
+ {5312, 12352, 16640, 22080, 26752, 32768, 38272, 43072, 48704, 54464, 59968, 65600, },
+ {3968, 11136, 16896, 22464, 27264, 32576, 38336, 44096, 49728, 55616, 61248, 66176, },
+ {3968, 11264, 17280, 22976, 27776, 33216, 39104, 44992, 50752, 56768, 62656, 67712, },
+ {3968, 11520, 17664, 23488, 28544, 33984, 39872, 46016, 51904, 58048, 64064, 69120, },
+ {3968, 11648, 17920, 23872, 29056, 34624, 40640, 46912, 53056, 59328, 64512, 69696, },
+ {4096, 11904, 18304, 24384, 29568, 35264, 41536, 47936, 54080, 60480, 65792, 71104, },
+ {4096, 12032, 18560, 24768, 30080, 35904, 42304, 48832, 55104, 61632, 67200, 72640, },
+ {4096, 12288, 18944, 25280, 30720, 36672, 43200, 49856, 56384, 63040, 68608, 74176, },
+ {4224, 12544, 19328, 25792, 31360, 37440, 43968, 50752, 57408, 64192, 69888, 75584, },
+ {4224, 12672, 19584, 26176, 31872, 38080, 44736, 51648, 58432, 65344, 71168, 76992, },
+ {4224, 12800, 19840, 26560, 32384, 38720, 45632, 52672, 59456, 65664, 71616, 78400, },
+ {4224, 13056, 20352, 27200, 33024, 39360, 46400, 53696, 60736, 66944, 72896, 79808, },
+ {4352, 13312, 20608, 27584, 33536, 40128, 47296, 54592, 60928, 67264, 74304, 81472, },
+ {4352, 13440, 19776, 26880, 34176, 40896, 48064, 55488, 61952, 68416, 75584, 82880, },
+ {4352, 13568, 20032, 27264, 34688, 41536, 48960, 56512, 62976, 69568, 76864, 84288, },
+ {4480, 13952, 20416, 27776, 35328, 42176, 49728, 57536, 64128, 70720, 78144, 85696, },
+ {4480, 14080, 20672, 28160, 35840, 42816, 50496, 58432, 65152, 72000, 79552, 87104, },
+ {4480, 14208, 21056, 28672, 36352, 43584, 51392, 59328, 66176, 73152, 80832, 88640, },
+ {4480, 14336, 21312, 29056, 36992, 44352, 52288, 60352, 67200, 74304, 82112, 90048, },
+ {4608, 14720, 21696, 29568, 37632, 44992, 53056, 61376, 68480, 75584, 83520, 91584, },
+ {4608, 14848, 21952, 29952, 38144, 45632, 53824, 62272, 69504, 76736, 84800, 92992, },
+ {4608, 14976, 22208, 30336, 38656, 46272, 54592, 63168, 70528, 77888, 86080, 94400, },
+ {4608, 15104, 22464, 30720, 39168, 46912, 55360, 64064, 71552, 79040, 87360, 95808, },
+ {4736, 14528, 22016, 30400, 38976, 47808, 55424, 63296, 71744, 80320, 88768, 97344, },
+ {4736, 14656, 22272, 30784, 39488, 48448, 56192, 64192, 72768, 81472, 90048, 98752, },
+ {4736, 14784, 22528, 31168, 40000, 49088, 56960, 65088, 73792, 82624, 91328, 100160, },
+ {4864, 15040, 22784, 31552, 40512, 49728, 57728, 65984, 74944, 83904, 92736, 101696, },
+ {4864, 15168, 23040, 31936, 41152, 50496, 58624, 67008, 75968, 85056, 94016, 103104, },
+ {4864, 15296, 23424, 32448, 41664, 51264, 59520, 67904, 76992, 86208, 95296, 104640, },
+ {4864, 15424, 23680, 32832, 42176, 51904, 60288, 68800, 78016, 87488, 96704, 106048, },
+ {4992, 15680, 23936, 33216, 42688, 52544, 61056, 69696, 79040, 88640, 97984, 107456, },
+ {4992, 15936, 24320, 33728, 43328, 53184, 61824, 70720, 80192, 89792, 99264, 108864, },
+ {4992, 16064, 24576, 34112, 43968, 53952, 62592, 71616, 81216, 90944, 100544, 110272, },
+ {5120, 16320, 24832, 34496, 44480, 54720, 63488, 72512, 82240, 92096, 101952, 111936, },
+ {5120, 16448, 25216, 35008, 44992, 55360, 64256, 73408, 83392, 93376, 103232, 113344, },
+ {5120, 16576, 25472, 35392, 45504, 56000, 65152, 74432, 84416, 94656, 104640, 114752, },
+ {5120, 16704, 25728, 35776, 46016, 56640, 65920, 75328, 85440, 95808, 105920, 116160, },
+ {5248, 16960, 25984, 36160, 46656, 57408, 66688, 76224, 86464, 96960, 107200, 117568, },
+ {5248, 17088, 26240, 36544, 47168, 58048, 67456, 77120, 87488, 98112, 108480, 118976, },
+ {5248, 17344, 26624, 37056, 47808, 58816, 68352, 78144, 88640, 99264, 109888, 120640, },
+ {5376, 17600, 27008, 37568, 47360, 58496, 69120, 79040, 89664, 100416, 111168, 122048, },
+ {5376, 17728, 27264, 37952, 47872, 59136, 69888, 79936, 90816, 101696, 112448, 123456, },
+ {5376, 17856, 27520, 38336, 48384, 59776, 70656, 80832, 91840, 102976, 113856, 124864, },
+ {3904, 16512, 27776, 38720, 48896, 60416, 71424, 81728, 92864, 104128, 115136, 126272, },
+ {4032, 16768, 28032, 39104, 49408, 60224, 71488, 82752, 93888, 105280, 116416, 126848, },
+ {4032, 16896, 28288, 39488, 49920, 60864, 72256, 83648, 94912, 106432, 117696, 128256, },
+ {4032, 17024, 28672, 40000, 50432, 61504, 73024, 84544, 95936, 107584, 119104, 129792, },
+ {4032, 17280, 29056, 40512, 51200, 62272, 73792, 85568, 97088, 108736, 120384, 131200, },
+ {4032, 17408, 29312, 40896, 51712, 62912, 74560, 86464, 98112, 110016, 121792, 132608, },
+ {4032, 17536, 29568, 41280, 52224, 63552, 75328, 87360, 99264, 111296, 123072, 134016, },
+ {4032, 17664, 29824, 41664, 52736, 64192, 76096, 88256, 100288, 112448, 123520, 134592, },
+ {4160, 17920, 30080, 42048, 53248, 64832, 76864, 89152, 101312, 113600, 124800, 136000, },
+ {4160, 18048, 30464, 42560, 53760, 65472, 77760, 90176, 102336, 114752, 126080, 137408, },
+ {4160, 18176, 30720, 42944, 54272, 66112, 78528, 91072, 103360, 115904, 127488, 138944, },
+ {4160, 18304, 30976, 43328, 54784, 66752, 79296, 91968, 104384, 117056, 128768, 140352, },
+ {4160, 18560, 31360, 43840, 55424, 67520, 80192, 92992, 105536, 118336, 130176, 141888, },
+ {4160, 18688, 31616, 44224, 55936, 68160, 80960, 93888, 106688, 119616, 131456, 143296, },
+ {4160, 18816, 32000, 44736, 56576, 68928, 81728, 94784, 107712, 120768, 132736, 144704, },
+ {4288, 19072, 32256, 45120, 57088, 69568, 82496, 95680, 108736, 121920, 134016, 146112, },
+ {4288, 19200, 32512, 45504, 57600, 70208, 83264, 96576, 109760, 123072, 135296, 147520, },
+ {4288, 19328, 32768, 45888, 58112, 70848, 84032, 97472, 110784, 124224, 136576, 148928, },
+ {4288, 19456, 33024, 46272, 58624, 71488, 84928, 98496, 111808, 124544, 137024, 150336, },
+ {4288, 19584, 33280, 46656, 59136, 72128, 85696, 99392, 112832, 125696, 138304, 151744, },
+ {4288, 19840, 33792, 47296, 59776, 72768, 86464, 100416, 113984, 126848, 139584, 153152, },
+ {4288, 19968, 34048, 47680, 60288, 73408, 87232, 101312, 115136, 128128, 140864, 154560, },
+ {4416, 20224, 34304, 48064, 60800, 74176, 88128, 102208, 116160, 129280, 142144, 156096, },
+ {4416, 20352, 34560, 48448, 61312, 74816, 88896, 103104, 116352, 129600, 143552, 157632, },
+ {4416, 20480, 34816, 48832, 61952, 75584, 89664, 104000, 117376, 130752, 144832, 159040, },
+ {4416, 20608, 33984, 48128, 62464, 76224, 90432, 104896, 118400, 131904, 146112, 160448, },
+ {4416, 20736, 34240, 48512, 62976, 76864, 91328, 105920, 119424, 133056, 147392, 161856, },
+ {4416, 20864, 34496, 48896, 63488, 77504, 92096, 106816, 120448, 134208, 148672, 163264, },
+ {4416, 21120, 34880, 49408, 64128, 78144, 92864, 107840, 121600, 135360, 149952, 164672, },
+ {4544, 21376, 35136, 49792, 64640, 78784, 93632, 108736, 122624, 136512, 151232, 166080, },
+ {4544, 21504, 35392, 50176, 65152, 79424, 94400, 109632, 123648, 137664, 152512, 167488, },
+ {4544, 21632, 35648, 50560, 65664, 80064, 95168, 110528, 124672, 138944, 153920, 168896, },
+ {4544, 21760, 36032, 51072, 66176, 80704, 95936, 111424, 125696, 140096, 155200, 170304, },
+ {4544, 21888, 36288, 51456, 66688, 81472, 96832, 112320, 126720, 141248, 156480, 171840, },
+ {4544, 22016, 36544, 51840, 67328, 82240, 97600, 113216, 127744, 142400, 157760, 173248, },
+ {4544, 22144, 36800, 52224, 67840, 82880, 98496, 114240, 128768, 143552, 159040, 174656, },
+ {4672, 22528, 37184, 52736, 68480, 83520, 99264, 115264, 130048, 144832, 160320, 176064, },
+ {4672, 22656, 37440, 53120, 68992, 84160, 100032, 116160, 131072, 145984, 161728, 177600, },
+ {4672, 22784, 37696, 53504, 69504, 84800, 100800, 117056, 132096, 147136, 163008, 179008, },
+ {4672, 22912, 37952, 53888, 70016, 85440, 101568, 117952, 133120, 148288, 164288, 180416, },
+ {4672, 23040, 38208, 54272, 70528, 86080, 102336, 118848, 134144, 149440, 165568, 181824, },
+ {4672, 23168, 38464, 54656, 71040, 86720, 103104, 119744, 135168, 150592, 166848, 183232, },
+ {4672, 23296, 38720, 55040, 71552, 87360, 103872, 120640, 136192, 151744, 168128, 184640, },
+ {4672, 23424, 38976, 55424, 72064, 88000, 104640, 121536, 137216, 152896, 169408, 186048, },
+ };
+
+ for (std::size_t i = 1; i <= FCMP_PLUS_PLUS_MAX_INPUTS; ++i)
+ {
+ // Uncomment the prints to construct the table
+ // printf("{");
+ for (std::size_t j = 1; j <= FCMP_PLUS_PLUS_MAX_LAYERS; ++j)
+ {
+ const std::size_t membership_proof_len = fcmp_pp::membership_proof_len(i, j);
+ const std::size_t fcmp_pp_proof_len = fcmp_pp::fcmp_pp_proof_len(i, j);
+
+ EXPECT_EQ(membership_proof_len, PROOF_LEN_TABLE[i-1][j-1]);
+ EXPECT_EQ(fcmp_pp_proof_len, ::fcmp_pp_proof_size(i, j));
+
+ // printf("%lu, ", membership_proof_len);
+ }
+ // printf("},\n");
+ }
+}
+//----------------------------------------------------------------------------------------------------------------------
+TEST(fcmp_pp, output_serialization)
+{
+ static const crypto::public_key O{0x01};
+ static const crypto::ec_point C{0x02};
+
+ static const std::string O_str = "0100000000000000000000000000000000000000000000000000000000000000";
+ static const std::string C_str = "0200000000000000000000000000000000000000000000000000000000000000";
+
+ // 1. Check serialized bytes size
+ const fcmp_pp::OutputPair legacy_output_pair = fcmp_pp::LegacyOutputPair{{O, C}};
+ const fcmp_pp::OutputPair carrot_output_pair = fcmp_pp::CarrotOutputPairV1{{O, C}};
+ ASSERT_FALSE(legacy_output_pair == carrot_output_pair);
+
+ const cryptonote::blobdata legacy_serialized = cryptonote::t_serializable_object_to_blob(legacy_output_pair);
+ const cryptonote::blobdata carrot_out_v1_ser = cryptonote::t_serializable_object_to_blob(carrot_output_pair);
+
+ ASSERT_EQ(legacy_serialized.size(), (1+32+32));
+ ASSERT_EQ(carrot_out_v1_ser.size(), (1+32+32));
+
+ // 2. Check serialized byte string
+ const std::string legacy_hex = epee::string_tools::buff_to_hex_nodelimer(legacy_serialized);
+ const std::string carrot_hex = epee::string_tools::buff_to_hex_nodelimer(carrot_out_v1_ser);
+
+ static const std::string LEGACY_TAG = "70";
+ static const std::string CARROT_TAG = "71";
+
+ ASSERT_EQ(legacy_hex, LEGACY_TAG + O_str + C_str);
+ ASSERT_EQ(carrot_hex, CARROT_TAG + O_str + C_str);
+
+ // 3. Check de-serialization
+ const std::vector<std::pair<fcmp_pp::OutputPair, cryptonote::blobdata>> op_vec{
+ {legacy_output_pair, legacy_serialized},
+ {carrot_output_pair, carrot_out_v1_ser}
+ };
+
+ for (const auto &serialized : op_vec)
+ {
+ fcmp_pp::OutputPair output;
+ ASSERT_TRUE(::serialization::parse_binary(serialized.second, output));
+ ASSERT_EQ(output, serialized.first);
+ }
+
+ // 4. Check UnifiedOutput
+ const uint64_t output_id = 8321;
+ const fcmp_pp::UnifiedOutput legacy_unified_output{output_id, legacy_output_pair};
+ const fcmp_pp::UnifiedOutput carrot_unified_output{output_id, carrot_output_pair};
+
+ const cryptonote::blobdata legacy_unified_ser = cryptonote::t_serializable_object_to_blob(legacy_unified_output);
+ const cryptonote::blobdata carrot_unified_ser = cryptonote::t_serializable_object_to_blob(carrot_unified_output);
+
+ ASSERT_EQ(legacy_unified_ser.size(), SIZEOF_SERIALIZED_UNIFIED_OUTPUT);
+ ASSERT_EQ(carrot_unified_ser.size(), SIZEOF_SERIALIZED_UNIFIED_OUTPUT);
+
+ const std::string legacy_unified_hex = epee::string_tools::buff_to_hex_nodelimer(legacy_unified_ser);
+ const std::string carrot_unified_hex = epee::string_tools::buff_to_hex_nodelimer(carrot_unified_ser);
+ const std::string outpt_id_hex = epee::string_tools::buff_to_hex_nodelimer(
+ cryptonote::t_serializable_object_to_blob(output_id)
+ );
+
+ ASSERT_EQ(legacy_unified_hex, outpt_id_hex + LEGACY_TAG + O_str + C_str);
+ ASSERT_EQ(carrot_unified_hex, outpt_id_hex + CARROT_TAG + O_str + C_str);
+
+ const std::vector<std::pair<fcmp_pp::UnifiedOutput, cryptonote::blobdata>> unified_vec{
+ {legacy_unified_output, legacy_unified_ser},
+ {carrot_unified_output, carrot_unified_ser}
+ };
+
+ for (const auto &serialized : unified_vec)
+ {
+ fcmp_pp::UnifiedOutput output;
+ ASSERT_TRUE(::serialization::parse_binary(serialized.second, output));
+ ASSERT_EQ(output, serialized.first);
+ }
+}
+//----------------------------------------------------------------------------------------------------------------------
### tests/unit_tests/main.cpp
@@ -42,6 +42,7 @@
#include "string_tools.h"
#include "common/command_line.h"
#include "common/util.h"
+#include "tests_common/fcmp_pp_helpers.h"
#include "unit_tests_utils.h"
namespace po = boost::program_options;
@@ -82,6 +83,7 @@ int main(int argc, char** argv)
// set the test data directory
unit_test::data_dir = command_line::get_arg(vm, arg_data_dir).c_str();
+ tests_common::data_dir = unit_test::data_dir;
// set the log level
if (!command_line::is_arg_defaulted(vm, arg_log_level))Why this scored 25/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.