Skip to content

Commit f8ead0f

Browse files
MariusVanDerWijdenARR4N
authored andcommitted
crypto/secp256k1: update libsecp256k1 (ethereum#31242)
Updates the libsecp256k1 dependency to commit: c0d9480fbbf8eccbd4be23ed27f6f2af6f3b211e PR: ``` BenchmarkSign-24 57756 21214 ns/op 164 B/op 3 allocs/op BenchmarkRecover-24 37156 33044 ns/op 80 B/op 1 allocs/op BenchmarkEcrecoverSignature-24 36889 32935 ns/op 80 B/op 1 allocs/op BenchmarkVerifySignature-24 41163 29207 ns/op 0 B/op 0 allocs/op BenchmarkDecompressPubkey-24 318624 4062 ns/op 304 B/op 6 allocs/op ``` Master: ``` BenchmarkSign-24 34509 35330 ns/op 164 B/op 3 allocs/op BenchmarkRecover-24 25418 47725 ns/op 80 B/op 1 allocs/op BenchmarkEcrecoverSignature-24 25735 47591 ns/op 80 B/op 1 allocs/op BenchmarkVerifySignature-24 29108 41097 ns/op 0 B/op 0 allocs/op BenchmarkDecompressPubkey-24 294747 4143 ns/op 304 B/op 6 allocs/op ``` Performance seems to be improved significantly: ``` Sign-24 34.86µ ± 3% 21.66µ ± 2% -37.86% (p=0.000 n=10) Recover-24 46.14µ ± 3% 33.24µ ± 2% -27.95% (p=0.000 n=10) ```
1 parent 58c0ab3 commit f8ead0f

File tree

191 files changed

+58211
-10117
lines changed

Some content is hidden

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

191 files changed

+58211
-10117
lines changed

crypto/secp256k1/ext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, unsigned char *point,
109109
ARG_CHECK(scalar != NULL);
110110
(void)ctx;
111111

112-
secp256k1_fe_set_b32(&feX, point);
113-
secp256k1_fe_set_b32(&feY, point+32);
112+
secp256k1_fe_set_b32_limit(&feX, point);
113+
secp256k1_fe_set_b32_limit(&feY, point+32);
114114
secp256k1_ge_set_xy(&ge, &feX, &feY);
115115
secp256k1_scalar_set_b32(&s, scalar, &overflow);
116116
if (overflow || secp256k1_scalar_is_zero(&s)) {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
env:
2+
### cirrus config
3+
CIRRUS_CLONE_DEPTH: 1
4+
### compiler options
5+
HOST:
6+
WRAPPER_CMD:
7+
# Specific warnings can be disabled with -Wno-error=foo.
8+
# -pedantic-errors is not equivalent to -Werror=pedantic and thus not implied by -Werror according to the GCC manual.
9+
WERROR_CFLAGS: -Werror -pedantic-errors
10+
MAKEFLAGS: -j4
11+
BUILD: check
12+
### secp256k1 config
13+
ECMULTWINDOW: 15
14+
ECMULTGENKB: 22
15+
ASM: no
16+
WIDEMUL: auto
17+
WITH_VALGRIND: yes
18+
EXTRAFLAGS:
19+
### secp256k1 modules
20+
EXPERIMENTAL: no
21+
ECDH: no
22+
RECOVERY: no
23+
EXTRAKEYS: no
24+
SCHNORRSIG: no
25+
MUSIG: no
26+
ELLSWIFT: no
27+
### test options
28+
SECP256K1_TEST_ITERS: 64
29+
BENCH: yes
30+
SECP256K1_BENCH_ITERS: 2
31+
CTIMETESTS: yes
32+
# Compile and run the tests
33+
EXAMPLES: yes
34+
35+
cat_logs_snippet: &CAT_LOGS
36+
always:
37+
cat_tests_log_script:
38+
- cat tests.log || true
39+
cat_noverify_tests_log_script:
40+
- cat noverify_tests.log || true
41+
cat_exhaustive_tests_log_script:
42+
- cat exhaustive_tests.log || true
43+
cat_ctime_tests_log_script:
44+
- cat ctime_tests.log || true
45+
cat_bench_log_script:
46+
- cat bench.log || true
47+
cat_config_log_script:
48+
- cat config.log || true
49+
cat_test_env_script:
50+
- cat test_env.log || true
51+
cat_ci_env_script:
52+
- env
53+
54+
linux_arm64_container_snippet: &LINUX_ARM64_CONTAINER
55+
env_script:
56+
- env | tee /tmp/env
57+
build_script:
58+
- DOCKER_BUILDKIT=1 docker build --file "ci/linux-debian.Dockerfile" --tag="ci_secp256k1_arm"
59+
- docker image prune --force # Cleanup stale layers
60+
test_script:
61+
- docker run --rm --mount "type=bind,src=./,dst=/ci_secp256k1" --env-file /tmp/env --replace --name "ci_secp256k1_arm" "ci_secp256k1_arm" bash -c "cd /ci_secp256k1/ && ./ci/ci.sh"
62+
63+
task:
64+
name: "ARM64: Linux (Debian stable)"
65+
persistent_worker:
66+
labels:
67+
type: arm64
68+
env:
69+
ECDH: yes
70+
RECOVERY: yes
71+
EXTRAKEYS: yes
72+
SCHNORRSIG: yes
73+
MUSIG: yes
74+
ELLSWIFT: yes
75+
matrix:
76+
# Currently only gcc-snapshot, the other compilers are tested on GHA with QEMU
77+
- env: { CC: 'gcc-snapshot' }
78+
<< : *LINUX_ARM64_CONTAINER
79+
<< : *CAT_LOGS
80+
81+
task:
82+
name: "ARM64: Linux (Debian stable), Valgrind"
83+
persistent_worker:
84+
labels:
85+
type: arm64
86+
env:
87+
ECDH: yes
88+
RECOVERY: yes
89+
EXTRAKEYS: yes
90+
SCHNORRSIG: yes
91+
MUSIG: yes
92+
ELLSWIFT: yes
93+
WRAPPER_CMD: 'valgrind --error-exitcode=42'
94+
SECP256K1_TEST_ITERS: 2
95+
matrix:
96+
- env: { CC: 'gcc' }
97+
- env: { CC: 'clang' }
98+
- env: { CC: 'gcc-snapshot' }
99+
- env: { CC: 'clang-snapshot' }
100+
<< : *LINUX_ARM64_CONTAINER
101+
<< : *CAT_LOGS
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/precomputed_ecmult.c linguist-generated
2+
src/precomputed_ecmult_gen.c linguist-generated
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: "Install Valgrind"
2+
description: "Install Homebrew's Valgrind package and cache it."
3+
runs:
4+
using: "composite"
5+
steps:
6+
- run: |
7+
brew tap LouisBrunner/valgrind
8+
brew fetch --HEAD LouisBrunner/valgrind/valgrind
9+
echo "CI_HOMEBREW_CELLAR_VALGRIND=$(brew --cellar valgrind)" >> "$GITHUB_ENV"
10+
shell: bash
11+
12+
- run: |
13+
sw_vers > valgrind_fingerprint
14+
brew --version >> valgrind_fingerprint
15+
git -C "$(brew --cache)/valgrind--git" rev-parse HEAD >> valgrind_fingerprint
16+
cat valgrind_fingerprint
17+
shell: bash
18+
19+
- uses: actions/cache@v4
20+
id: cache
21+
with:
22+
path: ${{ env.CI_HOMEBREW_CELLAR_VALGRIND }}
23+
key: ${{ github.job }}-valgrind-${{ hashFiles('valgrind_fingerprint') }}
24+
25+
- if: steps.cache.outputs.cache-hit != 'true'
26+
run: |
27+
brew install --HEAD LouisBrunner/valgrind/valgrind
28+
shell: bash
29+
30+
- if: steps.cache.outputs.cache-hit == 'true'
31+
run: |
32+
brew link valgrind
33+
shell: bash
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: 'Run in Docker with environment'
2+
description: 'Run a command in a Docker container, while passing explicitly set environment variables into the container.'
3+
inputs:
4+
dockerfile:
5+
description: 'A Dockerfile that defines an image'
6+
required: true
7+
tag:
8+
description: 'A tag of an image'
9+
required: true
10+
command:
11+
description: 'A command to run in a container'
12+
required: false
13+
default: ./ci/ci.sh
14+
runs:
15+
using: "composite"
16+
steps:
17+
- uses: docker/setup-buildx-action@v3
18+
19+
- uses: docker/build-push-action@v5
20+
id: main_builder
21+
continue-on-error: true
22+
with:
23+
context: .
24+
file: ${{ inputs.dockerfile }}
25+
tags: ${{ inputs.tag }}
26+
load: true
27+
cache-from: type=gha
28+
29+
- uses: docker/build-push-action@v5
30+
id: retry_builder
31+
if: steps.main_builder.outcome == 'failure'
32+
with:
33+
context: .
34+
file: ${{ inputs.dockerfile }}
35+
tags: ${{ inputs.tag }}
36+
load: true
37+
cache-from: type=gha
38+
39+
- # Workaround for https://github.com/google/sanitizers/issues/1614 .
40+
# The underlying issue has been fixed in clang 18.1.3.
41+
run: sudo sysctl -w vm.mmap_rnd_bits=28
42+
shell: bash
43+
44+
- # Tell Docker to pass environment variables in `env` into the container.
45+
run: >
46+
docker run \
47+
$(echo '${{ toJSON(env) }}' | jq -r 'keys[] | "--env \(.) "') \
48+
--volume ${{ github.workspace }}:${{ github.workspace }} \
49+
--workdir ${{ github.workspace }} \
50+
${{ inputs.tag }} bash -c "
51+
git config --global --add safe.directory ${{ github.workspace }}
52+
${{ inputs.command }}
53+
"
54+
shell: bash

0 commit comments

Comments
 (0)