Skip to content

Conversation

@bigspider
Copy link
Collaborator

@bigspider bigspider commented Mar 11, 2025

Puts a stripped down clone of rust-secp256k1 as an internal library vlib-secp256k1, and uses it as the dependency for vlib-bitcoin library (in turn forked from rust-bitcoin.

rust-secp256k1 is a Rust wrapper of the C-bindings of bitcoin-core's secp256k1 library; however, we can't really use it in Vanadium because we reimplement all the cryptography with ECALLs.

By cloning it and reimplementing the functionality locally using the app-sdk, we can minimize the required adaptations in rust-bitcoin.

This PR adds only a stub of the library, as most functionality is replaced with a todo!(). However, it already removes the internal crate rust-secp256k1-sys and anything related to the FFI interface. That allows removing the C++ compiler from the build pipeline of the bitcoin v-app, which is amazing for the compilation time.

Some features and other functionalities that are not relevant for Vanadium (like the 'recovery', 'ecdh' and 'ellswift' modules, or the Secp256k context), are also removed from vlib-secp256k1. Possibly, even more unused functionality could removed in the future (instead of implementing each and every todo!()).

@bigspider bigspider force-pushed the vlib-secp256k1 branch 2 times, most recently from 097acbe to 478abf7 Compare March 13, 2025 08:30
@bigspider bigspider marked this pull request as ready for review March 13, 2025 08:42
@bigspider bigspider requested a review from Copilot March 13, 2025 08:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an internal, stripped‐down clone of rust‑secp256k1 (named vlib‑secp256k1) and adjusts dependencies so that the bitcoin library now uses this new internal implementation. Key changes include:

  • Introducing a new Cargo.toml and README for vlib‑secp256k1.
  • Adding stub implementations (using todo!()) for various cryptographic methods (ECDSA, schnorr, scalar operations).
  • Updating bitcoin’s dependency to reference the local vlib‑secp256k1 instead of the git‑based rust‑secp256k1.

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated no comments.

Show a summary per file
File Description
libs/secp256k1/Cargo.toml New package configuration for the internal vlib‑secp256k1 library.
libs/secp256k1/README.md New README document for the internal library (contains a typo).
libs/secp256k1/src/ecdsa/mod.rs Added full ECDSA implementation with several stubbed functions.
libs/secp256k1/src/sdk_helpers.rs New helper functions for cryptographic computations using the SDK.
libs/secp256k1/src/context.rs Introduced configurations for signing, verification, and all‑capabilities contexts.
libs/secp256k1/src/ecdsa/serialized_signature.rs New type for handling DER‑serialized signatures without allocations.
libs/secp256k1/src/macros.rs Macros for newtype and pretty‑printing implementations.
libs/secp256k1/src/scalar.rs Scalar type implementation with basic operations and error handling.
libs/secp256k1/src/constants.rs Constants for secp256k1 curve parameters and related crypto values.
libs/secp256k1/src/schnorr.rs Schnorr signature support including (de)serialization and tests.
libs/bitcoin/src/lib.rs Adjusted re‑exports to use the local vlib‑secp256k1 instead of full re‑export.
libs/bitcoin/Cargo.toml Updated dependency settings to use the local vlib‑secp256k1 package.
app-sdk/src/bignum.rs Operator overloads for BigNum/Mod arithmetic using the app‑sdk’s FFI.
app-sdk/src/curve.rs Made Point fields public and added a new is_zero method to help verify the identity element.
app-sdk/src/lib.rs Configured different heap sizes based on target architecture.
.cargo/config.toml (both in secp256k1 & bitcoin) Configured environment for tests (setting RUST_TEST_THREADS).
Comments suppressed due to low confidence (1)

libs/secp256k1/README.md:15

  • The word "starded" appears to be a typo; it should be "started".
This folder starded from a fork of `rust-secp256k1`, at commit [31237ffd604b78baba4a90e35fe8a50c3f48a23b].

Also removed the features related to the Secp256k1 'context'.
Most methods are replaced with a todo!() placeholder.
Added an internal sdk_helpers module to add utility functions that
use the Vanadium app-sdk.
We only export the secp256k1.Secp256k1 type, since most functionality
in this module is not currently implemented.
@bigspider bigspider merged commit e48e3b3 into master Mar 13, 2025
14 checks passed
@bigspider bigspider deleted the vlib-secp256k1 branch March 13, 2025 11:52
nconsigny pushed a commit to nconsigny/vanadium that referenced this pull request Dec 20, 2025
Adds a local clone of rust-secp256k1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants