MPT-Crypto is a specialized C library implementing the cryptographic building blocks for
Confidential Multi-Purpose Tokens (MPT) on the XRP Ledger. It provides implementations of homomorphic encryption, aggregated range proofs, and specialized zero-knowledge proofs.
The library is built on top of libsecp256k1 for elliptic curve arithmetic and OpenSSL for hashing and randomness.
- Additive Homomorphic Encryption: Enables the ledger to aggregate encrypted balances (e.g.,
Enc(A) + Enc(B) = Enc(A+B)) without decryption. - Canonical Zero: Deterministic encryption of zero balances to prevent ledger state bloat and ensure consistency.
-
Aggregated Proofs: Supports proving that
$m$ values are within the range$[0, 2^{64})$ in a single proof with logarithmic size$\mathcal{O}(\log n)$ . - Inner Product Argument (IPA): Implements the standard Bulletproofs IPA for succinct verification.
- Fiat-Shamir: Secure non-interactive challenge generation with strict domain separation.
- Plaintext Equality: Proves two or more ciphertexts encrypt the same amount under different keys.
- Linkage Proof: Proves consistency between an ElGamal ciphertext (used for transfer) and a Pedersen Commitment (used for the range proof).
- Proof of Knowledge (PoK): Proves ownership of the secret key during account registration to prevent rogue key attacks.
Before building, ensure you have the following installed:
- CMake (version 3.10 or higher)
- C Compiler (GCC, Clang, or AppleClang)
- OpenSSL 3.x (development headers and libraries)
On macOS with Homebrew:
brew install cmake openssl@3On Ubuntu/Debian:
sudo apt-get install cmake libssl-dev build-essentialThis library requires libsecp256k1 as a sibling directory. Clone it from the bitcoin-core repository:
# From the parent directory of mpt-crypto
cd ..
git clone https://github.com/bitcoin-core/secp256k1.gitYour directory structure should look like:
Projects/
├── mpt-crypto/
└── secp256k1/
-
Create the build directory and configure:
cd mpt-crypto mkdir -p build && cd build cmake ..
-
Build the library and tests:
make -j4
macOS (Apple Silicon): If you encounter architecture mismatch errors with OpenSSL, explicitly set the architecture:
cmake -DCMAKE_OSX_ARCHITECTURES=arm64 ..macOS (Intel): Use x86_64 instead:
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 ..After building, run the test suite using CTest:
cd build
ctest --output-on-failureOr run individual tests directly:
./tests/test_elgamal
./tests/test_bulletproof_agg
./tests/test_commitmentsThe following tests should pass:
test_bulletproof_agg- Aggregated Bulletproof range proofstest_commitments- Pedersen commitmentstest_elgamal- ElGamal encryption/decryptiontest_elgamal_verify- ElGamal verificationtest_equality_proof- Equality proofstest_ipa- Inner Product Argument (IPA) Core Logictest_link_proof- Linkage proofstest_pok_sk- Proof of knowledge of secret keytest_same_plaintext- Same plaintext proofstest_same_plaintext_multi- Multi-recipient same plaintext proofstest_same_plaintext_multi_shared_r- Shared randomness variant
Note: test_bulletproof.c is excluded from the build because the aggregated implementation (bulletproof_aggregated.c) is fully general; verifying the m=1 case is now covered by test_bulletproof_agg.c.