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

C bindings for verkle #477

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions constantine/commitments/eth_verkle_ipa.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import
constantine/math/io/io_fields,
constantine/platforms/[abstractions, views]

import constantine/zoo_exports

const prefix_ipa = "ctt_eth_verkle_"

## ############################################################
##
## Inner Product Arguments
Expand Down Expand Up @@ -139,7 +143,7 @@ func innerProduct[F](r: var F, a, b: distinct(View[F] or MutableView[F])) =
func ipa_commit*[N: static int, EC, F](
crs: PolynomialEval[N, EC],
r: var EC,
poly: PolynomialEval[N, F]) =
poly: PolynomialEval[N, F]) {.libPrefix: prefix_ipa.} =
Copy link
Owner

Choose a reason for hiding this comment

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

This is not the proper level of exports as this is a generic procedure.

Export should happen at fully specified protocol level (i.e. curve, field, hash functions, N: static int input sizes are known).

In this case, this means having proper instantiated ipa_commit here:

# TODO: proper IPA wrapper for https://github.com/status-im/nim-eth-verkle
#
# For now we reexport
# - eth_verkle_ipa
# - sha256 for transcripts
export eth_verkle_ipa
export hashes

and tagging those with libPrefix.

Copy link
Author

@Richa-iitr Richa-iitr Oct 20, 2024

Choose a reason for hiding this comment

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

is there any example of a wrapper i can follow to understand?
If i am not wrong something like this

func mapToScalarField*(res: var Fr[Banderwagon], p: EC_TwEdw[Fp[Banderwagon]]): bool {.discardable.} =
## This function takes the x/y value from the above function as Fp element
## and convert that to bytes in Big Endian,
## and then load that to a Fr element
##
## Spec : https://hackmd.io/wliPP_RMT4emsucVuCqfHA?view#MapToFieldElement
var baseField: Fp[Banderwagon]
var baseFieldBytes: array[32, byte]
baseField.mapToBaseField(p) # compute the defined mapping
let check1 = baseFieldBytes.marshalBE(baseField) # Fp -> bytes
let check2 = res.unmarshalBE(baseFieldBytes) # bytes -> Fr
return check1 and check2
can be exported directly?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, anything with generics cannot be exported and need a concretely typed wrapper.

crs.pedersen_commit(r, poly)

func ipa_prove*[N, logN: static int, EcAff, F](
Expand Down Expand Up @@ -330,7 +334,7 @@ func ipa_verify*[N, logN: static int, EcAff, F](
commitment: EcAff,
opening_challenge: F,
eval_at_challenge: F,
proof: IpaProof[logN, EcAff, F]): bool =
proof: IpaProof[logN, EcAff, F]): bool {.libPrefix: prefix_ipa.} =
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

# We want to check ∑ᵢ[uᵢ]Lᵢ + C' + ∑ᵢ[uᵢ⁻¹]Rᵢ = a₀G₀ + [a₀.b₀]Q
# ∑ᵢ[uᵢ]Lᵢ + C' + ∑ᵢ[uᵢ⁻¹]Rᵢ = a₀G₀ + [a₀.b₀]Q
# with
Expand Down Expand Up @@ -661,7 +665,7 @@ func ipa_multi_prove*[N, logN: static int, EcAff, F](
proof: var IpaMultiProof[logN, EcAff, F],
polys: openArray[PolynomialEval[N, F]],
commitments: openArray[EcAff],
opening_challenges_in_domain: openArray[SomeUnsignedInt]) =
opening_challenges_in_domain: openArray[SomeUnsignedInt]) {.libPrefix: prefix_ipa.} =
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

## Create a combined proof that
## allow verifying the list of triplets
## (polynomial, commitment, opening challenge)
Expand Down Expand Up @@ -838,7 +842,7 @@ func ipa_multi_verify*[N, logN: static int, EcAff, F](
commitments: openArray[EcAff],
opening_challenges_in_domain: openArray[SomeUnsignedInt],
evals_at_challenges: openArray[F],
proof: IpaMultiProof[logN, EcAff, F]): bool =
proof: IpaMultiProof[logN, EcAff, F]): bool {.libPrefix: prefix_ipa.} =
Copy link
Owner

Choose a reason for hiding this comment

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

ditto

## Batch verification of commitments to multiple polynomials
## using a single multiproof
##
Expand Down
16 changes: 9 additions & 7 deletions constantine/ethereum_verkle_ipa.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import
./serialization/endians,
./math/io/[io_bigints, io_fields]

import ./zoo_exports

const EthVerkleSeed* = "eth_verkle_oct_2021"

func generate_random_points*(r: var openArray[EC_TwEdw_Aff[Fp[Banderwagon]]]) =
Expand Down Expand Up @@ -149,7 +151,7 @@ type

func serialize*(dst: var EthVerkleIpaProofBytes,
src: IpaProof[8, EC_TwEdw[Fp[Banderwagon]], Fr[Banderwagon]]
): cttEthVerkleIpaStatus {.discardable.} =
): cttEthVerkleIpaStatus {.libPrefix: prefix_ipa, discardable.} =
# Note: We store 1 out of 2 coordinates of an EC point, so size(Fp[Banderwagon])
const fpb = sizeof(Fp[Banderwagon])
const frb = sizeof(Fr[Banderwagon])
Expand All @@ -168,7 +170,7 @@ func serialize*(dst: var EthVerkleIpaProofBytes,
return cttEthVerkleIpa_Success

func deserialize*(dst: var EthVerkleIpaProof,
src: EthVerkleIpaProofBytes): cttEthVerkleIpaStatus =
src: EthVerkleIpaProofBytes): cttEthVerkleIpaStatus {.libPrefix: prefix_ipa, discardable.} =

const fpb = sizeof(Fp[Banderwagon])
const frb = sizeof(Fr[Banderwagon])
Expand All @@ -188,7 +190,7 @@ func deserialize*(dst: var EthVerkleIpaProof,

func serialize*(dst: var EthVerkleIpaMultiProofBytes,
src: IpaMultiProof[8, EC_TwEdw[Fp[Banderwagon]], Fr[Banderwagon]]
): cttEthVerkleIpaStatus {.discardable.} =
): cttEthVerkleIpaStatus {.libPrefix: prefix_ipa, discardable.} =

const frb = sizeof(Fr[Banderwagon])
let D = cast[ptr array[frb, byte]](dst.addr)
Expand All @@ -200,7 +202,7 @@ func serialize*(dst: var EthVerkleIpaMultiProofBytes,

func deserialize*(dst: var EthVerkleIpaMultiProof,
src: EthVerkleIpaMultiProofBytes
): cttEthVerkleIpaStatus =
): cttEthVerkleIpaStatus {.libPrefix: prefix_ipa.} =

const frb = sizeof(Fr[Banderwagon])
let D = cast[ptr array[frb, byte]](src.unsafeAddr)
Expand All @@ -215,7 +217,7 @@ func deserialize*(dst: var EthVerkleIpaMultiProof,
# TODO: refactor, this shouldn't use curves_primitives but internal functions
import ./lowlevel_fields

func mapToBaseField*(dst: var Fp[Banderwagon],p: EC_TwEdw[Fp[Banderwagon]]) =
func mapToBaseField*(dst: var Fp[Banderwagon],p: EC_TwEdw[Fp[Banderwagon]]) {.libPrefix: prefix_ipa, discardable.} =
Richa-iitr marked this conversation as resolved.
Show resolved Hide resolved
## The mapping chosen for the Banderwagon Curve is x/y
##
## This function takes a Banderwagon element & then
Expand All @@ -227,7 +229,7 @@ func mapToBaseField*(dst: var Fp[Banderwagon],p: EC_TwEdw[Fp[Banderwagon]]) =
invY.inv(p.y) # invY = 1/Y
dst.prod(p.x, invY) # dst = (X) * (1/Y)

func mapToScalarField*(res: var Fr[Banderwagon], p: EC_TwEdw[Fp[Banderwagon]]): bool {.discardable.} =
func mapToScalarField*(res: var Fr[Banderwagon], p: EC_TwEdw[Fp[Banderwagon]]): bool {.libPrefix: prefix_ipa, discardable.} =
## This function takes the x/y value from the above function as Fp element
## and convert that to bytes in Big Endian,
## and then load that to a Fr element
Expand All @@ -246,7 +248,7 @@ func mapToScalarField*(res: var Fr[Banderwagon], p: EC_TwEdw[Fp[Banderwagon]]):

func batchMapToScalarField*(
res: var openArray[Fr[Banderwagon]],
points: openArray[EC_TwEdw[Fp[Banderwagon]]]): bool {.discardable, noinline.} =
points: openArray[EC_TwEdw[Fp[Banderwagon]]]): bool {.libPrefix: prefix_ipa, discardable, noinline.} =
## This function performs the `mapToScalarField` operation
## on a batch of points
##
Expand Down
228 changes: 228 additions & 0 deletions include/constantine/protocols/ethereum_verkle_ipa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
/** Constantine
* Copyright (c) 2018-2019 Status Research & Development GmbH
* Copyright (c) 2020-Present Mamy André-Ratsimbazafy
* Licensed and distributed under either of
* * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
* * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
* at your option. This file may not be copied, modified, or distributed except according to those terms.
*/
#ifndef __CTT_H_ETHEREUM_VERKLE_IPA__
#define __CTT_H_ETHEREUM_VERKLE_IPA__

#include "constantine/core/datatypes.h"
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum __attribute__((__packed__)) {
cttEthVerkleIpa_Success,
cttEthVerkleIpa_VerificationFailure,
cttEthVerkleIpa_InputsLengthsMismatch,
cttEthVerkleIpa_ScalarZero,
cttEthVerkleIpa_ScalarLargerThanCurveOrder,
cttEthVerkleIpa_EccInvalidEncoding,
cttEthVerkleIpa_EccCoordinateGreaterThanOrEqualModulus,
cttEthVerkleIpa_EccPointNotOnCurve,
cttEthVerkleIpa_EccPointNotInSubGroup
} ctt_eth_verkle_ipa_status;

static const char* ctt_eth_verkle_ipa_status_to_string(ctt_eth_verkle_ipa_status status) {
static const char* const statuses[] = {
"cttEthVerkleIpa_Success",
"cttEthVerkleIpa_VerificationFailure",
"cttEthVerkleIpa_InputsLengthsMismatch",
"cttEthVerkleIpa_ScalarZero",
"cttEthVerkleIpa_ScalarLargerThanCurveOrder",
"cttEthVerkleIpa_EccInvalidEncoding",
"cttEthVerkleIpa_EccCoordinateGreaterThanOrEqualModulus",
"cttEthVerkleIpa_EccPointNotOnCurve",
"cttEthVerkleIpa_EccPointNotInSubGroup"
};
size_t length = sizeof statuses / sizeof *statuses;
if (0 <= status && status < length) {
return statuses[status];
}
return "cttEthVerkleIpa_InvalidStatusCode";
}

// Opaque types for Nim-defined types
typedef struct Fr Fr;
typedef struct Banderwagon Banderwagon;
typedef struct EC_TwEdw EC_TwEdw;
typedef struct Fp Fp;
Copy link
Owner

Choose a reason for hiding this comment

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

All the fields and curves related struct should be defined in constantine/include/constantine/curves/banderwagon.h

This would be similar to pallas and vesta as they don't use pairings:

type
bn254_snarks_fr = Fr[BN254_Snarks]
bn254_snarks_fp = Fp[BN254_Snarks]
bn254_snarks_fp2 = Fp2[BN254_Snarks]
bn254_snarks_g1_aff = EC_ShortW_Aff[Fp[BN254_Snarks], G1]
bn254_snarks_g1_jac = EC_ShortW_Jac[Fp[BN254_Snarks], G1]
bn254_snarks_g1_prj = EC_ShortW_Prj[Fp[BN254_Snarks], G1]
bn254_snarks_g2_aff = EC_ShortW_Aff[Fp2[BN254_Snarks], G2]
bn254_snarks_g2_jac = EC_ShortW_Jac[Fp2[BN254_Snarks], G2]
bn254_snarks_g2_prj = EC_ShortW_Prj[Fp2[BN254_Snarks], G2]
collectBindings(cBindings_bn254_snarks):
genBindingsField(big254, bn254_snarks_fr)
genBindingsField(big254, bn254_snarks_fp)
genBindingsFieldSqrt(bn254_snarks_fp)
genBindingsExtField(bn254_snarks_fp2)
genBindingsExtFieldSqrt(bn254_snarks_fp2)
genBindings_EC_ShortW_Affine(bn254_snarks_g1_aff, bn254_snarks_fp)
genBindings_EC_ShortW_NonAffine(bn254_snarks_g1_jac, bn254_snarks_g1_aff, big254, bn254_snarks_fr)
genBindings_EC_ShortW_NonAffine(bn254_snarks_g1_prj, bn254_snarks_g1_aff, big254, bn254_snarks_fr)
genBindings_EC_ShortW_Affine(bn254_snarks_g2_aff, bn254_snarks_fp2)
genBindings_EC_ShortW_NonAffine(bn254_snarks_g2_jac, bn254_snarks_g2_aff, big254, bn254_snarks_fr)
genBindings_EC_ShortW_NonAffine(bn254_snarks_g2_prj, bn254_snarks_g2_aff, big254, bn254_snarks_fr)
genBindings_EC_hash_to_curve(bn254_snarks_g1_aff, svdw, sha256, k = 128)
genBindings_EC_hash_to_curve(bn254_snarks_g1_jac, svdw, sha256, k = 128)
genBindings_EC_hash_to_curve(bn254_snarks_g1_prj, svdw, sha256, k = 128)
genBindings_EC_hash_to_curve(bn254_snarks_g2_aff, svdw, sha256, k = 128)
genBindings_EC_hash_to_curve(bn254_snarks_g2_jac, svdw, sha256, k = 128)
genBindings_EC_hash_to_curve(bn254_snarks_g2_prj, svdw, sha256, k = 128)
collectBindings(cBindings_bn254_snarks_parallel):
genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_g1_jac, bn254_snarks_g1_aff, bn254_snarks_fr)
genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_g1_prj, bn254_snarks_g1_aff, bn254_snarks_fr)

