-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bp++: Rangeproof PR #207
Open
sanket1729
wants to merge
22
commits into
BlockstreamResearch:master
Choose a base branch
from
sanket1729:bpp_final
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Bp++: Rangeproof PR #207
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
005ffbf
Drop this commit later: DO NOT MERGE
sanket1729 021df62
Revert "scalar: Remove unused secp256k1_scalar_chacha20"
sanket1729 2e2c3cd
Remove bppp_generators parse and serialize APIs
sanket1729 3350782
Relax generator len requirements to be exact n_len + l_len
sanket1729 8db2c3a
Fixup broken test for bppp_parse_one_of_points
sanket1729 5ec0f4a
Prepare of bulletproofs++ rangeproof implementation
sanket1729 afc5291
Add initial commitment data function for rangeproofs
sanket1729 79faa0c
Use asset generator base point instead of G.
sanket1729 662949b
Update generator serialization to have h0 = G
sanket1729 09665c8
Comment out one test case. This fails because of hacky serialization and
sanket1729 1cb5b94
make one ecmult_multi out of two
jonasnick cf08bd5
Fixup h0 serializtion etc
sanket1729 15cee83
Add BP++ round 1
sanket1729 5a1d01c
BP++ prover round 2
sanket1729 5b1017f
BP++ prover round 3
sanket1729 309dcbe
Prover round 4: Norm proof argument
sanket1729 0798cdc
Add BP++ prover
sanket1729 bcf6943
Add BP++ verifier
sanket1729 2d31ff7
Expose BP++ Apis
sanket1729 34d9d81
Add rangeproof unit tests
sanket1729 3353799
Add benchmarks
sanket1729 2c5084e
Fixup: test CI
sanket1729 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,18 @@ extern "C" { | |
|
||
#include <stdint.h> | ||
|
||
#include "secp256k1_generator.h" | ||
|
||
/** Opaque structure representing a large number of NUMS generators */ | ||
typedef struct secp256k1_bppp_generators secp256k1_bppp_generators; | ||
|
||
/** Opaque structure representing a prover context used in bulletproofs++ prover */ | ||
typedef struct secp256k1_bppp_rangeproof_prover_context secp256k1_bppp_rangeproof_prover_context; | ||
|
||
/** Allocates and initializes a list of NUMS generators. | ||
* Returns a list of generators, or calls the error callback if the allocation fails. | ||
* Args: ctx: pointer to a context object | ||
* n: number of NUMS generators to produce. | ||
* | ||
* TODO: In a followup range-proof PR, this is would still require 16 + 8 = 24 NUMS | ||
* points. We will later use G = H0(required for compatibility with pedersen_commitment DS) | ||
* in a separate commit to make review easier. | ||
*/ | ||
SECP256K1_API secp256k1_bppp_generators *secp256k1_bppp_generators_create( | ||
const secp256k1_context *ctx, | ||
|
@@ -43,11 +44,9 @@ SECP256K1_API secp256k1_bppp_generators *secp256k1_bppp_generators_parse( | |
* Args: ctx: pointer to a context object | ||
* gen: pointer to the generator set to be serialized | ||
* Out: data: pointer to buffer into which the generators will be serialized | ||
* In/Out: data_len: the length of the `data` buffer. Should be at least | ||
* k = 33 * num_gens. Will be set to k on successful return | ||
* | ||
* TODO: For ease of review, this setting G = H0 is not included in this commit. We will | ||
* add it in the follow-up rangeproof PR. | ||
* In/Out: data_len: the length of the `data` buffer. Should be initially set to at | ||
* least 33 times the number of generators plus one(33 * (num_gens - 1)). | ||
* Upon success, data_len will be set to the (33 * (num_gens - 1)). | ||
*/ | ||
SECP256K1_API int secp256k1_bppp_generators_serialize( | ||
const secp256k1_context *ctx, | ||
|
@@ -66,6 +65,97 @@ SECP256K1_API void secp256k1_bppp_generators_destroy( | |
secp256k1_bppp_generators *gen | ||
) SECP256K1_ARG_NONNULL(1); | ||
|
||
/** Returns the serialized size of an bulletproofs++ proof of a given number | ||
* of bits and the base. Both base and n_bits must be a power of two. The number | ||
* of digits required to represent number of bits in the given base must also be | ||
* a power of two. Specifically, all of n_bits, base and num_digits = (n_bits / log2(base)) | ||
* must all be a power of two. | ||
* Args: ctx: pointer to a context object | ||
* Out: len: 0 if the parameters and num_digits (n_bits/log2(base)) are not a power of two | ||
* length of the serialized proof otherwise | ||
* In: n_bits: number of bits to prove (max 64, should usually be 64) | ||
* base: base representation to be used in proof construction (max 256, recommended 16) | ||
*/ | ||
SECP256K1_API size_t secp256k1_bppp_rangeproof_proof_length( | ||
const secp256k1_context* ctx, | ||
size_t n_bits, | ||
size_t base | ||
) SECP256K1_ARG_NONNULL(1); | ||
|
||
/** Produces a Bulletproofs++ rangeproof. Returns 1 on success, 0 on failure. | ||
* Proof creation can only fail if the arguments are invalid. The documentation | ||
* below specifies the constraints on inputs and arguments under which this API | ||
* can fail. | ||
* Args: ctx: pointer to a context object | ||
* scratch: pointer to a scratch space | ||
* gens: pointer to the generator set to use, which must have exactly | ||
* `n = max(num_digits, base) + 7` generators, where num_digits is the number. | ||
* asset_gen: pointer to the asset generator for the Pedersen/CT commitment | ||
* Out: proof: pointer to a byte array to output the proof into | ||
* In/Out: plen: pointer to the size of the above array; will be set to the actual size of | ||
* the serialized proof. To learn this value in advance, to allocate a sufficient | ||
* buffer, call `secp256k1_bppp_rangeproof_proof_length` | ||
* In: n_bits: size of range being proven, in bits. Must be a power of two, | ||
* and at most 64. | ||
* base: base representation to be used in proof construction. Must be a power of two, | ||
* value: value committed in the Pedersen commitment. Must be less | ||
* than 2^n_bits. | ||
* min_value: minimum value of the range being proven. Must be less than value | ||
* commit: the Pedersen commitment being proven | ||
* blind: blinding factor for the Pedersen commitment. Must be a 32 byte | ||
* valid scalar within secp curve order. | ||
* nonce: seed for the RNG used to generate random data during proving | ||
* extra_commit: arbitrary extra data that the proof commits to (may be NULL if extra_commit_len is 0) | ||
* extra_commit_len: length of the arbitrary extra data. | ||
*/ | ||
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_bppp_rangeproof_prove( | ||
const secp256k1_context* ctx, | ||
secp256k1_scratch_space *scratch, | ||
const secp256k1_bppp_generators* gens, | ||
const secp256k1_generator* asset_gen, | ||
unsigned char* proof, | ||
size_t* plen, | ||
const size_t n_bits, | ||
const size_t base, | ||
const uint64_t value, | ||
const uint64_t min_value, | ||
const secp256k1_pedersen_commitment* commit, | ||
const unsigned char* blind, | ||
const unsigned char* nonce, | ||
const unsigned char* extra_commit, | ||
size_t extra_commit_len | ||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(11) SECP256K1_ARG_NONNULL(12) SECP256K1_ARG_NONNULL(13); | ||
|
||
/** Verifies an Bulletproofs++ rangeproof. Returns 1 on success, 0 on failure. | ||
* Args: ctx: pointer to a context object | ||
* scratch: pointer to a scratch space | ||
* gens: pointer to the generator set to use, which must have at least 2*n_bits generators | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* asset_gen: pointer to the asset generator for the CT commitment | ||
* In: proof: pointer to a byte array containing the serialized proof | ||
* plen: length of the serialized proof | ||
* n_bits: size of range being proven, in bits. Must be a power of two, | ||
* and at most 64. | ||
* base: base representation to be used in proof construction. Must be a power of two, | ||
* min_value: minimum value of the range being proven | ||
* commit: the Pedersen commitment being proven | ||
* extra_commit: arbitrary extra data that the proof commits to (may be NULL if extra_commit_len is 0) | ||
* extra_commit_len: length of the arbitrary extra data | ||
*/ | ||
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_bppp_rangeproof_verify( | ||
const secp256k1_context* ctx, | ||
secp256k1_scratch_space *scratch, | ||
const secp256k1_bppp_generators* gens, | ||
const secp256k1_generator* asset_gen, | ||
const unsigned char* proof, | ||
const size_t plen, | ||
const uint64_t n_bits, | ||
const uint64_t base, | ||
const uint64_t min_value, | ||
const secp256k1_pedersen_commitment* commit, | ||
const unsigned char* extra_commit, | ||
size_t extra_commit_len | ||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(10); | ||
|
||
# ifdef __cplusplus | ||
} | ||
# endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"num_digits is the number." -> "num_digits is
floor(log_base(value)) + 1
?