Skip to content

Commit 4e891c4

Browse files
Added MPC-BAM implementation of https://eprint.iacr.org/archive/2024/1950/20250601:081848. Also improved error handling, expanded test suite, fixed spelling
1 parent 7733354 commit 4e891c4

122 files changed

Lines changed: 17260 additions & 2783 deletions

File tree

Some content is hidden

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

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
default:
2-
image: docker.io/ubuntu:20.04
2+
image: registry.gitlab.com/fireblocks/external-docker-images/ubuntu:22.04
33
tags:
4-
- dev-common-runner
4+
- kub-builders
55
before_script:
66
- apt update
77
- DEBIAN_FRONTEND=noninteractive apt install -y build-essential cmake pkg-config uuid-dev libssl-dev libsecp256k1-dev

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.13)
22
project(mpc-lib LANGUAGES C CXX)
33

4+
option(MPC_LIB_BUILD_BENCHMARKS "Build benchmarking targets (requires Google Benchmark)" OFF)
5+
46
set(CMAKE_CXX_STANDARD 17)
57
set(CMAKE_CXX_EXTENSIONS OFF)
68

@@ -16,3 +18,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR} AND NOT MPC_LIB_SKIP_TESTS
1618
enable_testing()
1719
add_subdirectory(test)
1820
endif()
21+
22+
if(MPC_LIB_BUILD_BENCHMARKS)
23+
add_subdirectory(benchmarks)
24+
endif()

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@ To execute the test suite, run the command from the same build folder:
3232
make test
3333
```
3434

35+
### Benchmarks and Profiling
36+
37+
Build the BAM signing benchmark by enabling the benchmark option during configuration:
38+
```sh
39+
cmake -S . -B build -DMPC_LIB_BUILD_BENCHMARKS=ON
40+
cmake --build build --target bam_sign_benchmark
41+
```
42+
43+
Run the benchmark executable to measure `bam_key_sign` throughput (use `--benchmark_filter` to focus on a specific algorithm):
44+
```sh
45+
./build/benchmarks/bam_sign_benchmark --benchmark_filter=stark
46+
```
47+
48+
To profile the benchmark and visualize the results:
49+
1. Record samples with Linux `perf` (install `hotspot` or another viewer once):
50+
```sh
51+
perf record -F 999 -g ./build/benchmarks/bam_sign_benchmark --benchmark_filter=secp256k1_default
52+
```
53+
2. Open the generated `perf.data` in a graphical viewer, e.g.:
54+
```sh
55+
hotspot perf.data # Qt GUI with flame graphs
56+
# or convert to Speedscope
57+
perf script | speedscope
58+
```
59+
3560
## Usage
3661

3762
A few examples for running a full signing process can be found in the [tests section](https://github.com/fireblocks/mpc-lib/tree/main/test/cosigner)

benchmarks/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_executable(bam_sign_benchmark bam_sign_benchmark.cpp)
2+
target_link_libraries(bam_sign_benchmark cosigner uuid)
3+
target_include_directories(bam_sign_benchmark PRIVATE ${CMAKE_SOURCE_DIR}/include)

benchmarks/bam_sign_benchmark.cpp

Lines changed: 314 additions & 0 deletions
Large diffs are not rendered by default.

docker/Dockerfile.bookworm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM debian:bookworm-slim
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update && apt install -y \
6+
build-essential \
7+
uuid-dev \
8+
libssl-dev \
9+
libsecp256k1-dev \
10+
cmake \
11+
&& rm -rf /var/lib/apt/lists/* \
12+
&& rm -rf /var/cache/apt/archives/*
13+
14+
COPY . /usr/src/mpc-lib/
15+
WORKDIR /usr/src/mpc-lib
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:24.04
1+
FROM ubuntu:focal
22

33
ENV DEBIAN_FRONTEND=noninteractive
44

docker/Dockerfile.jammy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:jammy
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update && apt install -y \
6+
build-essential \
7+
uuid-dev \
8+
libssl-dev \
9+
libsecp256k1-dev \
10+
cmake \
11+
&& rm -rf /var/lib/apt/lists/* \
12+
&& rm -rf /var/cache/apt/archives/*
13+
14+
COPY . /usr/src/mpc-lib/
15+
WORKDIR /usr/src/mpc-lib/

docker/run_tests.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515

1616
input_base_name=$(basename ${Dockerfile})
1717
prefix=$(echo ${input_base_name}| awk '{split($0,a,"."); print a[1]}')
18-
tag=$(echo ${input_base_name} | sed "s/^${prefix}\.//" )
18+
tag=$(echo ${input_base_name}| awk '{split($0,a,"."); print a[2]}')
1919

2020
if [ x${prefix} != "xDockerfile" ]; then
2121
echo "Must Select a valid Dockerfile"
@@ -33,11 +33,10 @@ CURRENT_DIR=`pwd`
3333

3434
cd ${SCRIPT_DIR}/..
3535

36-
docker build --network=host -f ${CURRENT_DIR}/${Dockerfile} . -t $IMAGE_NAME
36+
docker build -f ${CURRENT_DIR}/${Dockerfile} . -t $IMAGE_NAME
3737

3838
docker run \
3939
--rm \
40-
--net=host \
4140
${IMAGE_NAME} bash -c "mkdir build_${IMAGE_NAME};cd build_${IMAGE_NAME};cmake ..;make -j && make -j test"
4241

4342
cd -

include/cosigner/asymmetric_eddsa_cosigner.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "cosigner/platform_service.h"
34
#include "cosigner_export.h"
45

56
#include "crypto/ed25519_algebra/ed25519_algebra.h"
@@ -22,22 +23,18 @@ namespace cosigner
2223
{
2324

2425
class cmp_key_persistency;
25-
class platform_service;
26+
class cosigner_verifier_chain;
27+
struct eddsa_signature_data;
28+
struct signing_data;
2629

2730
static constexpr size_t SHA256_HASH_SIZE = 32;
2831
typedef std::array<uint8_t, SHA256_HASH_SIZE> eddsa_commitment;
2932
static_assert(sizeof(eddsa_commitment) == SHA256_HASH_SIZE);
3033

31-
struct Rs_and_commitments
32-
{
33-
std::vector<elliptic_curve_point> Rs;
34-
eddsa_commitment R_commitment;
35-
};
36-
3734
class COSIGNER_EXPORT asymmetric_eddsa_cosigner
3835
{
3936
public:
40-
asymmetric_eddsa_cosigner(platform_service& cosigner_service, const cmp_key_persistency& key_persistency);
37+
asymmetric_eddsa_cosigner(platform_service& service, const cmp_key_persistency& key_persistency);
4138
virtual ~asymmetric_eddsa_cosigner() {}
4239

4340
protected:
@@ -49,7 +46,7 @@ class COSIGNER_EXPORT asymmetric_eddsa_cosigner
4946

5047
platform_service& _service;
5148
const cmp_key_persistency& _key_persistency;
52-
static const std::unique_ptr<elliptic_curve256_algebra_ctx_t, void (*)(elliptic_curve256_algebra_ctx_t*)> _ctx;
49+
std::unique_ptr<elliptic_curve256_algebra_ctx_t, void (*)(elliptic_curve256_algebra_ctx_t*)> _ctx;
5350
};
5451

5552
}

0 commit comments

Comments
 (0)