However Banderwagon is an Edwards curve so the template there might need an adaptation.
I don't remember what I add in mind as differences between short-weierstrass and twisted edwards, maybe it was just the affine<->jacobian<->projective coordinate conversion and that could be done as a separate template, see

template genBindings_EC_ShortW_Affine*(EC, Field: untyped) =
when appType == "lib":
{.push noconv, dynlib, exportc, raises: [].} # No exceptions allowed
else:
{.push noconv, exportc, raises: [].} # No exceptions allowed
# --------------------------------------------------------------------------------------
func `ctt _ EC _ is_eq`(P, Q: EC): SecretBool =
P == Q
func `ctt _ EC _ is_neutral`(P: EC): SecretBool =
P.isNeutral()
func `ctt _ EC _ set_neutral`(P: var EC) =
P.setNeutral()
func `ctt _ EC _ ccopy`(P: var EC, Q: EC, ctl: SecretBool) =
P.ccopy(Q, ctl)
func `ctt _ EC _ is_on_curve`(x, y: Field): SecretBool =
isOnCurve(x, y, EC.G)
func `ctt _ EC _ neg`(P: var EC, Q: EC) =
P.neg(Q)
func `ctt _ EC _ neg_in_place`(P: var EC) =
P.neg()
{.pop.}
template genBindings_EC_ShortW_NonAffine*(EC, EcAff, ScalarBig, ScalarField: untyped) =
# TODO: remove the need of explicit ScalarBig and ScalarField
when appType == "lib":
{.push noconv, dynlib, exportc, raises: [].} # No exceptions allowed
else:
{.push noconv, exportc, raises: [].} # No exceptions allowed
# --------------------------------------------------------------------------------------
func `ctt _ EC _ is_eq`(P, Q: EC): SecretBool =
P == Q
func `ctt _ EC _ is_neutral`(P: EC): SecretBool =
P.isNeutral()
func `ctt _ EC _ set_neutral`(P: var EC) =
P.setNeutral()
func `ctt _ EC _ ccopy`(P: var EC, Q: EC, ctl: SecretBool) =
P.ccopy(Q, ctl)
func `ctt _ EC _ neg`(P: var EC, Q: EC) =
P.neg(Q)
func `ctt _ EC _ neg_in_place`(P: var EC) =
P.neg()
func `ctt _ EC _ cneg_in_place`(P: var EC, ctl: SecretBool) =
P.neg()
func `ctt _ EC _ sum`(r: var EC, P, Q: EC) =
r.sum(P, Q)
func `ctt _ EC _ add_in_place`(P: var EC, Q: EC) =
P += Q
func `ctt _ EC _ diff`(r: var EC, P, Q: EC) =
r.diff(P, Q)
func `ctt _ EC _ double`(r: var EC, P: EC) =
r.double(P)
func `ctt _ EC _ double_in_place`(P: var EC) =
P.double()
func `ctt _ EC _ affine`(dst: var EcAff, src: EC) =
dst.affine(src)
func `ctt _ EC _ from_affine`(dst: var EC, src: EcAff) =
dst.fromAffine(src)
func `ctt _ EC _ batch_affine`(dst: ptr UncheckedArray[EcAff], src: ptr UncheckedArray[EC], n: csize_t) =
dst.batchAffine(src, cast[int](n))
func `ctt _ EC _ scalar_mul_big_coef`(
P: var EC, scalar: ScalarBig) =
P.scalarMul(scalar)
func `ctt _ EC _ scalar_mul_fr_coef`(
P: var EC, scalar: ScalarField) =
P.scalarMul(scalar)
func `ctt _ EC _ scalar_mul_big_coef_vartime`(
P: var EC, scalar: ScalarBig) =
P.scalarMul_vartime(scalar)
func `ctt _ EC _ scalar_mul_fr_coef_vartime`(
P: var EC, scalar: ScalarField) =
P.scalarMul_vartime(scalar)
func `ctt _ EC _ multi_scalar_mul_big_coefs_vartime`(
r: var EC,
coefs: ptr UncheckedArray[ScalarBig],
points: ptr UncheckedArray[EcAff],
len: csize_t) =
r.multiScalarMul_vartime(coefs, points, cast[int](len))
func `ctt _ EC _ multi_scalar_mul_fr_coefs_vartime`(
r: var EC,
coefs: ptr UncheckedArray[ScalarField],
points: ptr UncheckedArray[EcAff],
len: csize_t)=
r.multiScalarMul_vartime(coefs, points, cast[int](len))
{.pop.}

Copy link
Author

Choose a reason for hiding this comment

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

@mratsim i resolved this and added separate header for banderwagon. Please review and suggest changes. Also how can i verify things are working as expected?

Copy link
Owner

Choose a reason for hiding this comment

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

Good question, I don't have a testsuite for the C API of elliptic curves. It's not ideal but for now we can skip it merge as-is and focus on the C API for the full protocol.


typedef union {
uint8_t u8;
uint16_t u16;
uint32_t u32;
uint64_t u64;
unsigned int u;
} SomeUnsignedInt;
Copy link
Owner

Choose a reason for hiding this comment

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

You cannot emulate generics with union types.

Whatever the platform, the storage reserved will be 64-bit / 8 bytes per entry here.
But if Nim uses 32-bit inputs in an array a, the C code will read both entries with a[0] and will read past the buffer with a[1].

Hence generic procedures cannot be wrapped in C directly.

Copy link
Author

Choose a reason for hiding this comment

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

Understood, will think of another way here.


typedef struct {
SomeUnsignedInt* values;
size_t length;
} SomeUnsignedInt_Array;

// Define types for openArray
typedef struct {
Fr* data;
size_t len;
} Fr_BanderWagon_OpenArray;
Copy link
Owner

Choose a reason for hiding this comment

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

This is not needed, you can pass directly ptr + len.


typedef struct {
EC_TwEdw* data;
size_t len;
} EC_TwEdw_Fp_Banderwagon_OpenArray;
Copy link
Owner

Choose a reason for hiding this comment

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

not needed


typedef struct {
byte value[32]; // 32-byte array for field element
} Fp_Banderwagon;
Copy link
Owner

Choose a reason for hiding this comment

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

should be autogenerated in constantine/include/constantine/curves/banderwagon.h


typedef struct {
byte value[32]; // 32-byte array for field element
} Fr_Banderwagon;
Copy link
Owner

Choose a reason for hiding this comment

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

ditto


typedef struct {
byte x[32]; // 32-byte x-coordinate
byte y[32]; // 32-byte y-coordinate
} EC_TwEdw_Fp_Banderwagon;
Copy link
Owner

Choose a reason for hiding this comment

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

ditto


typedef struct {
byte x[32]; // 32-byte x-coordinate
byte y[32]; // 32-byte y-coordinate
} EC;
Copy link
Owner

Choose a reason for hiding this comment

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

ditto


typedef struct {
EC* points;
size_t length;
} PolynomialEval_EC;
Copy link
Owner

Choose a reason for hiding this comment

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

the protocol has fixed size polynomials. Nim static int are similar to generics and cannot be represented with C runtime parameters. Instead a no generic/no static procedure should be implemented at the croot of the project in constantine/ethereum_verkle_ipa.nim


typedef struct {
Fr* points;
size_t length;
} PolynomialEval_Fr;

typedef struct {
EC* points;
size_t length;
} PolynomialEval_EcAff;

