Skip to content

Commit

Permalink
Refactor some interfaces, compiling, not tested yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
yarkinwho committed Nov 9, 2023
1 parent 71a9319 commit eea0ea3
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 46 deletions.
88 changes: 72 additions & 16 deletions libraries/chain/include/eosio/chain/webassembly/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,17 @@ namespace webassembly {
*/
int32_t bls_g1_add(span<const char> op1, span<const char> op2, span<char> result) const;

/**
* Host function for G1 addition on the elliptic curve bls12-381
*
* @ingroup crypto
* @param op1 - a span containing the first operand G1 point in Montgemory form.
* @param op2 - a span containing the second operand G1 point in Montgemory form.
* @param[out] result - the result op1 + op2 in Montgemory form.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g1_add_mont(span<const char> op1, span<const char> op2, span<char> result) const;

/**
* Host function for G2 addition on the elliptic curve bls12-381
*
Expand All @@ -1808,41 +1819,42 @@ namespace webassembly {
int32_t bls_g2_add(span<const char> op1, span<const char> op2, span<char> result) const;

/**
* Host function for G1 scalar multiplication on the elliptic curve bls12-381
* Host function for G2 addition on the elliptic curve bls12-381
*
* @ingroup crypto
* @param point - a span containing the G1 point operand.
* @param scalar - a span containing the scalar operand.
* @param[out] result - the result: scalar * point.
* @param op1 - a span containing the first operand G2 point in Montgemory form.
* @param op2 - a span containing the second operand G2 point in Montgemory form.
* @param[out] result - the result op1 + op2 in Montgemory form.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g1_mul(span<const char> point, span<const char> scalar, span<char> result) const;
int32_t bls_g2_add_mont(span<const char> op1, span<const char> op2, span<char> result) const;

/**
* Host function for G2 scalar multiplication on the elliptic curve bls12-381
* Host function for G1 weighted sum (multi-exponentiation) on the elliptic curve bls12-381
*
* @ingroup crypto
* @param point - a span containing the G2 point operand.
* @param scalar - a span containing the scalar operand.
* @param[out] result - the result op1 * op2.
* @param points - a span containing a list of G1 points (P0, P1, P2... Pn).
* @param scalars - a span containing a list of scalars (s0, s1, s2... sn).
* @param n - the number of elements in the lists.
* @param[out] result - the result s0 * P0 + s1 * P1 + ... + sn * Pn.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g2_mul(span<const char> point, span<const char> scalar, span<char> result) const;
int32_t bls_g1_weighted_sum(span<const char> points, span<const char> scalars, const uint32_t n, span<char> result) const;

/**
* Host function for G1 multi-exponentiation on the elliptic curve bls12-381
* Host function for G1 weighted sum (multi-exponentiation) on the elliptic curve bls12-381
*
* @ingroup crypto
* @param points - a span containing a list of G1 points (P0, P1, P2... Pn).
* @param points - a span containing a list of G1 points (P0, P1, P2... Pn) in Montgemory form.
* @param scalars - a span containing a list of scalars (s0, s1, s2... sn).
* @param n - the number of elements in the lists.
* @param[out] result - the result s0 * P0 + s1 * P1 + ... + sn * Pn.
* @param[out] result - the result s0 * P0 + s1 * P1 + ... + sn * Pn in Montgemory form.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g1_exp(span<const char> points, span<const char> scalars, const uint32_t n, span<char> result) const;
int32_t bls_g1_weighted_sum_mont(span<const char> points, span<const char> scalars, const uint32_t n, span<char> result) const;

/**
* Host function for G2 multi-exponentiation on the elliptic curve bls12-381
* Host function for G2 weighted sum (multi-exponentiation) on the elliptic curve bls12-381
*
* @ingroup crypto
* @param points - a span containing a list of G2 points (P0, P1, P2... Pn).
Expand All @@ -1851,7 +1863,19 @@ namespace webassembly {
* @param[out] result - the result s0 * P0 + s1 * P1 + ... + sn * Pn.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g2_exp(span<const char> points, span<const char> scalars, const uint32_t n, span<char> result) const;
int32_t bls_g2_weighted_sum(span<const char> points, span<const char> scalars, const uint32_t n, span<char> result) const;

/**
* Host function for G2 weighted sum (multi-exponentiation) on the elliptic curve bls12-381
*
* @ingroup crypto
* @param points - a span containing a list of G2 points (P0, P1, P2... Pn) in Montgemory form.
* @param scalars - a span containing a list of scalars (s0, s1, s2... sn).
* @param n - the number of elements in the lists.
* @param[out] result - the result s0 * P0 + s1 * P1 + ... + sn * Pn in Montgemory form.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g2_weighted_sum_mont(span<const char> points, span<const char> scalars, const uint32_t n, span<char> result) const;

/**
* Host function to calculate the pairing of (G1, G2) pairs on the elliptic curve bls12-381
Expand All @@ -1865,6 +1889,18 @@ namespace webassembly {
*/
int32_t bls_pairing(span<const char> g1_points, span<const char> g2_points, const uint32_t n, span<char> result) const;

/**
* Host function to calculate the pairing of (G1, G2) pairs on the elliptic curve bls12-381
*
* @ingroup crypto
* @param g1_points - a span containing a list of G1 points (P0, P1, P2... Pn) in Montgemory form.
* @param g2_points - a span containing a list of G2 points (P0, P1, P2... Pn) in Montgemory form.
* @param n - the number of elements in the lists.
* @param[out] result - the result e(g1_0, g2_0) * e(g1_1, g2_1) * ... * e(g1_n, g2_n) in Montgemory form.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_pairing_mont(span<const char> g1_points, span<const char> g2_points, const uint32_t n, span<char> result) const;

/**
* Host function for mapping fp to G1 on the elliptic curve bls12-381
*
Expand All @@ -1875,6 +1911,16 @@ namespace webassembly {
*/
int32_t bls_g1_map(span<const char> e, span<char> result) const;

/**
* Host function for mapping fp to G1 on the elliptic curve bls12-381
*
* @ingroup crypto
* @param e - a span containing the field element fp to be mapped in Montgemory form.
* @param[out] result - the resulting element in G1 in Montgemory form.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g1_map_mont(span<const char> e, span<char> result) const;

/**
* Host function for mapping fp2 to G2 on the elliptic curve bls12-381
*
Expand All @@ -1885,6 +1931,16 @@ namespace webassembly {
*/
int32_t bls_g2_map(span<const char> e, span<char> result) const;

/**
* Host function for mapping fp2 to G2 on the elliptic curve bls12-381
*
* @ingroup crypto
* @param e - a span containing the field element fp2 to be mapped in Montgemory form.
* @param[out] result - the resulting element in G2 in Montgemory form.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g2_map_mont(span<const char> e, span<char> result) const;

/**
* Host function for modular reduction of 64 bytes wide scalar to a field element (fp, 48 bytes) of the elliptic curve bls12-381
* Involves Montgomery conversion on the resulting field element.
Expand Down
Loading

0 comments on commit eea0ea3

Please sign in to comment.