Skip to content

Commit 8d2833e

Browse files
committed
Merge remote-tracking branch 'secp256k1-zkp-update' into elements-22-fix-ci
2 parents f8add43 + 12b11e3 commit 8d2833e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5881
-1738
lines changed

src/secp256k1/.cirrus.yml

+17-47
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ env:
2323
WHITELIST: no
2424
MUSIG: no
2525
ECDSAADAPTOR: no
26+
BPPP: no
2627
### test options
2728
SECP256K1_TEST_ITERS:
2829
BENCH: yes
@@ -72,12 +73,12 @@ task:
7273
<< : *LINUX_CONTAINER
7374
matrix: &ENV_MATRIX
7475
- env: {WIDEMUL: int64, RECOVERY: yes}
75-
- env: {WIDEMUL: int64, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
76+
- env: {WIDEMUL: int64, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes}
7677
- env: {WIDEMUL: int128}
7778
- env: {WIDEMUL: int128, RECOVERY: yes, SCHNORRSIG: yes}
78-
- env: {WIDEMUL: int128, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
79+
- env: {WIDEMUL: int128, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes}
7980
- env: {WIDEMUL: int128, ASM: x86_64}
80-
- env: { RECOVERY: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes}
81+
- env: { RECOVERY: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes}
8182
- env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no}
8283
- env: {CPPFLAGS: -DDETERMINISTIC}
8384
- env: {CFLAGS: -O0, CTIMETEST: no}
@@ -108,6 +109,7 @@ task:
108109
GENERATOR: yes
109110
MUSIG: yes
110111
ECDSAADAPTOR: yes
112+
BPPP: yes
111113
matrix:
112114
- env:
113115
CC: i686-linux-gnu-gcc
@@ -119,63 +121,29 @@ task:
119121
<< : *CAT_LOGS
120122

121123
task:
122-
name: "x86_64: macOS Catalina"
124+
name: "arm64: macOS Ventura"
123125
macos_instance:
124-
image: catalina-base
126+
image: ghcr.io/cirruslabs/macos-ventura-base:latest
125127
# tasks with valgrind enabled take about 90 minutes
126128
timeout_in: 120m
127129
env:
128130
HOMEBREW_NO_AUTO_UPDATE: 1
129131
HOMEBREW_NO_INSTALL_CLEANUP: 1
130-
# Cirrus gives us a fixed number of 12 virtual CPUs. Not that we even have that many jobs at the moment...
131-
MAKEFLAGS: -j13
132+
# Cirrus gives us a fixed number of 4 virtual CPUs. Not that we even have that many jobs at the moment...
133+
MAKEFLAGS: -j5
132134
matrix:
133135
<< : *ENV_MATRIX
136+
env:
137+
ASM: no
138+
WITH_VALGRIND: no
139+
CTIMETEST: no
134140
matrix:
135141
- env:
136-
CC: gcc-9
142+
CC: gcc
137143
- env:
138144
CC: clang
139-
# Update Command Line Tools
140-
# Uncomment this if the Command Line Tools on the CirrusCI macOS image are too old to brew valgrind.
141-
# See https://apple.stackexchange.com/a/195963 for the implementation.
142-
## update_clt_script:
143-
## - system_profiler SPSoftwareDataType
144-
## - touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
145-
## - |-
146-
## PROD=$(softwareupdate -l | grep "*.*Command Line" | tail -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | sed 's/Label: //g' | tr -d '\n')
147-
## # For debugging
148-
## - softwareupdate -l && echo "PROD: $PROD"
149-
## - softwareupdate -i "$PROD" --verbose
150-
## - rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
151-
##
152-
brew_valgrind_pre_script:
153-
# Retry a few times because this tends to fail randomly.
154-
- for i in {1..5}; do brew update && break || sleep 15; done
155-
- brew config
156-
- brew tap LouisBrunner/valgrind
157-
# Fetch valgrind source but don't build it yet.
158-
- brew fetch --HEAD LouisBrunner/valgrind/valgrind
159-
brew_valgrind_cache:
160-
# This is $(brew --cellar valgrind) but command substition does not work here.
161-
folder: /usr/local/Cellar/valgrind
162-
# Rebuild cache if ...
163-
fingerprint_script:
164-
# ... macOS version changes:
165-
- sw_vers
166-
# ... brew changes:
167-
- brew config
168-
# ... valgrind changes:
169-
- git -C "$(brew --cache)/valgrind--git" rev-parse HEAD
170-
populate_script:
171-
# If there's no hit in the cache, build and install valgrind.
172-
- brew install --HEAD LouisBrunner/valgrind/valgrind
173-
brew_valgrind_post_script:
174-
# If we have restored valgrind from the cache, tell brew to create symlink to the PATH.
175-
# If we haven't restored from cached (and just run brew install), this is a no-op.
176-
- brew link valgrind
177145
brew_script:
178-
- brew install automake libtool gcc@9
146+
- brew install automake libtool gcc
179147
<< : *MERGE_BASE
180148
test_script:
181149
- ./ci/cirrus.sh
@@ -199,6 +167,7 @@ task:
199167
GENERATOR: yes
200168
MUSIG: yes
201169
ECDSAADAPTOR: yes
170+
BPPP: yes
202171
CTIMETEST: no
203172
<< : *MERGE_BASE
204173
test_script:
@@ -293,6 +262,7 @@ task:
293262
GENERATOR: yes
294263
MUSIG: yes
295264
ECDSAADAPTOR: yes
265+
BPPP: yes
296266
CTIMETEST: no
297267
matrix:
298268
- name: "Valgrind (memcheck)"

src/secp256k1/.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
bench
2+
bench_bppp
23
bench_ecmult
34
bench_generator
45
bench_rangeproof
56
bench_internal
7+
bench_whitelist
68
tests
9+
example_musig
710
exhaustive_tests
811
precompute_ecmult_gen
912
precompute_ecmult
@@ -66,4 +69,4 @@ src/stamp-h1
6669
libsecp256k1.pc
6770
contrib/gh-pr-create.sh
6871

69-
musig_example
72+
musig_example

src/secp256k1/Makefile.am

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ clean-precomp:
226226

227227
EXTRA_DIST = autogen.sh SECURITY.md
228228

229+
if ENABLE_MODULE_BPPP
230+
include src/modules/bppp/Makefile.am.include
231+
endif
232+
229233
if ENABLE_MODULE_ECDH
230234
include src/modules/ecdh/Makefile.am.include
231235
endif

src/secp256k1/README.md

+19-68
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,36 @@
1-
libsecp256k1
2-
============
3-
4-
[![Build Status](https://api.cirrus-ci.com/github/bitcoin-core/secp256k1.svg?branch=master)](https://cirrus-ci.com/github/bitcoin-core/secp256k1)
5-
6-
Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1.
7-
8-
This library is intended to be the highest quality publicly available library for cryptography on the secp256k1 curve. However, the primary focus of its development has been for usage in the Bitcoin system and usage unlike Bitcoin's may be less well tested, verified, or suffer from a less well thought out interface. Correct usage requires some care and consideration that the library is fit for your application's purpose.
9-
10-
Features:
11-
* secp256k1 ECDSA signing/verification and key generation.
12-
* Additive and multiplicative tweaking of secret/public keys.
13-
* Serialization/parsing of secret keys, public keys, signatures.
14-
* Constant time, constant memory access signing and public key generation.
15-
* Derandomized ECDSA (via RFC6979 or with a caller provided function.)
16-
* Very efficient implementation.
17-
* Suitable for embedded systems.
18-
* Optional module for public key recovery.
19-
* Optional module for ECDH key exchange.
20-
* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki).
21-
* Optional module for ECDSA adaptor signatures (experimental).
22-
23-
Experimental features have not received enough scrutiny to satisfy the standard of quality of this library but are made available for testing and review by the community. The APIs of these features should not be considered stable.
24-
25-
Implementation details
26-
----------------------
27-
28-
* General
29-
* No runtime heap allocation.
30-
* Extensive testing infrastructure.
31-
* Structured to facilitate review and analysis.
32-
* Intended to be portable to any system with a C89 compiler and uint64_t support.
33-
* No use of floating types.
34-
* Expose only higher level interfaces to minimize the API surface and improve application security. ("Be difficult to use insecurely.")
35-
* Field operations
36-
* Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1).
37-
* Using 5 52-bit limbs (including hand-optimized assembly for x86_64, by Diederik Huys).
38-
* Using 10 26-bit limbs (including hand-optimized assembly for 32-bit ARM, by Wladimir J. van der Laan).
39-
* This is an experimental feature that has not received enough scrutiny to satisfy the standard of quality of this library but is made available for testing and review by the community.
40-
* Scalar operations
41-
* Optimized implementation without data-dependent branches of arithmetic modulo the curve's order.
42-
* Using 4 64-bit limbs (relying on __int128 support in the compiler).
43-
* Using 8 32-bit limbs.
44-
* Modular inverses (both field elements and scalars) based on [safegcd](https://gcd.cr.yp.to/index.html) with some modifications, and a variable-time variant (by Peter Dettman).
45-
* Group operations
46-
* Point addition formula specifically simplified for the curve equation (y^2 = x^3 + 7).
47-
* Use addition between points in Jacobian and affine coordinates where possible.
48-
* Use a unified addition/doubling formula where necessary to avoid data-dependent branches.
49-
* Point/x comparison without a field inversion by comparison in the Jacobian coordinate space.
50-
* Point multiplication for verification (a*P + b*G).
51-
* Use wNAF notation for point multiplicands.
52-
* Use a much larger window for multiples of G, using precomputed multiples.
53-
* Use Shamir's trick to do the multiplication with the public key and the generator simultaneously.
54-
* Use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones.
55-
* Point multiplication for signing
56-
* Use a precomputed table of multiples of powers of 16 multiplied with the generator, so general multiplication becomes a series of additions.
57-
* Intended to be completely free of timing sidechannels for secret-key operations (on reasonable hardware/toolchains)
58-
* Access the table with branch-free conditional moves so memory access is uniform.
59-
* No data-dependent branches
60-
* Optional runtime blinding which attempts to frustrate differential power analysis.
61-
* The precomputed tables add and eventually subtract points for which no known scalar (secret key) is known, preventing even an attacker with control over the secret key used to control the data internally.
1+
libsecp256k1-zkp
2+
================
3+
4+
[![Build Status](https://api.cirrus-ci.com/github/BlockstreamResearch/secp256k1-zkp.svg?branch=master)](https://cirrus-ci.com/github/BlockstreamResearch/secp256k1-zkp)
5+
6+
A fork of [libsecp256k1](https://github.com/bitcoin-core/secp256k1) with support for advanced and experimental features such as Confidential Assets and MuSig2
7+
8+
Added features:
9+
* Experimental module for ECDSA adaptor signatures.
10+
* Experimental module for ECDSA sign-to-contract.
11+
* Experimental module for [MuSig2](src/modules/musig/musig.md).
12+
* Experimental module for Confidential Assets (Pedersen commitments, range proofs, and [surjection proofs](src/modules/surjection/surjection.md)).
13+
* Experimental module for Bulletproofs++ range proofs.
14+
* Experimental module for [address whitelisting](src/modules/whitelist/whitelist.md).
15+
16+
Experimental features are made available for testing and review by the community. The APIs of these features should not be considered stable.
6217

6318
Build steps
6419
-----------
6520

66-
libsecp256k1 is built using autotools:
21+
libsecp256k1-zkp is built using autotools:
6722

6823
$ ./autogen.sh
6924
$ ./configure
7025
$ make
7126
$ make check # run the test suite
7227
$ sudo make install # optional
7328

74-
To compile optional modules (such as Schnorr signatures), you need to run `./configure` with additional flags (such as `--enable-module-schnorrsig`). Run `./configure --help` to see the full list of available flags.
29+
To compile optional modules (such as Schnorr signatures), you need to run `./configure` with additional flags (such as `--enable-module-schnorrsig`). Run `./configure --help` to see the full list of available flags. For experimental modules, you will also need `--enable-experimental` as well as a flag for each individual module, e.g. `--enable-module-musig`.
7530

7631
Usage examples
7732
-----------
7833
Usage examples can be found in the [examples](examples) directory. To compile them you need to configure with `--enable-examples`.
79-
* [ECDSA example](examples/ecdsa.c)
80-
* [Schnorr signatures example](examples/schnorr.c)
81-
* [Deriving a shared secret (ECDH) example](examples/ecdh.c)
82-
To compile the Schnorr signature and ECDH examples, you also need to configure with `--enable-module-schnorrsig` and `--enable-module-ecdh`.
8334

8435
Test coverage
8536
-----------
@@ -105,7 +56,7 @@ To create a HTML report with coloured and annotated source code:
10556

10657
Benchmark
10758
------------
108-
If configured with `--enable-benchmark` (which is the default), binaries for benchmarking the libsecp256k1 functions will be present in the root directory after the build.
59+
If configured with `--enable-benchmark` (which is the default), binaries for benchmarking the libsecp256k1-zkp functions will be present in the root directory after the build.
10960

11061
To print the benchmark result to the command line:
11162

src/secp256k1/ci/cirrus.sh

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ valgrind --version || true
1919
--with-ecmult-gen-precision="$ECMULTGENPRECISION" \
2020
--enable-module-ecdh="$ECDH" --enable-module-recovery="$RECOVERY" \
2121
--enable-module-ecdsa-s2c="$ECDSA_S2C" \
22+
--enable-module-bppp="$BPPP" \
2223
--enable-module-rangeproof="$RANGEPROOF" --enable-module-whitelist="$WHITELIST" --enable-module-generator="$GENERATOR" \
2324
--enable-module-schnorrsig="$SCHNORRSIG" --enable-module-musig="$MUSIG" --enable-module-ecdsa-adaptor="$ECDSAADAPTOR" \
2425
--enable-module-schnorrsig="$SCHNORRSIG" \
@@ -51,6 +52,10 @@ then
5152
$EXEC ./bench_ecmult
5253
$EXEC ./bench_internal
5354
$EXEC ./bench
55+
if [ "$BPPP" = "yes" ]
56+
then
57+
$EXEC ./bench_bppp
58+
fi
5459
} >> bench.log 2>&1
5560
fi
5661

0 commit comments

Comments
 (0)