typedef struct {
Fr* domain_values;
size_t length;
} PolyEvalLinearDomain_Fr;

typedef struct {
EC* ec_points;
Fr* field_elements;
size_t logN;
} IpaProof_EcAff_Fr;

typedef struct {
EC* ec_points;
Fr* field_elements;
size_t logN;
} IpaMultiProof_EcAff_Fr;

typedef struct {
EC* ec_points;
size_t length;
} EcAffArray;
Copy link
Owner

Choose a reason for hiding this comment

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

ditto for all structs up to here


typedef struct EthVerkleIpaProof EthVerkleIpaProof;
typedef struct EthVerkleIpaMultiProof EthVerkleIpaMultiProof;
typedef struct IpaProof IpaProof;
typedef struct IpaMultiProof IpaMultiProof;
typedef struct EthVerkleTranscript EthVerkleTranscript;

typedef byte EthVerkleIpaProofBytes[544]; // Array of 544 bytes
typedef byte EthVerkleIpaMultiProofBytes[576];
Copy link
Owner

Choose a reason for hiding this comment

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

It's more useful to provide:

  • either ctt_eth_verkle_ipa_proof_sizeof() and ctt_eth_verkle_ipa_multiproof_sizeof() and let the caller do their allocation / destruction
  • or ctt_eth_verkle_ipa_proof_create() / ctt_eth_verkle_ipa_proof_destroy()
    and ctt_eth_verkle_ipa_multiproof_create() / ctt_eth_verkle_ipa_multiproof_destroy()



ctt_eth_verkle_ipa_status ctt_eth_verkle_serialize(
EthVerkleIpaProofBytes* dst,
const IpaProof* src
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_serialize(
EthVerkleIpaMultiProofBytes* dst,
const IpaMultiProof* src
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_deserialize(
const EthVerkleIpaProof* dst,
EthVerkleIpaProofBytes* src
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_deserialize(
const EthVerkleIpaMultiProof* dst,
EthVerkleIpaMultiProofBytes* src
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_mapToBaseField(
Fp_Banderwagon* dst, const EC_TwEdw_Fp_Banderwagon* p
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_mapToScalarField(
Fr_Banderwagon* res, const EC_TwEdw_Fp_Banderwagon* p
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_batchMapToScalarField(
Fr_BanderWagon_OpenArray* res, const EC_TwEdw_Fp_Banderwagon_OpenArray* p
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_ipa_commit(
const PolynomialEval_EC* crs,
EC* r,
const PolynomialEval_Fr* poly
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_ipa_prove(
const PolynomialEval_EcAff* crs,
const PolyEvalLinearDomain_Fr* domain,
EthVerkleTranscript* transcript,
Fr* eval_at_challenge,
IpaProof_EcAff_Fr* proof,
const PolynomialEval_Fr* poly,
const EC* commitment,
const Fr* opening_challenge
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_ipa_verify(
const PolynomialEval_EcAff* crs,
const PolyEvalLinearDomain_Fr* domain,
EthVerkleTranscript* transcript,
const EC* commitment,
const Fr* opening_challenge,
Fr* eval_at_challenge,
IpaProof_EcAff_Fr* proof
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_ipa_multi_prove(
const PolynomialEval_EcAff* crs,
const PolyEvalLinearDomain_Fr* domain,
EthVerkleTranscript* transcript,
IpaMultiProof_EcAff_Fr* proof,
const PolynomialEval_Fr* polys,
const EC_TwEdw_Fp_Banderwagon_OpenArray* commitments,
const Fr_BanderWagon_OpenArray* opening_challenges_in_domain
) __attribute__((warn_unused_result));

ctt_eth_verkle_ipa_status ctt_eth_verkle_ipa_multi_verify(
const PolynomialEval_EcAff* crs,
const PolyEvalLinearDomain_Fr* domain,
EthVerkleTranscript* transcript,
const EC_TwEdw_Fp_Banderwagon_OpenArray* commitments,
const Fr_BanderWagon_OpenArray* opening_challenges_in_domain,
Fr_BanderWagon_OpenArray* evals_at_challenges,
IpaMultiProof_EcAff_Fr* proof
) __attribute__((warn_unused_result));

#ifdef __cplusplus
}
#endif

#endif // __CTT_H_ETHEREUM_EVM_PRECOMPILES__
Richa-iitr marked this conversation as resolved.
Show resolved Hide resolved