Skip to content
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

Add host functions to support BLS12-381 #1427

Closed
wants to merge 14 commits into from

Conversation

namankumar
Copy link
Contributor

@namankumar namankumar commented Jan 11, 2024

This CAP proposes adding support for BLS12-381 elliptical curve to enable advanced zero knowledge proof systems including privacy preserving constructions and zkrollups. The Soroban ecosystem has already expressed interest in these type of systems.

Next steps:

  • determine appropriate size for modulus and field elements
  • determine appropriate size, types, and encoding for arguments
  • consider fees
  • consider sample applications to aid ecosystem adoption

Issue: stellar/rs-soroban-env#779
PR (in progress): stellar/rs-soroban-env#1310

#### Addition in G1

```rust
fn bls12_g1add( e: &Host, p0: BLST_G1_POINT, p1: BLST_G1_POINT) -> Result <BLST_G1_POINT, Error>;
Copy link
Contributor

Choose a reason for hiding this comment

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

BLST_G1_POINT is not a type, what is this signature supposed to mean?

While it's probably not important for the discussion, if we want to merge this, we should make it consistent with the host function specifications we have.

https://github.com/stellar/rs-soroban-env/blob/main/soroban-env-common/env.json can be used as a general reference. Some quick notes:

  • There is no need to specify the &Host argument.
  • There is no need to declare the return type as Result, just use the return value
  • There is no u8 type supported; minimal integer type is U32Val.
  • Slices can't be passed to the host functions; use BytesObject instead (the length of the bytes object is just a part of the protocol specification, but can't be reflected in the function signature)

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @dmkozh.
I would suggest following https://github.com/stellar/stellar-protocol/blob/master/core/cap-0046-03.md on host function definition format. The host functions are written in WAT (WebAssembly Text) format because that (not Rust, or Json) is what is exposed to the WASM contracts.

Copy link
Contributor

Choose a reason for hiding this comment

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

While WAT might be ok for bulk definitions we had in the protocol 20, I would prefer to also have a definition in terms of env-common types (used in env.json) - while these functions are not type-checked on the Wasm side, they are type-checked on the host-side, so it would make sense to specify what should be the signature. It is also easier to understand for the reader, which is important given that hopefully future CAPs will be focused on small sets of functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

env.json sounds good, i don't feel strongly either way

Arguments:
p_g1: point in G1(96 bytes)
p_g1: point in G1(192 bytes)
Returns padded 0x01 if pairing is successful else 0x00.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not return Bool instead?

```
Perform addition of two points in G1.
Inputs should be 96 bytes each.
An error will be thrown if neither input is in G1, input has invalid length, or encoding rules are violated.
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't return any errors actually - the host functions just trap in case of an error.

#### Map Base Field Element to G1

```rust
fn bls12_map_fp_to_g1( e: &Host, fp: &[u64]) -> Result <BLST_G1_POINT, Error>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have two variants of the same 'map' function that seemingly take the same input? I think we should only need one version, that either takes a U64Val, or BytesObject, depending on which case is more useful.

```
### Curve Operations

#### Addition in G1
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like there is a lot of redundancy in this interface. E.g. we could reduce the number of functions by 2 times if we take g1/g2 as an input bool parameter to functions instead of having duplicate functions for every operation.

This section describes the composition of the working group.

## Motivation
BLS12-381 host functions allow for cryptographic operations in the Soroban execution environment that are otherwise prohibitively expensive. It enables a variety of applications including confidentiality preserving systems, BLS signature schemes, and multiple types of scaling solutions. Pairing-friendly elliptic curves are needed for such systems and BLS12-381 is the state of the art in secure elliptical curves.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a note about the motivation of using BLS12-381 as opposed to BN254

@rsinha
Copy link

rsinha commented Jan 17, 2024

What are your thoughts on exposing a generic interface for pairing friendly curves? That is, instead of bls12_g1add, you could expose add for curve elements, that is implemented by the individual curve (and similarly for other group operations). This might make it easier to add additional curves in future.

One reference would be the algebraic interfaces defined in arkworks. There is a large family of curves, including 2-chain curves (which have applications to Rollups), that can be exposed via the same interface.

Copy link

This pull request is stale because it has been open for 30 days with no activity. It will be closed in 30 days unless the stale label is removed.

@github-actions github-actions bot added the stale label Feb 17, 2024
@namankumar namankumar deleted the branch stellar:master March 12, 2024 21:11
@namankumar namankumar closed this Mar 12, 2024
@namankumar namankumar deleted the master branch March 12, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants