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

BLS12-381 Crypto Primitives #154

Merged
merged 13 commits into from
Jul 18, 2023
Merged

Conversation

mschoenebeck
Copy link
Contributor

@mschoenebeck mschoenebeck commented Apr 22, 2023

This is the corresponding cdt pull request to 1071 of leap. Enable the following types and host functions for smart contracts.

Added the following types to cdt:

capi_bls_scalar  = uint8_t data[32];
capi_bls_fp      = uint8_t data[48];
capi_bls_fp2     = uint8_t data[96];
capi_bls_g1      = uint8_t data[144];
capi_bls_g2      = uint8_t data[288];
capi_bls_gt      = uint8_t data[576];

Added the following host functions to cdt (according to https://eips.ethereum.org/EIPS/eip-2537):

bls_g1_add(capi_bls_g1 op1, capi_bls_g1 op2, capi_bls_g1 result);
bls_g2_add(capi_bls_g2 op1, capi_bls_g2 op2, capi_bls_g2 result);
bls_g1_mul(capi_bls_g1 point, capi_bls_scalar scalar, bls_g1 result);
bls_g2_mul(capi_bls_g2 point, capi_bls_scalar scalar, bls_g2 result);
bls_g1_exp(capi_bls_g1[] points, capi_bls_scalar[] scalars, capi_bls_g1 result);
bls_g2_exp(capi_bls_g2[] points, capi_bls_scalar[] scalars, capi_bls_g2 result);
bls_pairing(capi_bls_g1[] g1_points, capi_bls_g2[] g2_points, capi_bls_gt result);
bls_g1_map(capi_bls_fp e, capi_bls_g1 result);
bls_g2_map(capi_bls_fp2 e, capi_bls_g2 result);
bls_fp_mod(std::array<uint8_t, 64> s, capi_bls_fp result);

Check out mschoenebeck/aggsigtest for a sample contract using those new host functions.

Copy link
Contributor

@dimas1185 dimas1185 left a comment

Choose a reason for hiding this comment

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

please add integration tests.
need to do the following:
add test contract to the tests/unit/test_contracts that calls every bls function
add this test to the 'tests/integration/contracts.hpp.in'
add integration test to the 'tests/integration' that is using this contract to check that all actions work properly

}
}

int32_t bls_g1_add(const uint8_t* op1, const uint8_t* op2, uint8_t* res)
Copy link
Contributor

@dimas1185 dimas1185 Jun 29, 2023

Choose a reason for hiding this comment

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

what about something like this? that way you can enforce structure size:

using some_type = uint8_t[144];
    int32_t bls_g1_add(const some_type& op1, const some_type& op2, some_type& res)

Copy link
Contributor Author

@mschoenebeck mschoenebeck Jun 30, 2023

Choose a reason for hiding this comment

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

Added bls types to enforce correct operand sizes in: mschoenebeck@9d1424d

Edit: Updated https://github.com/mschoenebeck/aggsigtest/blob/main/aggsigtest.cpp as well.

@mschoenebeck
Copy link
Contributor Author

Added integration tests for all bls primitives in: mschoenebeck@7a6dfcb

@spoonincode
Copy link
Member

The integration tests are not passing because the leap-dev.deb being used is from 4.0, which of course will not have support for the new bls host functions,

- name: Download leap-dev.deb (Ubuntu 20 only)
if: matrix.platform == 'ubuntu20'
uses: AntelopeIO/asset-artifact-download-action@v2
with:
owner: AntelopeIO
repo: leap
file: 'leap-dev.*(x86_64|amd64).deb'
target: 4.0
artifact-name: leap-dev-ubuntu20-amd64
container-package: experimental-binaries
token: ${{github.token}}

If we'd like to see the tests pass here (and continue to pass post merge), we need to switch the leap-dev.deb over to one from leap's BLS PR. Sadly since it's a fork, referencing it by branch won't work, but I'm pretty sure using

   target: 90071617799738820350538f632ca5d5fd54e5e8

will work (this is the head of AntelopeIO/leap#1071 at the moment)

Once AntelopeIO/leap#1071 is merged in to leap's main, the above will need to become

   target: main

until 5.0 is cut, at which point it can then be changed to

   target: 5

@arhag arhag changed the base branch from main to bls_integration July 18, 2023 18:15
Copy link
Member

@arhag arhag left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me. There are some small tweaks the ENF will do including getting the CI to fully pass. But we are good as it is to merge this into the bls_integraton branch.

@arhag arhag merged commit b540790 into AntelopeIO:bls_integration Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants