From 9dea740b6c157eeac074349c320e78064ceae889 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Fri, 1 Dec 2023 15:05:35 +0100 Subject: [PATCH 01/24] zal: export MSM and threadpool to C DLL --- .cargo/config.toml | 4 +- Cargo.toml | 7 +- bindings/c_curve_decls.nim | 2 +- bindings/c_curve_decls_parallel.nim | 35 +++++++ bindings/c_typedefs.nim | 49 +++++++--- bindings/lib_constantine.nim | 1 + bindings/lib_curves.nim | 96 +++++++------------ bindings/lib_headers.nim | 85 ++++++++++++++-- bindings/lib_threadpool.nim | 15 +++ bindings/lib_threadpool.nim.cfg | 1 + bindings/macro_curves_bindings.nim | 56 +++++++++++ .../Cargo.toml | 2 +- .../src/lib.rs | 0 .../Cargo.toml | 2 +- .../src/lib.rs | 0 .../Cargo.toml | 4 +- .../src/lib.rs | 0 .../Cargo.toml | 9 -- .../src/lib.rs | 14 --- constantine.nimble | 9 +- constantine/curves_primitives_parallel.nim | 49 ++++++++++ constantine/threadpool.nim | 10 ++ constantine/threadpool/threadpool.nim | 8 +- constantine/zoo_exports.nim | 33 ++++--- include/constantine/core/datatypes.h | 2 +- include/constantine/core/serialization.h | 2 +- include/constantine/core/threadpool.h | 45 +++++++++ include/constantine/curves/bigints.h | 25 +++++ include/constantine/curves/bls12_381.h | 64 ++++++------- .../constantine/curves/bls12_381_parallel.h | 28 ++++++ include/constantine/curves/bn254_snarks.h | 64 ++++++------- .../curves/bn254_snarks_parallel.h | 28 ++++++ include/constantine/curves/pallas.h | 42 ++++---- include/constantine/curves/pallas_parallel.h | 28 ++++++ include/constantine/curves/vesta.h | 42 ++++---- include/constantine/curves/vesta_parallel.h | 28 ++++++ include/constantine/hashes/sha256.h | 2 +- .../protocols/ethereum_bls_signatures.h | 2 +- 38 files changed, 641 insertions(+), 252 deletions(-) create mode 100644 bindings/c_curve_decls_parallel.nim create mode 100644 bindings/lib_threadpool.nim create mode 100644 bindings/lib_threadpool.nim.cfg create mode 100644 bindings/macro_curves_bindings.nim rename constantine-rust/{ctt-curve-bls12-381 => constantine-curves}/Cargo.toml (87%) rename constantine-rust/{ctt-curve-bls12-381 => constantine-curves}/src/lib.rs (100%) rename constantine-rust/{ctt-curve-bn254-snarks => constantine-proto-ethereum-bls-signatures}/Cargo.toml (80%) rename constantine-rust/{ctt-curve-bn254-snarks => constantine-proto-ethereum-bls-signatures}/src/lib.rs (100%) rename constantine-rust/{ctt-curve-pasta => constantine-zal-halo2kzg}/Cargo.toml (63%) rename constantine-rust/{ctt-curve-pasta => constantine-zal-halo2kzg}/src/lib.rs (100%) delete mode 100644 constantine-rust/ctt-proto-ethereum-bls-signatures/Cargo.toml delete mode 100644 constantine-rust/ctt-proto-ethereum-bls-signatures/src/lib.rs create mode 100644 constantine/curves_primitives_parallel.nim create mode 100644 constantine/threadpool.nim create mode 100644 include/constantine/core/threadpool.h create mode 100644 include/constantine/curves/bigints.h create mode 100644 include/constantine/curves/bls12_381_parallel.h create mode 100644 include/constantine/curves/bn254_snarks_parallel.h create mode 100644 include/constantine/curves/pallas_parallel.h create mode 100644 include/constantine/curves/vesta_parallel.h diff --git a/.cargo/config.toml b/.cargo/config.toml index f29efcf7..983c5c4c 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -13,6 +13,6 @@ # if the base LLVM versions differ. # For example before LLVM 15 opaque pointers in IR triggered an error. -[build] -# https://doc.rust-lang.org/rustc/linker-plugin-lto.html +# [build] +# # https://doc.rust-lang.org/rustc/linker-plugin-lto.html # rustflags="-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld" diff --git a/Cargo.toml b/Cargo.toml index 4eb08b82..0fade026 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,10 +2,9 @@ resolver = "2" members = [ "constantine-rust/constantine-sys", - "constantine-rust/ctt-curve-bls12-381", - "constantine-rust/ctt-curve-bn254-snarks", - "constantine-rust/ctt-curve-pasta", - "constantine-rust/ctt-proto-ethereum-bls-signatures", + "constantine-rust/constantine-curves", + "constantine-rust/constantine-zal-halo2kzg", + "constantine-rust/constantine-proto-ethereum-bls-signatures", ] # If Nim static library is compiled with Clang ThinLTO, enable it on Rust side diff --git a/bindings/c_curve_decls.nim b/bindings/c_curve_decls.nim index 21dc54ac..5c13a585 100644 --- a/bindings/c_curve_decls.nim +++ b/bindings/c_curve_decls.nim @@ -303,7 +303,7 @@ template genBindings_EC_ShortW_Affine*(ECP, Field: untyped) = {.pop.} -template genBindings_EC_ShortW_NonAffine*(ECP, ECP_Aff, Field: untyped) = +template genBindings_EC_ShortW_NonAffine*(ECP, ECP_Aff: untyped) = when appType == "lib": {.push noconv, dynlib, exportc, raises: [].} # No exceptions allowed else: diff --git a/bindings/c_curve_decls_parallel.nim b/bindings/c_curve_decls_parallel.nim new file mode 100644 index 00000000..f81bc6b6 --- /dev/null +++ b/bindings/c_curve_decls_parallel.nim @@ -0,0 +1,35 @@ +# 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. + +import + ../constantine/math/config/curves, + ../constantine/curves_primitives_parallel + +export curves_primitives_parallel + +template genParallelBindings_EC_ShortW_NonAffine*(ECP, ECP_Aff: untyped) = + # For some unknown reason {.push noconv.} + # would overwrite the threadpool {.nimcall.} + # in the parallel for-loop `generateClosure` + # + # Similarly, exportc breaks the threadpool generated closure + # hence instead of push/pop we create a pragma alias + + when appType == "lib": + {.pragma: libExport, dynlib, exportc, raises: [].} # No exceptions allowed + else: + {.pragma: libExport, exportc, raises: [].} # No exceptions allowed + + # -------------------------------------------------------------------------------------- + proc `ctt _ ECP _ multi_scalar_mul_vartime_parallel`( + tp: Threadpool, + r: ptr ECP, + coefs: ptr UncheckedArray[BigInt[ECP.F.C.getCurveOrderBitwidth()]], + points: ptr UncheckedArray[ECP_Aff], + len: csize_t) {.libExport.} = + tp.multiScalarMul_vartime_parallel(r, coefs, points, cast[int](len)) diff --git a/bindings/c_typedefs.nim b/bindings/c_typedefs.nim index 1e6bd944..8d109db2 100644 --- a/bindings/c_typedefs.nim +++ b/bindings/c_typedefs.nim @@ -32,10 +32,8 @@ proc genHeaderGuardAndInclude*(name, body: string): string = #define __CTT_H_{name}__ #include "constantine/core/datatypes.h" - {body} - -#endif +#endif // __CTT_H_{name}__ """ proc genCpp*(body: string): string {.raises:[ValueError].} = @@ -43,9 +41,7 @@ proc genCpp*(body: string): string {.raises:[ValueError].} = #ifdef __cplusplus extern "C" {{ #endif - {body} - #ifdef __cplusplus }} #endif @@ -91,6 +87,9 @@ proc genWordsRequired*(): string = #define CTT_WORDS_REQUIRED(bits) ((bits+WordBitWidth-1)/WordBitWidth) """ +proc genBigInt*(bits: int): string = + &"typedef struct {{ secret_word limbs[CTT_WORDS_REQUIRED({bits})]; }} big{bits};" + proc genField*(name: string, bits: int): string = &"typedef struct {{ secret_word limbs[CTT_WORDS_REQUIRED({bits})]; }} {name};" @@ -125,7 +124,11 @@ void ctt_{libName}_init_NimMain(void);""" let TypeMap {.compileTime.} = newStringTable({ "bool": "ctt_bool ", "SecretBool": "secret_bool", - "SecretWord": "secret_word" + "SecretWord": "secret_word", + + # Parallel only, proc are so long we don't care about alignment + "csize_t": "size_t", + "Threadpool": "ctt_threadpool*" }) proc toCrettype*(node: NimNode): string = @@ -137,24 +140,33 @@ proc toCrettype*(node: NimNode): string = TypeMap[$node] proc toCtrivialParam*(name: string, typ: NimNode): string = - typ.expectKind({nnkVarTy, nnkSym}) + typ.expectKind({nnkVarTy, nnkPtrTy, nnkSym}) let isVar = typ.kind == nnkVarTy + let isPtr = typ.kind == nnkPtrTy + let constify = if isVar: "" else: "const " + let ptrify = isVar or isPtr - let sTyp = if isVar: $typ[0] + let sTyp = if ptrify: $typ[0] else: $typ if sTyp in TypeMap: - # Pass-by-value - constify & TypeMap[sTyp] & " " & name + # Pass-by-value unless explicit pointer + # if explicit pointer, apply `const` modifier where relevant + let ptrify = if ptrify: "*" + else: "" + if isPtr: + constify & TypeMap[sTyp] & ptrify & " " & name + else: + TypeMap[sTyp] & ptrify & " " & name else: # Pass-by-reference constify & sTyp & "* " & name proc toCparam*(name: string, typ: NimNode): string = - typ.expectKind({nnkVarTy, nnkCall, nnkSym}) + typ.expectKind({nnkVarTy, nnkCall, nnkSym, nnkPtrTy}) if typ.kind == nnkCall: typ[0].expectKind(nnkOpenSymChoice) @@ -174,5 +186,20 @@ proc toCparam*(name: string, typ: NimNode): string = TypeMap[sTyp] & " " & name & "[], ptrdiff_t " & name & "_len" else: sTyp & " " & name & "[], ptrdiff_t " & name & "_len" + elif typ.kind == nnkPtrTy and typ[0].kind == nnkCall: + typ[0][0].expectKind(nnkOpenSymChoice) + doAssert typ[0][0][0].eqIdent"[]" + doAssert typ[0][1].eqIdent"UncheckedArray" + + let innerType = typ[0][2].getTypeInst() + if innerType.kind == nnkBracketExpr: + doAssert innerType[0].eqIdent"BigInt" + "const big" & $innerType[1].intVal & " " & name & "[]" + else: + let sTyp = $innerType + if sTyp in TypeMap: + "const " & TypeMap[sTyp] & " " & name & "[]" + else: + "const " & sTyp & " " & name & "[]" else: toCtrivialParam(name, typ) diff --git a/bindings/lib_constantine.nim b/bindings/lib_constantine.nim index e807f865..c08e7d3b 100644 --- a/bindings/lib_constantine.nim +++ b/bindings/lib_constantine.nim @@ -15,6 +15,7 @@ {.push warning[UnusedImport]: off.} import + ./lib_threadpool, ./lib_hashes, ./lib_curves, # Protocols diff --git a/bindings/lib_curves.nim b/bindings/lib_curves.nim index 64c0ce97..df0756ac 100644 --- a/bindings/lib_curves.nim +++ b/bindings/lib_curves.nim @@ -12,58 +12,11 @@ # # ############################################################ -import ./c_curve_decls -export c_curve_decls - -when not defined(CTT_MAKE_HEADERS): - template collectBindings(cBindingsStr: untyped, body: typed): untyped = - body -else: - # We gate `c_typedefs` as it imports strutils - # which uses the {.rtl.} pragma and might compile in Nim Runtime Library procs - # that cannot be removed. - # - # We want to ensure its only used for header generation, not in deployment. - import ./c_typedefs - import std/[macros, strutils] - - macro collectBindings(cBindingsStr: untyped, body: typed): untyped = - ## Collect function definitions from a generator template - var cBindings: string - for generator in body: - generator.expectKind(nnkStmtList) - for fnDef in generator: - if fnDef.kind notin {nnkProcDef, nnkFuncDef}: - continue - - cBindings &= "\n" - # rettype name(pType0* pName0, pType1* pName1, ...); - cBindings &= fnDef.params[0].toCrettype() - cBindings &= ' ' - cBindings &= $fnDef.name - cBindings &= '(' - for i in 1 ..< fnDef.params.len: - if i != 1: cBindings &= ", " - - let paramDef = fnDef.params[i] - paramDef.expectKind(nnkIdentDefs) - let pType = paramDef[^2] - # No default value - paramDef[^1].expectKind(nnkEmpty) - - for j in 0 ..< paramDef.len - 2: - if j != 0: cBindings &= ", " - var name = $paramDef[j] - cBindings &= toCparam(name.split('`')[0], pType) - - if fnDef.params[0].eqIdent"bool": - cBindings &= ") __attribute__((warn_unused_result));" - else: - cBindings &= ");" - - - result = newConstStmt(nnkPostfix.newTree(ident"*", cBindingsStr), newLit cBindings) - +import + ./macro_curves_bindings, + ./c_curve_decls, + ./c_curve_decls_parallel +export c_curve_decls, c_curve_decls_parallel # ---------------------------------------------------------- @@ -85,12 +38,15 @@ collectBindings(cBindings_bls12_381): genBindingsExtField(bls12_381_fp2) genBindingsExtFieldSqrt(bls12_381_fp2) genBindings_EC_ShortW_Affine(bls12_381_ec_g1_aff, bls12_381_fp) - genBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_jac, bls12_381_ec_g1_aff, bls12_381_fp) - genBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_prj, bls12_381_ec_g1_aff, bls12_381_fp) + genBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_jac, bls12_381_ec_g1_aff) + genBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_prj, bls12_381_ec_g1_aff) genBindings_EC_ShortW_Affine(bls12_381_ec_g2_aff, bls12_381_fp2) - genBindings_EC_ShortW_NonAffine(bls12_381_ec_g2_jac, bls12_381_ec_g2_aff, bls12_381_fp2) - genBindings_EC_ShortW_NonAffine(bls12_381_ec_g2_prj, bls12_381_ec_g2_aff, bls12_381_fp2) + genBindings_EC_ShortW_NonAffine(bls12_381_ec_g2_jac, bls12_381_ec_g2_aff) + genBindings_EC_ShortW_NonAffine(bls12_381_ec_g2_prj, bls12_381_ec_g2_aff) +collectBindings(cBindings_bls12_381_parallel): + genParallelBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_jac, bls12_381_ec_g1_aff) + genParallelBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_prj, bls12_381_ec_g1_aff) # ---------------------------------------------------------- type @@ -111,11 +67,15 @@ collectBindings(cBindings_bn254_snarks): genBindingsExtField(bn254_snarks_fp2) genBindingsExtFieldSqrt(bn254_snarks_fp2) genBindings_EC_ShortW_Affine(bn254_snarks_ec_g1_aff, bn254_snarks_fp) - genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_jac, bn254_snarks_ec_g1_aff, bn254_snarks_fp) - genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_prj, bn254_snarks_ec_g1_aff, bn254_snarks_fp) + genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_jac, bn254_snarks_ec_g1_aff) + genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_prj, bn254_snarks_ec_g1_aff) genBindings_EC_ShortW_Affine(bn254_snarks_ec_g2_aff, bn254_snarks_fp2) - genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g2_jac, bn254_snarks_ec_g2_aff, bn254_snarks_fp2) - genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g2_prj, bn254_snarks_ec_g2_aff, bn254_snarks_fp2) + genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g2_jac, bn254_snarks_ec_g2_aff) + genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g2_prj, bn254_snarks_ec_g2_aff) + +collectBindings(cBindings_bn254_snarks_parallel): + genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_jac, bn254_snarks_ec_g1_aff) + genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_prj, bn254_snarks_ec_g1_aff) # ---------------------------------------------------------- @@ -131,8 +91,12 @@ collectBindings(cBindings_pallas): genBindingsField(pallas_fp) genBindingsFieldSqrt(pallas_fp) genBindings_EC_ShortW_Affine(pallas_ec_aff, pallas_fp) - genBindings_EC_ShortW_NonAffine(pallas_ec_jac, pallas_ec_aff, pallas_fp) - genBindings_EC_ShortW_NonAffine(pallas_ec_prj, pallas_ec_aff, pallas_fp) + genBindings_EC_ShortW_NonAffine(pallas_ec_jac, pallas_ec_aff) + genBindings_EC_ShortW_NonAffine(pallas_ec_prj, pallas_ec_aff) + +collectBindings(cBindings_pallas_parallel): + genParallelBindings_EC_ShortW_NonAffine(pallas_ec_jac, pallas_ec_aff) + genParallelBindings_EC_ShortW_NonAffine(pallas_ec_prj, pallas_ec_aff) type vesta_fr = Fr[Vesta] @@ -146,7 +110,11 @@ collectBindings(cBindings_vesta): genBindingsField(vesta_fp) genBindingsFieldSqrt(vesta_fp) genBindings_EC_ShortW_Affine(vesta_ec_aff, vesta_fp) - genBindings_EC_ShortW_NonAffine(vesta_ec_jac, vesta_ec_aff, vesta_fp) - genBindings_EC_ShortW_NonAffine(vesta_ec_prj, vesta_ec_aff, vesta_fp) + genBindings_EC_ShortW_NonAffine(vesta_ec_jac, vesta_ec_aff) + genBindings_EC_ShortW_NonAffine(vesta_ec_prj, vesta_ec_aff) + +collectBindings(cBindings_vesta_parallel): + genParallelBindings_EC_ShortW_NonAffine(vesta_ec_jac, vesta_ec_aff) + genParallelBindings_EC_ShortW_NonAffine(vesta_ec_prj, vesta_ec_aff) # ---------------------------------------------------------- diff --git a/bindings/lib_headers.nim b/bindings/lib_headers.nim index 503abd5c..798a5319 100644 --- a/bindings/lib_headers.nim +++ b/bindings/lib_headers.nim @@ -12,11 +12,12 @@ # # ############################################################ -import std/[os, strformat, strutils] +import std/[os, strformat, strutils, intsets] import ./c_typedefs, ./lib_curves +import ../constantine/platforms/static_for proc writeHeader_classicCurve(filepath: string, curve: string, modBits, orderBits: int, curve_decls: string) = - var header: string + var header = "\n" header &= genField(&"{curve}_fr", orderBits) header &= '\n' header &= genField(&"{curve}_fp", modBits) @@ -30,7 +31,7 @@ proc writeHeader_classicCurve(filepath: string, curve: string, modBits, orderBit header &= curve_decls header &= '\n' - header = genCpp(header) + header = "\n" & genCpp(header) header = genHeaderGuardAndInclude(curve.toUpperASCII(), header) header = genHeaderLicense() & header @@ -40,7 +41,7 @@ proc writeHeader_pairingFriendly(filepath: string, curve: string, modBits, order let fpK = if g2_extfield == 1: "fp" else: "fp" & $g2_extfield - var header: string + var header = "\n" header &= genField(&"{curve}_fr", orderBits) header &= '\n' header &= genField(&"{curve}_fp", modBits) @@ -62,7 +63,7 @@ proc writeHeader_pairingFriendly(filepath: string, curve: string, modBits, order header &= curve_decls header &= '\n' - header = genCpp(header) + header = "\n" & genCpp(header) header = genHeaderGuardAndInclude(curve.toUpperASCII(), header) header = genHeaderLicense() & header @@ -82,16 +83,80 @@ proc writeHeader(dirPath: string, C: static Curve, curve_decls: string) = echo "Generated header: ", relPath +proc writeParallelHeader(dirPath: string, C: static Curve, curve_decls: string) = + const modBits = C.getCurveBitWidth() + const orderBits = C.getCurveOrderBitWidth() + let curve = ($C).toLowerASCII() + let relPath = dirPath/"constantine"/"curves"/curve & "_parallel.h" + + var includes: string + includes &= "#include \"constantine/core/threadpool.h\"" + includes &= '\n' + includes &= &"#include \"constantine/curves/bigints.h\"" + includes &= '\n' + includes &= &"#include \"constantine/curves/{curve}.h\"" + includes &= '\n' + + var header: string + header &= curve_decls + header &= '\n' + + header = "\n" & genCpp(header) + header = genHeaderGuardAndInclude(curve.toUpperASCII() & "_PARALLEL", includes & header) + header = genHeaderLicense() & header + + writeFile(relPath, header) + echo "Generated header: ", relPath + +proc writeBigIntHeader(dirPath: string, bigSizes: IntSet) = + let relPath = dirPath/"constantine"/"curves"/"bigints.h" + + var header = "\n" + + for size in bigSizes: + header &= genBigInt(size) + header &= '\n' + + header = "\n" & genCpp(header) + header = genHeaderGuardAndInclude("BIGINTS", header) + header = genHeaderLicense() & header + + writeFile(relPath, header) + echo "Generated header: ", relPath + proc writeCurveHeaders(dir: string) = static: doAssert defined(CTT_MAKE_HEADERS), " Pass '-d:CTT_MAKE_HEADERS' to the compiler so that curves declarations are collected." - writeHeader(dir, BLS12_381, cBindings_bls12_381) - writeHeader(dir, BN254_Snarks, cBindings_bn254_snarks) - writeHeader(dir, Pallas, cBindings_pallas) - writeHeader(dir, Vesta, cBindings_vesta) + const curveMappings = { + BLS12_381: cBindings_bls12_381, + BN254_Snarks: cBindings_bn254_snarks, + Pallas: cBindings_pallas, + Vesta: cBindings_vesta + } + + staticFor i, 0, curveMappings.len: + writeHeader(dir, curveMappings[i][0], curveMappings[i][1]) + +proc writeCurveParallelHeaders(dir: string) = + static: doAssert defined(CTT_MAKE_HEADERS), " Pass '-d:CTT_MAKE_HEADERS' to the compiler so that curves declarations are collected." + + const curveMappings = { + BLS12_381: cBindings_bls12_381_parallel, + BN254_Snarks: cBindings_bn254_snarks_parallel, + Pallas: cBindings_pallas_parallel, + Vesta: cBindings_vesta_parallel + } + + var bigSizes = initIntSet() + + staticFor i, 0, curveMappings.len: + writeParallelHeader(dir, curveMappings[i][0], curveMappings[i][1]) + bigSizes.incl(curveMappings[i][0].getCurveOrderBitWidth()) + + dir.writeBigIntHeader(bigSizes) when isMainModule: proc main() {.inline.} = writeCurveHeaders("include") - + writeCurveParallelHeaders("include") main() \ No newline at end of file diff --git a/bindings/lib_threadpool.nim b/bindings/lib_threadpool.nim new file mode 100644 index 00000000..bbbddf71 --- /dev/null +++ b/bindings/lib_threadpool.nim @@ -0,0 +1,15 @@ +# 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. + +# ############################################################ +# +# Constantine's threadpool +# +# ############################################################ + +import ../constantine/threadpool \ No newline at end of file diff --git a/bindings/lib_threadpool.nim.cfg b/bindings/lib_threadpool.nim.cfg new file mode 100644 index 00000000..9d57ecf9 --- /dev/null +++ b/bindings/lib_threadpool.nim.cfg @@ -0,0 +1 @@ +--threads:on \ No newline at end of file diff --git a/bindings/macro_curves_bindings.nim b/bindings/macro_curves_bindings.nim new file mode 100644 index 00000000..efd9ce1f --- /dev/null +++ b/bindings/macro_curves_bindings.nim @@ -0,0 +1,56 @@ +# 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. + +when not defined(CTT_MAKE_HEADERS): + template collectBindings*(cBindingsStr: untyped, body: typed): untyped = + body +else: + # We gate `c_typedefs` as it imports strutils + # which uses the {.rtl.} pragma and might compile in Nim Runtime Library procs + # that cannot be removed. + # + # We want to ensure its only used for header generation, not in deployment. + import ./c_typedefs + import std/[macros, strutils] + + macro collectBindings*(cBindingsStr: untyped, body: typed): untyped = + ## Collect function definitions from a generator template + var cBindings: string + for generator in body: + generator.expectKind(nnkStmtList) + for fnDef in generator: + if fnDef.kind notin {nnkProcDef, nnkFuncDef}: + continue + + cBindings &= "\n" + # rettype name(pType0* pName0, pType1* pName1, ...); + cBindings &= fnDef.params[0].toCrettype() + cBindings &= ' ' + cBindings &= $fnDef.name + cBindings &= '(' + for i in 1 ..< fnDef.params.len: + if i != 1: cBindings &= ", " + + let paramDef = fnDef.params[i] + paramDef.expectKind(nnkIdentDefs) + let pType = paramDef[^2] + # No default value + paramDef[^1].expectKind(nnkEmpty) + + for j in 0 ..< paramDef.len - 2: + if j != 0: cBindings &= ", " + var name = $paramDef[j] + cBindings &= toCparam(name.split('`')[0], pType) + + if fnDef.params[0].eqIdent"bool": + cBindings &= ") __attribute__((warn_unused_result));" + else: + cBindings &= ");" + + + result = newConstStmt(nnkPostfix.newTree(ident"*", cBindingsStr), newLit cBindings) diff --git a/constantine-rust/ctt-curve-bls12-381/Cargo.toml b/constantine-rust/constantine-curves/Cargo.toml similarity index 87% rename from constantine-rust/ctt-curve-bls12-381/Cargo.toml rename to constantine-rust/constantine-curves/Cargo.toml index 47385063..65dc12de 100644 --- a/constantine-rust/ctt-curve-bls12-381/Cargo.toml +++ b/constantine-rust/constantine-curves/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ctt-curve-bls12-381" +name = "constantine-curves" version = "0.1.0" edition = "2021" diff --git a/constantine-rust/ctt-curve-bls12-381/src/lib.rs b/constantine-rust/constantine-curves/src/lib.rs similarity index 100% rename from constantine-rust/ctt-curve-bls12-381/src/lib.rs rename to constantine-rust/constantine-curves/src/lib.rs diff --git a/constantine-rust/ctt-curve-bn254-snarks/Cargo.toml b/constantine-rust/constantine-proto-ethereum-bls-signatures/Cargo.toml similarity index 80% rename from constantine-rust/ctt-curve-bn254-snarks/Cargo.toml rename to constantine-rust/constantine-proto-ethereum-bls-signatures/Cargo.toml index 3f3821c4..15ec5f3a 100644 --- a/constantine-rust/ctt-curve-bn254-snarks/Cargo.toml +++ b/constantine-rust/constantine-proto-ethereum-bls-signatures/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ctt-curve-bn254-snarks" +name = "constantine-proto-ethereum-bls-signatures" version = "0.1.0" edition = "2021" diff --git a/constantine-rust/ctt-curve-bn254-snarks/src/lib.rs b/constantine-rust/constantine-proto-ethereum-bls-signatures/src/lib.rs similarity index 100% rename from constantine-rust/ctt-curve-bn254-snarks/src/lib.rs rename to constantine-rust/constantine-proto-ethereum-bls-signatures/src/lib.rs diff --git a/constantine-rust/ctt-curve-pasta/Cargo.toml b/constantine-rust/constantine-zal-halo2kzg/Cargo.toml similarity index 63% rename from constantine-rust/ctt-curve-pasta/Cargo.toml rename to constantine-rust/constantine-zal-halo2kzg/Cargo.toml index 032b50b0..9ab2f431 100644 --- a/constantine-rust/ctt-curve-pasta/Cargo.toml +++ b/constantine-rust/constantine-zal-halo2kzg/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "ctt-curve-pasta" +name = "constantine-zal-halo2curves" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -constantine-sys = { path = "../constantine-sys" } +constantine-curves = { path = "../constantine-curves" } \ No newline at end of file diff --git a/constantine-rust/ctt-curve-pasta/src/lib.rs b/constantine-rust/constantine-zal-halo2kzg/src/lib.rs similarity index 100% rename from constantine-rust/ctt-curve-pasta/src/lib.rs rename to constantine-rust/constantine-zal-halo2kzg/src/lib.rs diff --git a/constantine-rust/ctt-proto-ethereum-bls-signatures/Cargo.toml b/constantine-rust/ctt-proto-ethereum-bls-signatures/Cargo.toml deleted file mode 100644 index 04bcf7a0..00000000 --- a/constantine-rust/ctt-proto-ethereum-bls-signatures/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "ctt-proto-ethereum-bls-signatures" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -constantine-sys = { path = "../constantine-sys" } \ No newline at end of file diff --git a/constantine-rust/ctt-proto-ethereum-bls-signatures/src/lib.rs b/constantine-rust/ctt-proto-ethereum-bls-signatures/src/lib.rs deleted file mode 100644 index 7d12d9af..00000000 --- a/constantine-rust/ctt-proto-ethereum-bls-signatures/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/constantine.nimble b/constantine.nimble index 340ac4cc..f8ac4f6e 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -190,6 +190,7 @@ proc genDynamicLib(outdir, nimcache: string) = exec "nim c " & flags & releaseBuildOptions(bmDynamicLib) & + " --threads:on " & " --noMain --app:lib " & &" --nimMainPrefix:ctt_init_ " & # Constantine is designed so that NimMain isn't needed, provided --mm:arc -d:useMalloc --panics:on -d:noSignalHandler &" --out:{libName} --outdir:{outdir} " & @@ -209,17 +210,18 @@ proc genDynamicLib(outdir, nimcache: string) = else: compile "libconstantine.so" -proc genStaticLib(outdir, nimcache: string, rustLib = false) = +proc genStaticLib(outdir, nimcache: string) = proc compile(libName: string, flags = "") = echo &"Compiling static library: {outdir}/" & libName exec "nim c " & flags & releaseBuildOptions(bmStaticLib) & + " --threads:on " & " --noMain --app:staticlib " & &" --nimMainPrefix:ctt_init_ " & # Constantine is designed so that NimMain isn't needed, provided --mm:arc -d:useMalloc --panics:on -d:noSignalHandler &" --out:{libName} --outdir:{outdir} " & - &" --nimcache:{nimcache}/libconstantine_static" & (if rustLib: "_rust" else: "") & + &" --nimcache:{nimcache}/libconstantine_static" & &" bindings/lib_constantine.nim" when defined(windows): @@ -238,6 +240,7 @@ proc genStaticLib(outdir, nimcache: string, rustLib = false) = task make_headers, "Regenerate Constantine headers": exec "nim c -r -d:CTT_MAKE_HEADERS " & " -d:release " & + " --threads:on " & " --verbosity:0 --hints:off --warnings:off " & " --outdir:build/make " & " --nimcache:nimcache/libcurves_headers " & @@ -250,7 +253,7 @@ task make_lib, "Build Constantine library": task make_lib_rust, "Build Constantine library (use within a Rust build.rs script)": doAssert existsEnv"OUT_DIR", "Cargo needs to set the \"OUT_DIR\" environment variable" let rustOutDir = getEnv"OUT_DIR" - genStaticLib(rustOutDir, rustOutDir/"nimcache", rustLib = true) + genStaticLib(rustOutDir, rustOutDir/"nimcache") proc testLib(path, testName: string, useGMP: bool) = let dynlibName = if defined(windows): "constantine.dll" diff --git a/constantine/curves_primitives_parallel.nim b/constantine/curves_primitives_parallel.nim new file mode 100644 index 00000000..8a3729c7 --- /dev/null +++ b/constantine/curves_primitives_parallel.nim @@ -0,0 +1,49 @@ +# 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. + +import + ./math/config/[curves, type_bigint, type_ff], + ./threadpool, + ./math/elliptic/ec_multi_scalar_mul_parallel, + ./math/ec_shortweierstrass + +# ############################################################ +# +# Generator for low-level parallel primitives API +# +# ############################################################ + +# Threadpool +# ------------------------------------------------------------ + +export threadpool.Threadpool +export threadpool.new +export threadpool.shutdown + +# Base types +# ------------------------------------------------------------ + +export curves.Curve +export type_bigint.BigInt +export + type_ff.Fp, + type_ff.Fr, + type_ff.FF + +# Elliptic curve +# ------------------------------------------------------------ + +export + ec_shortweierstrass.Subgroup, + ec_shortweierstrass.ECP_ShortW_Aff, + ec_shortweierstrass.ECP_ShortW_Jac, + ec_shortweierstrass.ECP_ShortW_Prj, + ec_shortweierstrass.ECP_ShortW + +export + ec_multi_scalar_mul_parallel.multiScalarMul_vartime_parallel \ No newline at end of file diff --git a/constantine/threadpool.nim b/constantine/threadpool.nim new file mode 100644 index 00000000..ec95382b --- /dev/null +++ b/constantine/threadpool.nim @@ -0,0 +1,10 @@ +# 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. + +import ./threadpool/[threadpool, partitioners] +export threadpool, partitioners \ No newline at end of file diff --git a/constantine/threadpool/threadpool.nim b/constantine/threadpool/threadpool.nim index e0de2062..33e34d3e 100644 --- a/constantine/threadpool/threadpool.nim +++ b/constantine/threadpool/threadpool.nim @@ -23,6 +23,8 @@ import ./parallel_offloading, ../platforms/[allocs, bithacks] +import ../zoo_exports + export # flowvars Flowvar, isSpawned, isReady @@ -938,8 +940,8 @@ proc wait(scopedBarrier: ptr ScopedBarrier) {.raises:[], gcsafe.} = # # # ############################################################ -proc new*(T: type Threadpool, numThreads = countProcessors()): T {.raises: [ResourceExhaustedError].} = - ## Initialize a threadpool that manages `numThreads` threads. +proc new*(T: type Threadpool, numThreads = countProcessors()): T {.libPrefix: "ctt_threadpool_", raises: [ResourceExhaustedError].} = + ## Initialize a threadpool that manages `num_threads` threads. ## Default to the number of logical processors available. ## ## A Constantine's threadpool cannot be instantiated @@ -993,7 +995,7 @@ proc cleanup(tp: Threadpool) {.raises: [].} = tp.freeHeapAligned() -proc shutdown*(tp: Threadpool) {.raises:[].} = +proc shutdown*(tp: Threadpool) {.raises:[], libPrefix: "ctt_threadpool_".} = ## Wait until all tasks are processed and then shutdown the threadpool preCondition: workerContext.currentTask.isRootTask() tp.syncAll() diff --git a/constantine/zoo_exports.nim b/constantine/zoo_exports.nim index 6ddf18b4..9b9d982a 100644 --- a/constantine/zoo_exports.nim +++ b/constantine/zoo_exports.nim @@ -32,23 +32,30 @@ var prefix_sha256* {.compileTime.} = "ctt_sha256_" import std/macros macro libPrefix*(prefix: static string, procAst: untyped): untyped = - if prefix == "": - return procAst - else: - var pragmas = procAst.pragma - if pragmas.kind == nnkEmpty: - pragmas = nnkPragma.newTree() + var pragmas = procAst.pragma + if pragmas.kind == nnkEmpty: + pragmas = nnkPragma.newTree() + + # Ensure all exceptions are caught. + pragmas.add nnkExprColonExpr.newTree( + ident"raises", + nnkBracket.newTree()) + if appType != "lib" and appType != "staticLib": + # extern only does name-mangling but allows for dead-code elimination. + pragmas.add nnkExprColonExpr.newTree( + ident"extern", + newLit(prefix & "$1")) + else: + # exportc only does name-mangling and dead-code elimination. + # use the OS default call convention pragmas.add ident"noconv" pragmas.add nnkExprColonExpr.newTree( ident"exportc", newLit(prefix & "$1")) - pragmas.add nnkExprColonExpr.newTree( - ident"raises", - nnkBracket.newTree()) - if appType == "lib": - pragmas.add ident"dynlib" + if appType == "lib": + pragmas.add ident"dynlib" - result = procAst - result.pragma = pragmas + result = procAst + result.pragma = pragmas diff --git a/include/constantine/core/datatypes.h b/include/constantine/core/datatypes.h index 492e3863..6910fe6a 100644 --- a/include/constantine/core/datatypes.h +++ b/include/constantine/core/datatypes.h @@ -64,4 +64,4 @@ typedef uint8_t byte; } #endif -#endif \ No newline at end of file +#endif // __CTT_H_DATATYPES__ \ No newline at end of file diff --git a/include/constantine/core/serialization.h b/include/constantine/core/serialization.h index c93c671d..b2e8efae 100644 --- a/include/constantine/core/serialization.h +++ b/include/constantine/core/serialization.h @@ -63,4 +63,4 @@ static const char* ctt_codec_ecc_status_to_string(ctt_codec_ecc_status status) { } #endif -#endif \ No newline at end of file +#endif // __CTT_H_SERIALIZATION__ \ No newline at end of file diff --git a/include/constantine/core/threadpool.h b/include/constantine/core/threadpool.h new file mode 100644 index 00000000..d8a817f8 --- /dev/null +++ b/include/constantine/core/threadpool.h @@ -0,0 +1,45 @@ +/** 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_THREADPOOL__ +#define __CTT_H_THREADPOOL__ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__SIZE_TYPE__) +typedef __SIZE_TYPE__ size_t; +#else +#include +#endif + +typedef struct ctt_threadpool ctt_threadpool; + +/** Create a new threadpool that manages `num_threads` threads + * + * Initialize a threadpool that manages `num_threads` threads. + * + * A Constantine's threadpool cannot be instantiated + * on a thread managed by another Constantine's threadpool + * including the root thread. + * + * Mixing with other libraries' threadpools and runtime + * will not impact correctness but may impact performance. + */ +struct ctt_threadpool* ctt_threadpool_new(size_t num_threads); + +/** Wait until all pending tasks are processed and then shutdown the threadpool + */ +void ctt_threadpool_shutdown(struct ctt_threadpool* threadpool); + +#ifdef __cplusplus +} +#endif + +#endif // __CTT_H_THREADPOOL__ \ No newline at end of file diff --git a/include/constantine/curves/bigints.h b/include/constantine/curves/bigints.h new file mode 100644 index 00000000..40cfefa3 --- /dev/null +++ b/include/constantine/curves/bigints.h @@ -0,0 +1,25 @@ +/** 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_BIGINTS__ +#define __CTT_H_BIGINTS__ + +#include "constantine/core/datatypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { secret_word limbs[CTT_WORDS_REQUIRED(255)]; } big255; +typedef struct { secret_word limbs[CTT_WORDS_REQUIRED(254)]; } big254; + +#ifdef __cplusplus +} +#endif + +#endif // __CTT_H_BIGINTS__ diff --git a/include/constantine/curves/bls12_381.h b/include/constantine/curves/bls12_381.h index ffb255ed..3f1a4f9f 100644 --- a/include/constantine/curves/bls12_381.h +++ b/include/constantine/curves/bls12_381.h @@ -49,13 +49,13 @@ void ctt_bls12_381_fr_square_in_place(bls12_381_fr* a); void ctt_bls12_381_fr_div2(bls12_381_fr* a); void ctt_bls12_381_fr_inv(bls12_381_fr* r, const bls12_381_fr* a); void ctt_bls12_381_fr_inv_in_place(bls12_381_fr* a); -void ctt_bls12_381_fr_ccopy(bls12_381_fr* a, const bls12_381_fr* b, const secret_bool ctl); -void ctt_bls12_381_fr_cswap(bls12_381_fr* a, bls12_381_fr* b, const secret_bool ctl); -void ctt_bls12_381_fr_cset_zero(bls12_381_fr* a, const secret_bool ctl); -void ctt_bls12_381_fr_cset_one(bls12_381_fr* a, const secret_bool ctl); -void ctt_bls12_381_fr_cneg_in_place(bls12_381_fr* a, const secret_bool ctl); -void ctt_bls12_381_fr_cadd_in_place(bls12_381_fr* a, const bls12_381_fr* b, const secret_bool ctl); -void ctt_bls12_381_fr_csub_in_place(bls12_381_fr* a, const bls12_381_fr* b, const secret_bool ctl); +void ctt_bls12_381_fr_ccopy(bls12_381_fr* a, const bls12_381_fr* b, secret_bool ctl); +void ctt_bls12_381_fr_cswap(bls12_381_fr* a, bls12_381_fr* b, secret_bool ctl); +void ctt_bls12_381_fr_cset_zero(bls12_381_fr* a, secret_bool ctl); +void ctt_bls12_381_fr_cset_one(bls12_381_fr* a, secret_bool ctl); +void ctt_bls12_381_fr_cneg_in_place(bls12_381_fr* a, secret_bool ctl); +void ctt_bls12_381_fr_cadd_in_place(bls12_381_fr* a, const bls12_381_fr* b, secret_bool ctl); +void ctt_bls12_381_fr_csub_in_place(bls12_381_fr* a, const bls12_381_fr* b, secret_bool ctl); ctt_bool ctt_bls12_381_fp_unmarshalBE(bls12_381_fp* dst, const byte src[], ptrdiff_t src_len) __attribute__((warn_unused_result)); ctt_bool ctt_bls12_381_fp_marshalBE(byte dst[], ptrdiff_t dst_len, const bls12_381_fp* src) __attribute__((warn_unused_result)); secret_bool ctt_bls12_381_fp_is_eq(const bls12_381_fp* a, const bls12_381_fp* b); @@ -80,13 +80,13 @@ void ctt_bls12_381_fp_square_in_place(bls12_381_fp* a); void ctt_bls12_381_fp_div2(bls12_381_fp* a); void ctt_bls12_381_fp_inv(bls12_381_fp* r, const bls12_381_fp* a); void ctt_bls12_381_fp_inv_in_place(bls12_381_fp* a); -void ctt_bls12_381_fp_ccopy(bls12_381_fp* a, const bls12_381_fp* b, const secret_bool ctl); -void ctt_bls12_381_fp_cswap(bls12_381_fp* a, bls12_381_fp* b, const secret_bool ctl); -void ctt_bls12_381_fp_cset_zero(bls12_381_fp* a, const secret_bool ctl); -void ctt_bls12_381_fp_cset_one(bls12_381_fp* a, const secret_bool ctl); -void ctt_bls12_381_fp_cneg_in_place(bls12_381_fp* a, const secret_bool ctl); -void ctt_bls12_381_fp_cadd_in_place(bls12_381_fp* a, const bls12_381_fp* b, const secret_bool ctl); -void ctt_bls12_381_fp_csub_in_place(bls12_381_fp* a, const bls12_381_fp* b, const secret_bool ctl); +void ctt_bls12_381_fp_ccopy(bls12_381_fp* a, const bls12_381_fp* b, secret_bool ctl); +void ctt_bls12_381_fp_cswap(bls12_381_fp* a, bls12_381_fp* b, secret_bool ctl); +void ctt_bls12_381_fp_cset_zero(bls12_381_fp* a, secret_bool ctl); +void ctt_bls12_381_fp_cset_one(bls12_381_fp* a, secret_bool ctl); +void ctt_bls12_381_fp_cneg_in_place(bls12_381_fp* a, secret_bool ctl); +void ctt_bls12_381_fp_cadd_in_place(bls12_381_fp* a, const bls12_381_fp* b, secret_bool ctl); +void ctt_bls12_381_fp_csub_in_place(bls12_381_fp* a, const bls12_381_fp* b, secret_bool ctl); secret_bool ctt_bls12_381_fp_is_square(const bls12_381_fp* a); void ctt_bls12_381_fp_invsqrt(bls12_381_fp* r, const bls12_381_fp* a); secret_bool ctt_bls12_381_fp_invsqrt_in_place(bls12_381_fp* r, const bls12_381_fp* a); @@ -120,29 +120,29 @@ void ctt_bls12_381_fp2_square_in_place(bls12_381_fp2* a); void ctt_bls12_381_fp2_div2(bls12_381_fp2* a); void ctt_bls12_381_fp2_inv(bls12_381_fp2* r, const bls12_381_fp2* a); void ctt_bls12_381_fp2_inv_in_place(bls12_381_fp2* a); -void ctt_bls12_381_fp2_ccopy(bls12_381_fp2* a, const bls12_381_fp2* b, const secret_bool ctl); -void ctt_bls12_381_fp2_cset_zero(bls12_381_fp2* a, const secret_bool ctl); -void ctt_bls12_381_fp2_cset_one(bls12_381_fp2* a, const secret_bool ctl); -void ctt_bls12_381_fp2_cneg_in_place(bls12_381_fp2* a, const secret_bool ctl); -void ctt_bls12_381_fp2_cadd_in_place(bls12_381_fp2* a, const bls12_381_fp2* b, const secret_bool ctl); -void ctt_bls12_381_fp2_csub_in_place(bls12_381_fp2* a, const bls12_381_fp2* b, const secret_bool ctl); +void ctt_bls12_381_fp2_ccopy(bls12_381_fp2* a, const bls12_381_fp2* b, secret_bool ctl); +void ctt_bls12_381_fp2_cset_zero(bls12_381_fp2* a, secret_bool ctl); +void ctt_bls12_381_fp2_cset_one(bls12_381_fp2* a, secret_bool ctl); +void ctt_bls12_381_fp2_cneg_in_place(bls12_381_fp2* a, secret_bool ctl); +void ctt_bls12_381_fp2_cadd_in_place(bls12_381_fp2* a, const bls12_381_fp2* b, secret_bool ctl); +void ctt_bls12_381_fp2_csub_in_place(bls12_381_fp2* a, const bls12_381_fp2* b, secret_bool ctl); secret_bool ctt_bls12_381_fp2_is_square(const bls12_381_fp2* a); void ctt_bls12_381_fp2_sqrt_in_place(bls12_381_fp2* a); secret_bool ctt_bls12_381_fp2_sqrt_if_square_in_place(bls12_381_fp2* a); secret_bool ctt_bls12_381_ec_g1_aff_is_eq(const bls12_381_ec_g1_aff* P, const bls12_381_ec_g1_aff* Q); secret_bool ctt_bls12_381_ec_g1_aff_is_inf(const bls12_381_ec_g1_aff* P); void ctt_bls12_381_ec_g1_aff_set_inf(bls12_381_ec_g1_aff* P); -void ctt_bls12_381_ec_g1_aff_ccopy(bls12_381_ec_g1_aff* P, const bls12_381_ec_g1_aff* Q, const secret_bool ctl); +void ctt_bls12_381_ec_g1_aff_ccopy(bls12_381_ec_g1_aff* P, const bls12_381_ec_g1_aff* Q, secret_bool ctl); secret_bool ctt_bls12_381_ec_g1_aff_is_on_curve(const bls12_381_fp* x, const bls12_381_fp* y); void ctt_bls12_381_ec_g1_aff_neg(bls12_381_ec_g1_aff* P, const bls12_381_ec_g1_aff* Q); void ctt_bls12_381_ec_g1_aff_neg_in_place(bls12_381_ec_g1_aff* P); secret_bool ctt_bls12_381_ec_g1_jac_is_eq(const bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); secret_bool ctt_bls12_381_ec_g1_jac_is_inf(const bls12_381_ec_g1_jac* P); void ctt_bls12_381_ec_g1_jac_set_inf(bls12_381_ec_g1_jac* P); -void ctt_bls12_381_ec_g1_jac_ccopy(bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q, const secret_bool ctl); +void ctt_bls12_381_ec_g1_jac_ccopy(bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q, secret_bool ctl); void ctt_bls12_381_ec_g1_jac_neg(bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); void ctt_bls12_381_ec_g1_jac_neg_in_place(bls12_381_ec_g1_jac* P); -void ctt_bls12_381_ec_g1_jac_cneg_in_place(bls12_381_ec_g1_jac* P, const secret_bool ctl); +void ctt_bls12_381_ec_g1_jac_cneg_in_place(bls12_381_ec_g1_jac* P, secret_bool ctl); void ctt_bls12_381_ec_g1_jac_sum(bls12_381_ec_g1_jac* r, const bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); void ctt_bls12_381_ec_g1_jac_add_in_place(bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); void ctt_bls12_381_ec_g1_jac_diff(bls12_381_ec_g1_jac* r, const bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); @@ -153,10 +153,10 @@ void ctt_bls12_381_ec_g1_jac_from_affine(bls12_381_ec_g1_jac* dst, const secret_bool ctt_bls12_381_ec_g1_prj_is_eq(const bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); secret_bool ctt_bls12_381_ec_g1_prj_is_inf(const bls12_381_ec_g1_prj* P); void ctt_bls12_381_ec_g1_prj_set_inf(bls12_381_ec_g1_prj* P); -void ctt_bls12_381_ec_g1_prj_ccopy(bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q, const secret_bool ctl); +void ctt_bls12_381_ec_g1_prj_ccopy(bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q, secret_bool ctl); void ctt_bls12_381_ec_g1_prj_neg(bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); void ctt_bls12_381_ec_g1_prj_neg_in_place(bls12_381_ec_g1_prj* P); -void ctt_bls12_381_ec_g1_prj_cneg_in_place(bls12_381_ec_g1_prj* P, const secret_bool ctl); +void ctt_bls12_381_ec_g1_prj_cneg_in_place(bls12_381_ec_g1_prj* P, secret_bool ctl); void ctt_bls12_381_ec_g1_prj_sum(bls12_381_ec_g1_prj* r, const bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); void ctt_bls12_381_ec_g1_prj_add_in_place(bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); void ctt_bls12_381_ec_g1_prj_diff(bls12_381_ec_g1_prj* r, const bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); @@ -167,17 +167,17 @@ void ctt_bls12_381_ec_g1_prj_from_affine(bls12_381_ec_g1_prj* dst, const secret_bool ctt_bls12_381_ec_g2_aff_is_eq(const bls12_381_ec_g2_aff* P, const bls12_381_ec_g2_aff* Q); secret_bool ctt_bls12_381_ec_g2_aff_is_inf(const bls12_381_ec_g2_aff* P); void ctt_bls12_381_ec_g2_aff_set_inf(bls12_381_ec_g2_aff* P); -void ctt_bls12_381_ec_g2_aff_ccopy(bls12_381_ec_g2_aff* P, const bls12_381_ec_g2_aff* Q, const secret_bool ctl); +void ctt_bls12_381_ec_g2_aff_ccopy(bls12_381_ec_g2_aff* P, const bls12_381_ec_g2_aff* Q, secret_bool ctl); secret_bool ctt_bls12_381_ec_g2_aff_is_on_curve(const bls12_381_fp2* x, const bls12_381_fp2* y); void ctt_bls12_381_ec_g2_aff_neg(bls12_381_ec_g2_aff* P, const bls12_381_ec_g2_aff* Q); void ctt_bls12_381_ec_g2_aff_neg_in_place(bls12_381_ec_g2_aff* P); secret_bool ctt_bls12_381_ec_g2_jac_is_eq(const bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); secret_bool ctt_bls12_381_ec_g2_jac_is_inf(const bls12_381_ec_g2_jac* P); void ctt_bls12_381_ec_g2_jac_set_inf(bls12_381_ec_g2_jac* P); -void ctt_bls12_381_ec_g2_jac_ccopy(bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q, const secret_bool ctl); +void ctt_bls12_381_ec_g2_jac_ccopy(bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q, secret_bool ctl); void ctt_bls12_381_ec_g2_jac_neg(bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); void ctt_bls12_381_ec_g2_jac_neg_in_place(bls12_381_ec_g2_jac* P); -void ctt_bls12_381_ec_g2_jac_cneg_in_place(bls12_381_ec_g2_jac* P, const secret_bool ctl); +void ctt_bls12_381_ec_g2_jac_cneg_in_place(bls12_381_ec_g2_jac* P, secret_bool ctl); void ctt_bls12_381_ec_g2_jac_sum(bls12_381_ec_g2_jac* r, const bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); void ctt_bls12_381_ec_g2_jac_add_in_place(bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); void ctt_bls12_381_ec_g2_jac_diff(bls12_381_ec_g2_jac* r, const bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); @@ -188,10 +188,10 @@ void ctt_bls12_381_ec_g2_jac_from_affine(bls12_381_ec_g2_jac* dst, const secret_bool ctt_bls12_381_ec_g2_prj_is_eq(const bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); secret_bool ctt_bls12_381_ec_g2_prj_is_inf(const bls12_381_ec_g2_prj* P); void ctt_bls12_381_ec_g2_prj_set_inf(bls12_381_ec_g2_prj* P); -void ctt_bls12_381_ec_g2_prj_ccopy(bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q, const secret_bool ctl); +void ctt_bls12_381_ec_g2_prj_ccopy(bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q, secret_bool ctl); void ctt_bls12_381_ec_g2_prj_neg(bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); void ctt_bls12_381_ec_g2_prj_neg_in_place(bls12_381_ec_g2_prj* P); -void ctt_bls12_381_ec_g2_prj_cneg_in_place(bls12_381_ec_g2_prj* P, const secret_bool ctl); +void ctt_bls12_381_ec_g2_prj_cneg_in_place(bls12_381_ec_g2_prj* P, secret_bool ctl); void ctt_bls12_381_ec_g2_prj_sum(bls12_381_ec_g2_prj* r, const bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); void ctt_bls12_381_ec_g2_prj_add_in_place(bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); void ctt_bls12_381_ec_g2_prj_diff(bls12_381_ec_g2_prj* r, const bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); @@ -200,10 +200,8 @@ void ctt_bls12_381_ec_g2_prj_double_in_place(bls12_381_ec_g2_prj* P); void ctt_bls12_381_ec_g2_prj_affine(bls12_381_ec_g2_aff* dst, const bls12_381_ec_g2_prj* src); void ctt_bls12_381_ec_g2_prj_from_affine(bls12_381_ec_g2_prj* dst, const bls12_381_ec_g2_aff* src); - #ifdef __cplusplus } #endif - -#endif +#endif // __CTT_H_BLS12_381__ diff --git a/include/constantine/curves/bls12_381_parallel.h b/include/constantine/curves/bls12_381_parallel.h new file mode 100644 index 00000000..01c5a65d --- /dev/null +++ b/include/constantine/curves/bls12_381_parallel.h @@ -0,0 +1,28 @@ +/** 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_BLS12_381_PARALLEL__ +#define __CTT_H_BLS12_381_PARALLEL__ + +#include "constantine/core/datatypes.h" +#include "constantine/core/threadpool.h" +#include "constantine/curves/bigints.h" +#include "constantine/curves/bls12_381.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void ctt_bls12_381_ec_g1_jac_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const bls12_381_ec_g1_jac* r, const big255 coefs[], const bls12_381_ec_g1_aff points[], size_t len); +void ctt_bls12_381_ec_g1_prj_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const bls12_381_ec_g1_prj* r, const big255 coefs[], const bls12_381_ec_g1_aff points[], size_t len); + +#ifdef __cplusplus +} +#endif + +#endif // __CTT_H_BLS12_381_PARALLEL__ diff --git a/include/constantine/curves/bn254_snarks.h b/include/constantine/curves/bn254_snarks.h index 9e0b7acd..6507e664 100644 --- a/include/constantine/curves/bn254_snarks.h +++ b/include/constantine/curves/bn254_snarks.h @@ -49,13 +49,13 @@ void ctt_bn254_snarks_fr_square_in_place(bn254_snarks_fr* a); void ctt_bn254_snarks_fr_div2(bn254_snarks_fr* a); void ctt_bn254_snarks_fr_inv(bn254_snarks_fr* r, const bn254_snarks_fr* a); void ctt_bn254_snarks_fr_inv_in_place(bn254_snarks_fr* a); -void ctt_bn254_snarks_fr_ccopy(bn254_snarks_fr* a, const bn254_snarks_fr* b, const secret_bool ctl); -void ctt_bn254_snarks_fr_cswap(bn254_snarks_fr* a, bn254_snarks_fr* b, const secret_bool ctl); -void ctt_bn254_snarks_fr_cset_zero(bn254_snarks_fr* a, const secret_bool ctl); -void ctt_bn254_snarks_fr_cset_one(bn254_snarks_fr* a, const secret_bool ctl); -void ctt_bn254_snarks_fr_cneg_in_place(bn254_snarks_fr* a, const secret_bool ctl); -void ctt_bn254_snarks_fr_cadd_in_place(bn254_snarks_fr* a, const bn254_snarks_fr* b, const secret_bool ctl); -void ctt_bn254_snarks_fr_csub_in_place(bn254_snarks_fr* a, const bn254_snarks_fr* b, const secret_bool ctl); +void ctt_bn254_snarks_fr_ccopy(bn254_snarks_fr* a, const bn254_snarks_fr* b, secret_bool ctl); +void ctt_bn254_snarks_fr_cswap(bn254_snarks_fr* a, bn254_snarks_fr* b, secret_bool ctl); +void ctt_bn254_snarks_fr_cset_zero(bn254_snarks_fr* a, secret_bool ctl); +void ctt_bn254_snarks_fr_cset_one(bn254_snarks_fr* a, secret_bool ctl); +void ctt_bn254_snarks_fr_cneg_in_place(bn254_snarks_fr* a, secret_bool ctl); +void ctt_bn254_snarks_fr_cadd_in_place(bn254_snarks_fr* a, const bn254_snarks_fr* b, secret_bool ctl); +void ctt_bn254_snarks_fr_csub_in_place(bn254_snarks_fr* a, const bn254_snarks_fr* b, secret_bool ctl); ctt_bool ctt_bn254_snarks_fp_unmarshalBE(bn254_snarks_fp* dst, const byte src[], ptrdiff_t src_len) __attribute__((warn_unused_result)); ctt_bool ctt_bn254_snarks_fp_marshalBE(byte dst[], ptrdiff_t dst_len, const bn254_snarks_fp* src) __attribute__((warn_unused_result)); secret_bool ctt_bn254_snarks_fp_is_eq(const bn254_snarks_fp* a, const bn254_snarks_fp* b); @@ -80,13 +80,13 @@ void ctt_bn254_snarks_fp_square_in_place(bn254_snarks_fp* a); void ctt_bn254_snarks_fp_div2(bn254_snarks_fp* a); void ctt_bn254_snarks_fp_inv(bn254_snarks_fp* r, const bn254_snarks_fp* a); void ctt_bn254_snarks_fp_inv_in_place(bn254_snarks_fp* a); -void ctt_bn254_snarks_fp_ccopy(bn254_snarks_fp* a, const bn254_snarks_fp* b, const secret_bool ctl); -void ctt_bn254_snarks_fp_cswap(bn254_snarks_fp* a, bn254_snarks_fp* b, const secret_bool ctl); -void ctt_bn254_snarks_fp_cset_zero(bn254_snarks_fp* a, const secret_bool ctl); -void ctt_bn254_snarks_fp_cset_one(bn254_snarks_fp* a, const secret_bool ctl); -void ctt_bn254_snarks_fp_cneg_in_place(bn254_snarks_fp* a, const secret_bool ctl); -void ctt_bn254_snarks_fp_cadd_in_place(bn254_snarks_fp* a, const bn254_snarks_fp* b, const secret_bool ctl); -void ctt_bn254_snarks_fp_csub_in_place(bn254_snarks_fp* a, const bn254_snarks_fp* b, const secret_bool ctl); +void ctt_bn254_snarks_fp_ccopy(bn254_snarks_fp* a, const bn254_snarks_fp* b, secret_bool ctl); +void ctt_bn254_snarks_fp_cswap(bn254_snarks_fp* a, bn254_snarks_fp* b, secret_bool ctl); +void ctt_bn254_snarks_fp_cset_zero(bn254_snarks_fp* a, secret_bool ctl); +void ctt_bn254_snarks_fp_cset_one(bn254_snarks_fp* a, secret_bool ctl); +void ctt_bn254_snarks_fp_cneg_in_place(bn254_snarks_fp* a, secret_bool ctl); +void ctt_bn254_snarks_fp_cadd_in_place(bn254_snarks_fp* a, const bn254_snarks_fp* b, secret_bool ctl); +void ctt_bn254_snarks_fp_csub_in_place(bn254_snarks_fp* a, const bn254_snarks_fp* b, secret_bool ctl); secret_bool ctt_bn254_snarks_fp_is_square(const bn254_snarks_fp* a); void ctt_bn254_snarks_fp_invsqrt(bn254_snarks_fp* r, const bn254_snarks_fp* a); secret_bool ctt_bn254_snarks_fp_invsqrt_in_place(bn254_snarks_fp* r, const bn254_snarks_fp* a); @@ -120,29 +120,29 @@ void ctt_bn254_snarks_fp2_square_in_place(bn254_snarks_fp2* a); void ctt_bn254_snarks_fp2_div2(bn254_snarks_fp2* a); void ctt_bn254_snarks_fp2_inv(bn254_snarks_fp2* r, const bn254_snarks_fp2* a); void ctt_bn254_snarks_fp2_inv_in_place(bn254_snarks_fp2* a); -void ctt_bn254_snarks_fp2_ccopy(bn254_snarks_fp2* a, const bn254_snarks_fp2* b, const secret_bool ctl); -void ctt_bn254_snarks_fp2_cset_zero(bn254_snarks_fp2* a, const secret_bool ctl); -void ctt_bn254_snarks_fp2_cset_one(bn254_snarks_fp2* a, const secret_bool ctl); -void ctt_bn254_snarks_fp2_cneg_in_place(bn254_snarks_fp2* a, const secret_bool ctl); -void ctt_bn254_snarks_fp2_cadd_in_place(bn254_snarks_fp2* a, const bn254_snarks_fp2* b, const secret_bool ctl); -void ctt_bn254_snarks_fp2_csub_in_place(bn254_snarks_fp2* a, const bn254_snarks_fp2* b, const secret_bool ctl); +void ctt_bn254_snarks_fp2_ccopy(bn254_snarks_fp2* a, const bn254_snarks_fp2* b, secret_bool ctl); +void ctt_bn254_snarks_fp2_cset_zero(bn254_snarks_fp2* a, secret_bool ctl); +void ctt_bn254_snarks_fp2_cset_one(bn254_snarks_fp2* a, secret_bool ctl); +void ctt_bn254_snarks_fp2_cneg_in_place(bn254_snarks_fp2* a, secret_bool ctl); +void ctt_bn254_snarks_fp2_cadd_in_place(bn254_snarks_fp2* a, const bn254_snarks_fp2* b, secret_bool ctl); +void ctt_bn254_snarks_fp2_csub_in_place(bn254_snarks_fp2* a, const bn254_snarks_fp2* b, secret_bool ctl); secret_bool ctt_bn254_snarks_fp2_is_square(const bn254_snarks_fp2* a); void ctt_bn254_snarks_fp2_sqrt_in_place(bn254_snarks_fp2* a); secret_bool ctt_bn254_snarks_fp2_sqrt_if_square_in_place(bn254_snarks_fp2* a); secret_bool ctt_bn254_snarks_ec_g1_aff_is_eq(const bn254_snarks_ec_g1_aff* P, const bn254_snarks_ec_g1_aff* Q); secret_bool ctt_bn254_snarks_ec_g1_aff_is_inf(const bn254_snarks_ec_g1_aff* P); void ctt_bn254_snarks_ec_g1_aff_set_inf(bn254_snarks_ec_g1_aff* P); -void ctt_bn254_snarks_ec_g1_aff_ccopy(bn254_snarks_ec_g1_aff* P, const bn254_snarks_ec_g1_aff* Q, const secret_bool ctl); +void ctt_bn254_snarks_ec_g1_aff_ccopy(bn254_snarks_ec_g1_aff* P, const bn254_snarks_ec_g1_aff* Q, secret_bool ctl); secret_bool ctt_bn254_snarks_ec_g1_aff_is_on_curve(const bn254_snarks_fp* x, const bn254_snarks_fp* y); void ctt_bn254_snarks_ec_g1_aff_neg(bn254_snarks_ec_g1_aff* P, const bn254_snarks_ec_g1_aff* Q); void ctt_bn254_snarks_ec_g1_aff_neg_in_place(bn254_snarks_ec_g1_aff* P); secret_bool ctt_bn254_snarks_ec_g1_jac_is_eq(const bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); secret_bool ctt_bn254_snarks_ec_g1_jac_is_inf(const bn254_snarks_ec_g1_jac* P); void ctt_bn254_snarks_ec_g1_jac_set_inf(bn254_snarks_ec_g1_jac* P); -void ctt_bn254_snarks_ec_g1_jac_ccopy(bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q, const secret_bool ctl); +void ctt_bn254_snarks_ec_g1_jac_ccopy(bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q, secret_bool ctl); void ctt_bn254_snarks_ec_g1_jac_neg(bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); void ctt_bn254_snarks_ec_g1_jac_neg_in_place(bn254_snarks_ec_g1_jac* P); -void ctt_bn254_snarks_ec_g1_jac_cneg_in_place(bn254_snarks_ec_g1_jac* P, const secret_bool ctl); +void ctt_bn254_snarks_ec_g1_jac_cneg_in_place(bn254_snarks_ec_g1_jac* P, secret_bool ctl); void ctt_bn254_snarks_ec_g1_jac_sum(bn254_snarks_ec_g1_jac* r, const bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); void ctt_bn254_snarks_ec_g1_jac_add_in_place(bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); void ctt_bn254_snarks_ec_g1_jac_diff(bn254_snarks_ec_g1_jac* r, const bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); @@ -153,10 +153,10 @@ void ctt_bn254_snarks_ec_g1_jac_from_affine(bn254_snarks_ec_g1_jac* dst, secret_bool ctt_bn254_snarks_ec_g1_prj_is_eq(const bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); secret_bool ctt_bn254_snarks_ec_g1_prj_is_inf(const bn254_snarks_ec_g1_prj* P); void ctt_bn254_snarks_ec_g1_prj_set_inf(bn254_snarks_ec_g1_prj* P); -void ctt_bn254_snarks_ec_g1_prj_ccopy(bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q, const secret_bool ctl); +void ctt_bn254_snarks_ec_g1_prj_ccopy(bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q, secret_bool ctl); void ctt_bn254_snarks_ec_g1_prj_neg(bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); void ctt_bn254_snarks_ec_g1_prj_neg_in_place(bn254_snarks_ec_g1_prj* P); -void ctt_bn254_snarks_ec_g1_prj_cneg_in_place(bn254_snarks_ec_g1_prj* P, const secret_bool ctl); +void ctt_bn254_snarks_ec_g1_prj_cneg_in_place(bn254_snarks_ec_g1_prj* P, secret_bool ctl); void ctt_bn254_snarks_ec_g1_prj_sum(bn254_snarks_ec_g1_prj* r, const bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); void ctt_bn254_snarks_ec_g1_prj_add_in_place(bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); void ctt_bn254_snarks_ec_g1_prj_diff(bn254_snarks_ec_g1_prj* r, const bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); @@ -167,17 +167,17 @@ void ctt_bn254_snarks_ec_g1_prj_from_affine(bn254_snarks_ec_g1_prj* dst, secret_bool ctt_bn254_snarks_ec_g2_aff_is_eq(const bn254_snarks_ec_g2_aff* P, const bn254_snarks_ec_g2_aff* Q); secret_bool ctt_bn254_snarks_ec_g2_aff_is_inf(const bn254_snarks_ec_g2_aff* P); void ctt_bn254_snarks_ec_g2_aff_set_inf(bn254_snarks_ec_g2_aff* P); -void ctt_bn254_snarks_ec_g2_aff_ccopy(bn254_snarks_ec_g2_aff* P, const bn254_snarks_ec_g2_aff* Q, const secret_bool ctl); +void ctt_bn254_snarks_ec_g2_aff_ccopy(bn254_snarks_ec_g2_aff* P, const bn254_snarks_ec_g2_aff* Q, secret_bool ctl); secret_bool ctt_bn254_snarks_ec_g2_aff_is_on_curve(const bn254_snarks_fp2* x, const bn254_snarks_fp2* y); void ctt_bn254_snarks_ec_g2_aff_neg(bn254_snarks_ec_g2_aff* P, const bn254_snarks_ec_g2_aff* Q); void ctt_bn254_snarks_ec_g2_aff_neg_in_place(bn254_snarks_ec_g2_aff* P); secret_bool ctt_bn254_snarks_ec_g2_jac_is_eq(const bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); secret_bool ctt_bn254_snarks_ec_g2_jac_is_inf(const bn254_snarks_ec_g2_jac* P); void ctt_bn254_snarks_ec_g2_jac_set_inf(bn254_snarks_ec_g2_jac* P); -void ctt_bn254_snarks_ec_g2_jac_ccopy(bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q, const secret_bool ctl); +void ctt_bn254_snarks_ec_g2_jac_ccopy(bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q, secret_bool ctl); void ctt_bn254_snarks_ec_g2_jac_neg(bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); void ctt_bn254_snarks_ec_g2_jac_neg_in_place(bn254_snarks_ec_g2_jac* P); -void ctt_bn254_snarks_ec_g2_jac_cneg_in_place(bn254_snarks_ec_g2_jac* P, const secret_bool ctl); +void ctt_bn254_snarks_ec_g2_jac_cneg_in_place(bn254_snarks_ec_g2_jac* P, secret_bool ctl); void ctt_bn254_snarks_ec_g2_jac_sum(bn254_snarks_ec_g2_jac* r, const bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); void ctt_bn254_snarks_ec_g2_jac_add_in_place(bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); void ctt_bn254_snarks_ec_g2_jac_diff(bn254_snarks_ec_g2_jac* r, const bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); @@ -188,10 +188,10 @@ void ctt_bn254_snarks_ec_g2_jac_from_affine(bn254_snarks_ec_g2_jac* dst, secret_bool ctt_bn254_snarks_ec_g2_prj_is_eq(const bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); secret_bool ctt_bn254_snarks_ec_g2_prj_is_inf(const bn254_snarks_ec_g2_prj* P); void ctt_bn254_snarks_ec_g2_prj_set_inf(bn254_snarks_ec_g2_prj* P); -void ctt_bn254_snarks_ec_g2_prj_ccopy(bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q, const secret_bool ctl); +void ctt_bn254_snarks_ec_g2_prj_ccopy(bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q, secret_bool ctl); void ctt_bn254_snarks_ec_g2_prj_neg(bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); void ctt_bn254_snarks_ec_g2_prj_neg_in_place(bn254_snarks_ec_g2_prj* P); -void ctt_bn254_snarks_ec_g2_prj_cneg_in_place(bn254_snarks_ec_g2_prj* P, const secret_bool ctl); +void ctt_bn254_snarks_ec_g2_prj_cneg_in_place(bn254_snarks_ec_g2_prj* P, secret_bool ctl); void ctt_bn254_snarks_ec_g2_prj_sum(bn254_snarks_ec_g2_prj* r, const bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); void ctt_bn254_snarks_ec_g2_prj_add_in_place(bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); void ctt_bn254_snarks_ec_g2_prj_diff(bn254_snarks_ec_g2_prj* r, const bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); @@ -200,10 +200,8 @@ void ctt_bn254_snarks_ec_g2_prj_double_in_place(bn254_snarks_ec_g2_prj* P void ctt_bn254_snarks_ec_g2_prj_affine(bn254_snarks_ec_g2_aff* dst, const bn254_snarks_ec_g2_prj* src); void ctt_bn254_snarks_ec_g2_prj_from_affine(bn254_snarks_ec_g2_prj* dst, const bn254_snarks_ec_g2_aff* src); - #ifdef __cplusplus } #endif - -#endif +#endif // __CTT_H_BN254_SNARKS__ diff --git a/include/constantine/curves/bn254_snarks_parallel.h b/include/constantine/curves/bn254_snarks_parallel.h new file mode 100644 index 00000000..f7cc0663 --- /dev/null +++ b/include/constantine/curves/bn254_snarks_parallel.h @@ -0,0 +1,28 @@ +/** 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_BN254_SNARKS_PARALLEL__ +#define __CTT_H_BN254_SNARKS_PARALLEL__ + +#include "constantine/core/datatypes.h" +#include "constantine/core/threadpool.h" +#include "constantine/curves/bigints.h" +#include "constantine/curves/bn254_snarks.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void ctt_bn254_snarks_ec_g1_jac_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const bn254_snarks_ec_g1_jac* r, const big254 coefs[], const bn254_snarks_ec_g1_aff points[], size_t len); +void ctt_bn254_snarks_ec_g1_prj_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const bn254_snarks_ec_g1_prj* r, const big254 coefs[], const bn254_snarks_ec_g1_aff points[], size_t len); + +#ifdef __cplusplus +} +#endif + +#endif // __CTT_H_BN254_SNARKS_PARALLEL__ diff --git a/include/constantine/curves/pallas.h b/include/constantine/curves/pallas.h index 5ebee783..7be9a5b0 100644 --- a/include/constantine/curves/pallas.h +++ b/include/constantine/curves/pallas.h @@ -45,13 +45,13 @@ void ctt_pallas_fr_square_in_place(pallas_fr* a); void ctt_pallas_fr_div2(pallas_fr* a); void ctt_pallas_fr_inv(pallas_fr* r, const pallas_fr* a); void ctt_pallas_fr_inv_in_place(pallas_fr* a); -void ctt_pallas_fr_ccopy(pallas_fr* a, const pallas_fr* b, const secret_bool ctl); -void ctt_pallas_fr_cswap(pallas_fr* a, pallas_fr* b, const secret_bool ctl); -void ctt_pallas_fr_cset_zero(pallas_fr* a, const secret_bool ctl); -void ctt_pallas_fr_cset_one(pallas_fr* a, const secret_bool ctl); -void ctt_pallas_fr_cneg_in_place(pallas_fr* a, const secret_bool ctl); -void ctt_pallas_fr_cadd_in_place(pallas_fr* a, const pallas_fr* b, const secret_bool ctl); -void ctt_pallas_fr_csub_in_place(pallas_fr* a, const pallas_fr* b, const secret_bool ctl); +void ctt_pallas_fr_ccopy(pallas_fr* a, const pallas_fr* b, secret_bool ctl); +void ctt_pallas_fr_cswap(pallas_fr* a, pallas_fr* b, secret_bool ctl); +void ctt_pallas_fr_cset_zero(pallas_fr* a, secret_bool ctl); +void ctt_pallas_fr_cset_one(pallas_fr* a, secret_bool ctl); +void ctt_pallas_fr_cneg_in_place(pallas_fr* a, secret_bool ctl); +void ctt_pallas_fr_cadd_in_place(pallas_fr* a, const pallas_fr* b, secret_bool ctl); +void ctt_pallas_fr_csub_in_place(pallas_fr* a, const pallas_fr* b, secret_bool ctl); ctt_bool ctt_pallas_fp_unmarshalBE(pallas_fp* dst, const byte src[], ptrdiff_t src_len) __attribute__((warn_unused_result)); ctt_bool ctt_pallas_fp_marshalBE(byte dst[], ptrdiff_t dst_len, const pallas_fp* src) __attribute__((warn_unused_result)); secret_bool ctt_pallas_fp_is_eq(const pallas_fp* a, const pallas_fp* b); @@ -76,13 +76,13 @@ void ctt_pallas_fp_square_in_place(pallas_fp* a); void ctt_pallas_fp_div2(pallas_fp* a); void ctt_pallas_fp_inv(pallas_fp* r, const pallas_fp* a); void ctt_pallas_fp_inv_in_place(pallas_fp* a); -void ctt_pallas_fp_ccopy(pallas_fp* a, const pallas_fp* b, const secret_bool ctl); -void ctt_pallas_fp_cswap(pallas_fp* a, pallas_fp* b, const secret_bool ctl); -void ctt_pallas_fp_cset_zero(pallas_fp* a, const secret_bool ctl); -void ctt_pallas_fp_cset_one(pallas_fp* a, const secret_bool ctl); -void ctt_pallas_fp_cneg_in_place(pallas_fp* a, const secret_bool ctl); -void ctt_pallas_fp_cadd_in_place(pallas_fp* a, const pallas_fp* b, const secret_bool ctl); -void ctt_pallas_fp_csub_in_place(pallas_fp* a, const pallas_fp* b, const secret_bool ctl); +void ctt_pallas_fp_ccopy(pallas_fp* a, const pallas_fp* b, secret_bool ctl); +void ctt_pallas_fp_cswap(pallas_fp* a, pallas_fp* b, secret_bool ctl); +void ctt_pallas_fp_cset_zero(pallas_fp* a, secret_bool ctl); +void ctt_pallas_fp_cset_one(pallas_fp* a, secret_bool ctl); +void ctt_pallas_fp_cneg_in_place(pallas_fp* a, secret_bool ctl); +void ctt_pallas_fp_cadd_in_place(pallas_fp* a, const pallas_fp* b, secret_bool ctl); +void ctt_pallas_fp_csub_in_place(pallas_fp* a, const pallas_fp* b, secret_bool ctl); secret_bool ctt_pallas_fp_is_square(const pallas_fp* a); void ctt_pallas_fp_invsqrt(pallas_fp* r, const pallas_fp* a); secret_bool ctt_pallas_fp_invsqrt_in_place(pallas_fp* r, const pallas_fp* a); @@ -94,17 +94,17 @@ secret_bool ctt_pallas_fp_sqrt_ratio_if_square(pallas_fp* r, const pallas_fp* u, secret_bool ctt_pallas_ec_aff_is_eq(const pallas_ec_aff* P, const pallas_ec_aff* Q); secret_bool ctt_pallas_ec_aff_is_inf(const pallas_ec_aff* P); void ctt_pallas_ec_aff_set_inf(pallas_ec_aff* P); -void ctt_pallas_ec_aff_ccopy(pallas_ec_aff* P, const pallas_ec_aff* Q, const secret_bool ctl); +void ctt_pallas_ec_aff_ccopy(pallas_ec_aff* P, const pallas_ec_aff* Q, secret_bool ctl); secret_bool ctt_pallas_ec_aff_is_on_curve(const pallas_fp* x, const pallas_fp* y); void ctt_pallas_ec_aff_neg(pallas_ec_aff* P, const pallas_ec_aff* Q); void ctt_pallas_ec_aff_neg_in_place(pallas_ec_aff* P); secret_bool ctt_pallas_ec_jac_is_eq(const pallas_ec_jac* P, const pallas_ec_jac* Q); secret_bool ctt_pallas_ec_jac_is_inf(const pallas_ec_jac* P); void ctt_pallas_ec_jac_set_inf(pallas_ec_jac* P); -void ctt_pallas_ec_jac_ccopy(pallas_ec_jac* P, const pallas_ec_jac* Q, const secret_bool ctl); +void ctt_pallas_ec_jac_ccopy(pallas_ec_jac* P, const pallas_ec_jac* Q, secret_bool ctl); void ctt_pallas_ec_jac_neg(pallas_ec_jac* P, const pallas_ec_jac* Q); void ctt_pallas_ec_jac_neg_in_place(pallas_ec_jac* P); -void ctt_pallas_ec_jac_cneg_in_place(pallas_ec_jac* P, const secret_bool ctl); +void ctt_pallas_ec_jac_cneg_in_place(pallas_ec_jac* P, secret_bool ctl); void ctt_pallas_ec_jac_sum(pallas_ec_jac* r, const pallas_ec_jac* P, const pallas_ec_jac* Q); void ctt_pallas_ec_jac_add_in_place(pallas_ec_jac* P, const pallas_ec_jac* Q); void ctt_pallas_ec_jac_diff(pallas_ec_jac* r, const pallas_ec_jac* P, const pallas_ec_jac* Q); @@ -115,10 +115,10 @@ void ctt_pallas_ec_jac_from_affine(pallas_ec_jac* dst, const pallas_ec_af secret_bool ctt_pallas_ec_prj_is_eq(const pallas_ec_prj* P, const pallas_ec_prj* Q); secret_bool ctt_pallas_ec_prj_is_inf(const pallas_ec_prj* P); void ctt_pallas_ec_prj_set_inf(pallas_ec_prj* P); -void ctt_pallas_ec_prj_ccopy(pallas_ec_prj* P, const pallas_ec_prj* Q, const secret_bool ctl); +void ctt_pallas_ec_prj_ccopy(pallas_ec_prj* P, const pallas_ec_prj* Q, secret_bool ctl); void ctt_pallas_ec_prj_neg(pallas_ec_prj* P, const pallas_ec_prj* Q); void ctt_pallas_ec_prj_neg_in_place(pallas_ec_prj* P); -void ctt_pallas_ec_prj_cneg_in_place(pallas_ec_prj* P, const secret_bool ctl); +void ctt_pallas_ec_prj_cneg_in_place(pallas_ec_prj* P, secret_bool ctl); void ctt_pallas_ec_prj_sum(pallas_ec_prj* r, const pallas_ec_prj* P, const pallas_ec_prj* Q); void ctt_pallas_ec_prj_add_in_place(pallas_ec_prj* P, const pallas_ec_prj* Q); void ctt_pallas_ec_prj_diff(pallas_ec_prj* r, const pallas_ec_prj* P, const pallas_ec_prj* Q); @@ -127,10 +127,8 @@ void ctt_pallas_ec_prj_double_in_place(pallas_ec_prj* P); void ctt_pallas_ec_prj_affine(pallas_ec_aff* dst, const pallas_ec_prj* src); void ctt_pallas_ec_prj_from_affine(pallas_ec_prj* dst, const pallas_ec_aff* src); - #ifdef __cplusplus } #endif - -#endif +#endif // __CTT_H_PALLAS__ diff --git a/include/constantine/curves/pallas_parallel.h b/include/constantine/curves/pallas_parallel.h new file mode 100644 index 00000000..7f43d6df --- /dev/null +++ b/include/constantine/curves/pallas_parallel.h @@ -0,0 +1,28 @@ +/** 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_PALLAS_PARALLEL__ +#define __CTT_H_PALLAS_PARALLEL__ + +#include "constantine/core/datatypes.h" +#include "constantine/core/threadpool.h" +#include "constantine/curves/bigints.h" +#include "constantine/curves/pallas.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const pallas_ec_jac* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const pallas_ec_prj* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); + +#ifdef __cplusplus +} +#endif + +#endif // __CTT_H_PALLAS_PARALLEL__ diff --git a/include/constantine/curves/vesta.h b/include/constantine/curves/vesta.h index 4051173d..ee841c5a 100644 --- a/include/constantine/curves/vesta.h +++ b/include/constantine/curves/vesta.h @@ -45,13 +45,13 @@ void ctt_vesta_fr_square_in_place(vesta_fr* a); void ctt_vesta_fr_div2(vesta_fr* a); void ctt_vesta_fr_inv(vesta_fr* r, const vesta_fr* a); void ctt_vesta_fr_inv_in_place(vesta_fr* a); -void ctt_vesta_fr_ccopy(vesta_fr* a, const vesta_fr* b, const secret_bool ctl); -void ctt_vesta_fr_cswap(vesta_fr* a, vesta_fr* b, const secret_bool ctl); -void ctt_vesta_fr_cset_zero(vesta_fr* a, const secret_bool ctl); -void ctt_vesta_fr_cset_one(vesta_fr* a, const secret_bool ctl); -void ctt_vesta_fr_cneg_in_place(vesta_fr* a, const secret_bool ctl); -void ctt_vesta_fr_cadd_in_place(vesta_fr* a, const vesta_fr* b, const secret_bool ctl); -void ctt_vesta_fr_csub_in_place(vesta_fr* a, const vesta_fr* b, const secret_bool ctl); +void ctt_vesta_fr_ccopy(vesta_fr* a, const vesta_fr* b, secret_bool ctl); +void ctt_vesta_fr_cswap(vesta_fr* a, vesta_fr* b, secret_bool ctl); +void ctt_vesta_fr_cset_zero(vesta_fr* a, secret_bool ctl); +void ctt_vesta_fr_cset_one(vesta_fr* a, secret_bool ctl); +void ctt_vesta_fr_cneg_in_place(vesta_fr* a, secret_bool ctl); +void ctt_vesta_fr_cadd_in_place(vesta_fr* a, const vesta_fr* b, secret_bool ctl); +void ctt_vesta_fr_csub_in_place(vesta_fr* a, const vesta_fr* b, secret_bool ctl); ctt_bool ctt_vesta_fp_unmarshalBE(vesta_fp* dst, const byte src[], ptrdiff_t src_len) __attribute__((warn_unused_result)); ctt_bool ctt_vesta_fp_marshalBE(byte dst[], ptrdiff_t dst_len, const vesta_fp* src) __attribute__((warn_unused_result)); secret_bool ctt_vesta_fp_is_eq(const vesta_fp* a, const vesta_fp* b); @@ -76,13 +76,13 @@ void ctt_vesta_fp_square_in_place(vesta_fp* a); void ctt_vesta_fp_div2(vesta_fp* a); void ctt_vesta_fp_inv(vesta_fp* r, const vesta_fp* a); void ctt_vesta_fp_inv_in_place(vesta_fp* a); -void ctt_vesta_fp_ccopy(vesta_fp* a, const vesta_fp* b, const secret_bool ctl); -void ctt_vesta_fp_cswap(vesta_fp* a, vesta_fp* b, const secret_bool ctl); -void ctt_vesta_fp_cset_zero(vesta_fp* a, const secret_bool ctl); -void ctt_vesta_fp_cset_one(vesta_fp* a, const secret_bool ctl); -void ctt_vesta_fp_cneg_in_place(vesta_fp* a, const secret_bool ctl); -void ctt_vesta_fp_cadd_in_place(vesta_fp* a, const vesta_fp* b, const secret_bool ctl); -void ctt_vesta_fp_csub_in_place(vesta_fp* a, const vesta_fp* b, const secret_bool ctl); +void ctt_vesta_fp_ccopy(vesta_fp* a, const vesta_fp* b, secret_bool ctl); +void ctt_vesta_fp_cswap(vesta_fp* a, vesta_fp* b, secret_bool ctl); +void ctt_vesta_fp_cset_zero(vesta_fp* a, secret_bool ctl); +void ctt_vesta_fp_cset_one(vesta_fp* a, secret_bool ctl); +void ctt_vesta_fp_cneg_in_place(vesta_fp* a, secret_bool ctl); +void ctt_vesta_fp_cadd_in_place(vesta_fp* a, const vesta_fp* b, secret_bool ctl); +void ctt_vesta_fp_csub_in_place(vesta_fp* a, const vesta_fp* b, secret_bool ctl); secret_bool ctt_vesta_fp_is_square(const vesta_fp* a); void ctt_vesta_fp_invsqrt(vesta_fp* r, const vesta_fp* a); secret_bool ctt_vesta_fp_invsqrt_in_place(vesta_fp* r, const vesta_fp* a); @@ -94,17 +94,17 @@ secret_bool ctt_vesta_fp_sqrt_ratio_if_square(vesta_fp* r, const vesta_fp* u, co secret_bool ctt_vesta_ec_aff_is_eq(const vesta_ec_aff* P, const vesta_ec_aff* Q); secret_bool ctt_vesta_ec_aff_is_inf(const vesta_ec_aff* P); void ctt_vesta_ec_aff_set_inf(vesta_ec_aff* P); -void ctt_vesta_ec_aff_ccopy(vesta_ec_aff* P, const vesta_ec_aff* Q, const secret_bool ctl); +void ctt_vesta_ec_aff_ccopy(vesta_ec_aff* P, const vesta_ec_aff* Q, secret_bool ctl); secret_bool ctt_vesta_ec_aff_is_on_curve(const vesta_fp* x, const vesta_fp* y); void ctt_vesta_ec_aff_neg(vesta_ec_aff* P, const vesta_ec_aff* Q); void ctt_vesta_ec_aff_neg_in_place(vesta_ec_aff* P); secret_bool ctt_vesta_ec_jac_is_eq(const vesta_ec_jac* P, const vesta_ec_jac* Q); secret_bool ctt_vesta_ec_jac_is_inf(const vesta_ec_jac* P); void ctt_vesta_ec_jac_set_inf(vesta_ec_jac* P); -void ctt_vesta_ec_jac_ccopy(vesta_ec_jac* P, const vesta_ec_jac* Q, const secret_bool ctl); +void ctt_vesta_ec_jac_ccopy(vesta_ec_jac* P, const vesta_ec_jac* Q, secret_bool ctl); void ctt_vesta_ec_jac_neg(vesta_ec_jac* P, const vesta_ec_jac* Q); void ctt_vesta_ec_jac_neg_in_place(vesta_ec_jac* P); -void ctt_vesta_ec_jac_cneg_in_place(vesta_ec_jac* P, const secret_bool ctl); +void ctt_vesta_ec_jac_cneg_in_place(vesta_ec_jac* P, secret_bool ctl); void ctt_vesta_ec_jac_sum(vesta_ec_jac* r, const vesta_ec_jac* P, const vesta_ec_jac* Q); void ctt_vesta_ec_jac_add_in_place(vesta_ec_jac* P, const vesta_ec_jac* Q); void ctt_vesta_ec_jac_diff(vesta_ec_jac* r, const vesta_ec_jac* P, const vesta_ec_jac* Q); @@ -115,10 +115,10 @@ void ctt_vesta_ec_jac_from_affine(vesta_ec_jac* dst, const vesta_ec_aff* secret_bool ctt_vesta_ec_prj_is_eq(const vesta_ec_prj* P, const vesta_ec_prj* Q); secret_bool ctt_vesta_ec_prj_is_inf(const vesta_ec_prj* P); void ctt_vesta_ec_prj_set_inf(vesta_ec_prj* P); -void ctt_vesta_ec_prj_ccopy(vesta_ec_prj* P, const vesta_ec_prj* Q, const secret_bool ctl); +void ctt_vesta_ec_prj_ccopy(vesta_ec_prj* P, const vesta_ec_prj* Q, secret_bool ctl); void ctt_vesta_ec_prj_neg(vesta_ec_prj* P, const vesta_ec_prj* Q); void ctt_vesta_ec_prj_neg_in_place(vesta_ec_prj* P); -void ctt_vesta_ec_prj_cneg_in_place(vesta_ec_prj* P, const secret_bool ctl); +void ctt_vesta_ec_prj_cneg_in_place(vesta_ec_prj* P, secret_bool ctl); void ctt_vesta_ec_prj_sum(vesta_ec_prj* r, const vesta_ec_prj* P, const vesta_ec_prj* Q); void ctt_vesta_ec_prj_add_in_place(vesta_ec_prj* P, const vesta_ec_prj* Q); void ctt_vesta_ec_prj_diff(vesta_ec_prj* r, const vesta_ec_prj* P, const vesta_ec_prj* Q); @@ -127,10 +127,8 @@ void ctt_vesta_ec_prj_double_in_place(vesta_ec_prj* P); void ctt_vesta_ec_prj_affine(vesta_ec_aff* dst, const vesta_ec_prj* src); void ctt_vesta_ec_prj_from_affine(vesta_ec_prj* dst, const vesta_ec_aff* src); - #ifdef __cplusplus } #endif - -#endif +#endif // __CTT_H_VESTA__ diff --git a/include/constantine/curves/vesta_parallel.h b/include/constantine/curves/vesta_parallel.h new file mode 100644 index 00000000..314b6870 --- /dev/null +++ b/include/constantine/curves/vesta_parallel.h @@ -0,0 +1,28 @@ +/** 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_VESTA_PARALLEL__ +#define __CTT_H_VESTA_PARALLEL__ + +#include "constantine/core/datatypes.h" +#include "constantine/core/threadpool.h" +#include "constantine/curves/bigints.h" +#include "constantine/curves/vesta.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const vesta_ec_jac* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const vesta_ec_prj* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); + +#ifdef __cplusplus +} +#endif + +#endif // __CTT_H_VESTA_PARALLEL__ diff --git a/include/constantine/hashes/sha256.h b/include/constantine/hashes/sha256.h index a920528a..8a92a5ed 100644 --- a/include/constantine/hashes/sha256.h +++ b/include/constantine/hashes/sha256.h @@ -70,4 +70,4 @@ void ctt_sha256_hash(byte digest[32], const byte* message, ptrdiff_t message_len } #endif -#endif \ No newline at end of file +#endif // __CTT_H_SHA256__ \ No newline at end of file diff --git a/include/constantine/protocols/ethereum_bls_signatures.h b/include/constantine/protocols/ethereum_bls_signatures.h index 6bd32d40..332c87ba 100644 --- a/include/constantine/protocols/ethereum_bls_signatures.h +++ b/include/constantine/protocols/ethereum_bls_signatures.h @@ -232,4 +232,4 @@ ctt_eth_bls_status ctt_eth_bls_fast_aggregate_verify(const ctt_eth_bls_pubkey pu } #endif -#endif \ No newline at end of file +#endif // __CTT_H_ETHEREUM_BLS_SIGNATURES__ \ No newline at end of file From 28931d6eae5403d7eec341d437d5d7d0b526c22f Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Fri, 1 Dec 2023 16:18:54 +0100 Subject: [PATCH 02/24] fix LTO spurious warnings when building library --- constantine.nimble | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/constantine.nimble b/constantine.nimble index f8ac4f6e..77e6f6ca 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -168,7 +168,9 @@ proc releaseBuildOptions(buildMode = bmBinary): string = # "-s -flinker-output=nolto-rel" # with an extra C compiler call # to consolidate all objects into one. - let ltoFlags = " -d:lto " # " --UseAsmSyntaxIntel --passC:-flto=auto --passL:-flto=auto " + let ltoFlags = " -d:lto " & # " --UseAsmSyntaxIntel --passC:-flto=auto --passL:-flto=auto " + # With LTO, the GCC linker produces lots of spurious warnings when copying into openArrays/strings + " --passC:-Wno-stringop-overflow --passL:-Wno-stringop-overflow " let apple = defined(macos) or defined(macox) or defined(ios) let ltoOptions = if useLtoDefault: @@ -670,11 +672,6 @@ proc test(cmd: string) = exec cmd proc testBatch(commands: var string, flags, path: string) = - # With LTO, the linker produces lots of spurious warnings when copying into openArrays/strings - - let flags = if defined(gcc): flags & " --passC:-Wno-stringop-overflow --passL:-Wno-stringop-overflow " - else: flags - commands = commands & setupTestCommand(flags, path) & '\n' proc setupBench(benchName: string, run: bool): string = @@ -684,10 +681,6 @@ proc setupBench(benchName: string, run: bool): string = let asmStatus = if getEnvVars().useAsmIfAble: "asmIfAvailable" else: "noAsm" - if defined(gcc): - # With LTO, the linker produces lots of spurious warnings when copying into openArrays/strings - runFlags = runFlags & " --passC:-Wno-stringop-overflow --passL:-Wno-stringop-overflow " - let cc = if existsEnv"CC": getEnv"CC" else: "defaultcompiler" From 14634c648b3723682723eafd42233b8a2a68210f Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Fri, 1 Dec 2023 16:19:22 +0100 Subject: [PATCH 03/24] fix appType staticLib vs staticlib --- constantine/zoo_exports.nim | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/constantine/zoo_exports.nim b/constantine/zoo_exports.nim index 9b9d982a..ffd741e3 100644 --- a/constantine/zoo_exports.nim +++ b/constantine/zoo_exports.nim @@ -31,6 +31,28 @@ var prefix_sha256* {.compileTime.} = "ctt_sha256_" import std/macros +# macro libPrefix*(prefix: static string, procAst: untyped): untyped = +# if prefix == "": +# return procAst +# else: +# var pragmas = procAst.pragma +# if pragmas.kind == nnkEmpty: +# pragmas = nnkPragma.newTree() + +# pragmas.add ident"noconv" +# pragmas.add nnkExprColonExpr.newTree( +# ident"exportc", +# newLit(prefix & "$1")) +# pragmas.add nnkExprColonExpr.newTree( +# ident"raises", +# nnkBracket.newTree()) + +# if appType == "lib": +# pragmas.add ident"dynlib" + +# result = procAst +# result.pragma = pragmas + macro libPrefix*(prefix: static string, procAst: untyped): untyped = var pragmas = procAst.pragma if pragmas.kind == nnkEmpty: @@ -41,7 +63,7 @@ macro libPrefix*(prefix: static string, procAst: untyped): untyped = ident"raises", nnkBracket.newTree()) - if appType != "lib" and appType != "staticLib": + if appType != "lib" and appType != "staticlib": # extern only does name-mangling but allows for dead-code elimination. pragmas.add nnkExprColonExpr.newTree( ident"extern", @@ -58,4 +80,4 @@ macro libPrefix*(prefix: static string, procAst: untyped): untyped = pragmas.add ident"dynlib" result = procAst - result.pragma = pragmas + result.pragma = pragmas \ No newline at end of file From 1db3574f651fb3994ca4cbd1f66002a9df53538f Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Fri, 1 Dec 2023 17:25:58 +0100 Subject: [PATCH 04/24] fix threadpool --- .../constantine-curves/src/lib.rs | 36 ++++++++++++++++--- constantine-rust/constantine-sys/build.rs | 1 + constantine/threadpool.nim | 7 +++- constantine/threadpool/threadpool.nim | 2 +- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/constantine-rust/constantine-curves/src/lib.rs b/constantine-rust/constantine-curves/src/lib.rs index 7d12d9af..f4f216dc 100644 --- a/constantine-rust/constantine-curves/src/lib.rs +++ b/constantine-rust/constantine-curves/src/lib.rs @@ -1,14 +1,40 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +//! 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. + +use constantine_sys::*; + +pub struct CttThreadpool { + ctx: *mut ctt_threadpool, +} + +impl CttThreadpool { + #[inline(always)] + pub fn new(num_threads: usize) -> CttThreadpool { + let ctx = unsafe{ ctt_threadpool_new(num_threads) }; + CttThreadpool{ctx} + } } +impl Drop for CttThreadpool { + fn drop(&mut self) { + unsafe { ctt_threadpool_shutdown(self.ctx) } + } +} + + + #[cfg(test)] mod tests { use super::*; #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); + fn t_threadpool() { + let tp = CttThreadpool::new(4); + drop(tp); } } diff --git a/constantine-rust/constantine-sys/build.rs b/constantine-rust/constantine-sys/build.rs index 25b706c4..4887e130 100644 --- a/constantine-rust/constantine-sys/build.rs +++ b/constantine-rust/constantine-sys/build.rs @@ -18,6 +18,7 @@ fn main() { println!("cargo:rerun-if-changed={}", root_dir.join("Cargo.toml").display()); println!("cargo:rerun-if-changed={}", root_dir.join("constantine").display()); println!("cargo:rerun-if-changed={}", root_dir.join("bindings").display()); + println!("cargo:rerun-if-changed={}", root_dir.join("include").display()); println!("cargo:rerun-if-changed={}", root_dir.join("constantine.nimble").display()); println!("Building Constantine library ..."); diff --git a/constantine/threadpool.nim b/constantine/threadpool.nim index ec95382b..2821e347 100644 --- a/constantine/threadpool.nim +++ b/constantine/threadpool.nim @@ -7,4 +7,9 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import ./threadpool/[threadpool, partitioners] -export threadpool, partitioners \ No newline at end of file +import ./zoo_exports + +export threadpool, partitioners + +proc ctt_threadpool_new*(num_threads: csize_t): Threadpool {.libPrefix: "", raises: [ResourceExhaustedError].} = + Threadpool.new(cast[int](numThreads)) \ No newline at end of file diff --git a/constantine/threadpool/threadpool.nim b/constantine/threadpool/threadpool.nim index 33e34d3e..f53b70f7 100644 --- a/constantine/threadpool/threadpool.nim +++ b/constantine/threadpool/threadpool.nim @@ -940,7 +940,7 @@ proc wait(scopedBarrier: ptr ScopedBarrier) {.raises:[], gcsafe.} = # # # ############################################################ -proc new*(T: type Threadpool, numThreads = countProcessors()): T {.libPrefix: "ctt_threadpool_", raises: [ResourceExhaustedError].} = +proc new*(T: type Threadpool, numThreads = countProcessors()): T {.raises: [ResourceExhaustedError].} = ## Initialize a threadpool that manages `num_threads` threads. ## Default to the number of logical processors available. ## From 9aad9a06985ae3852bb3a1cff453d601f287a10c Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Fri, 1 Dec 2023 17:26:49 +0100 Subject: [PATCH 05/24] shorter EC FFI --- bindings/c_typedefs.nim | 2 +- bindings/lib_curves.nim | 56 +- bindings/lib_headers.nim | 12 +- .../constantine-sys/src/bindings.rs | 1003 +++++++++-------- include/constantine.h | 5 + include/constantine/curves/bls12_381.h | 152 +-- .../constantine/curves/bls12_381_parallel.h | 4 +- include/constantine/curves/bn254_snarks.h | 152 +-- .../curves/bn254_snarks_parallel.h | 4 +- include/constantine/curves/pallas_parallel.h | 4 +- include/constantine/curves/vesta_parallel.h | 4 +- 11 files changed, 738 insertions(+), 660 deletions(-) diff --git a/bindings/c_typedefs.nim b/bindings/c_typedefs.nim index 8d109db2..3c03d41f 100644 --- a/bindings/c_typedefs.nim +++ b/bindings/c_typedefs.nim @@ -128,7 +128,7 @@ let TypeMap {.compileTime.} = newStringTable({ # Parallel only, proc are so long we don't care about alignment "csize_t": "size_t", - "Threadpool": "ctt_threadpool*" + "Threadpool": "const ctt_threadpool*" }) proc toCrettype*(node: NimNode): string = diff --git a/bindings/lib_curves.nim b/bindings/lib_curves.nim index df0756ac..00ee069a 100644 --- a/bindings/lib_curves.nim +++ b/bindings/lib_curves.nim @@ -24,12 +24,12 @@ type bls12_381_fr = Fr[BLS12_381] bls12_381_fp = Fp[BLS12_381] bls12_381_fp2 = Fp2[BLS12_381] - bls12_381_ec_g1_aff = ECP_ShortW_Aff[Fp[BLS12_381], G1] - bls12_381_ec_g1_jac = ECP_ShortW_Jac[Fp[BLS12_381], G1] - bls12_381_ec_g1_prj = ECP_ShortW_Prj[Fp[BLS12_381], G1] - bls12_381_ec_g2_aff = ECP_ShortW_Aff[Fp2[BLS12_381], G2] - bls12_381_ec_g2_jac = ECP_ShortW_Jac[Fp2[BLS12_381], G2] - bls12_381_ec_g2_prj = ECP_ShortW_Prj[Fp2[BLS12_381], G2] + bls12_381_g1_aff = ECP_ShortW_Aff[Fp[BLS12_381], G1] + bls12_381_g1_jac = ECP_ShortW_Jac[Fp[BLS12_381], G1] + bls12_381_g1_prj = ECP_ShortW_Prj[Fp[BLS12_381], G1] + bls12_381_g2_aff = ECP_ShortW_Aff[Fp2[BLS12_381], G2] + bls12_381_g2_jac = ECP_ShortW_Jac[Fp2[BLS12_381], G2] + bls12_381_g2_prj = ECP_ShortW_Prj[Fp2[BLS12_381], G2] collectBindings(cBindings_bls12_381): genBindingsField(bls12_381_fr) @@ -37,28 +37,28 @@ collectBindings(cBindings_bls12_381): genBindingsFieldSqrt(bls12_381_fp) genBindingsExtField(bls12_381_fp2) genBindingsExtFieldSqrt(bls12_381_fp2) - genBindings_EC_ShortW_Affine(bls12_381_ec_g1_aff, bls12_381_fp) - genBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_jac, bls12_381_ec_g1_aff) - genBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_prj, bls12_381_ec_g1_aff) - genBindings_EC_ShortW_Affine(bls12_381_ec_g2_aff, bls12_381_fp2) - genBindings_EC_ShortW_NonAffine(bls12_381_ec_g2_jac, bls12_381_ec_g2_aff) - genBindings_EC_ShortW_NonAffine(bls12_381_ec_g2_prj, bls12_381_ec_g2_aff) + genBindings_EC_ShortW_Affine(bls12_381_g1_aff, bls12_381_fp) + genBindings_EC_ShortW_NonAffine(bls12_381_g1_jac, bls12_381_g1_aff) + genBindings_EC_ShortW_NonAffine(bls12_381_g1_prj, bls12_381_g1_aff) + genBindings_EC_ShortW_Affine(bls12_381_g2_aff, bls12_381_fp2) + genBindings_EC_ShortW_NonAffine(bls12_381_g2_jac, bls12_381_g2_aff) + genBindings_EC_ShortW_NonAffine(bls12_381_g2_prj, bls12_381_g2_aff) collectBindings(cBindings_bls12_381_parallel): - genParallelBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_jac, bls12_381_ec_g1_aff) - genParallelBindings_EC_ShortW_NonAffine(bls12_381_ec_g1_prj, bls12_381_ec_g1_aff) + genParallelBindings_EC_ShortW_NonAffine(bls12_381_g1_jac, bls12_381_g1_aff) + genParallelBindings_EC_ShortW_NonAffine(bls12_381_g1_prj, bls12_381_g1_aff) # ---------------------------------------------------------- type bn254_snarks_fr = Fr[BN254_Snarks] bn254_snarks_fp = Fp[BN254_Snarks] bn254_snarks_fp2 = Fp2[BN254_Snarks] - bn254_snarks_ec_g1_aff = ECP_ShortW_Aff[Fp[BN254_Snarks], G1] - bn254_snarks_ec_g1_jac = ECP_ShortW_Jac[Fp[BN254_Snarks], G1] - bn254_snarks_ec_g1_prj = ECP_ShortW_Prj[Fp[BN254_Snarks], G1] - bn254_snarks_ec_g2_aff = ECP_ShortW_Aff[Fp2[BN254_Snarks], G2] - bn254_snarks_ec_g2_jac = ECP_ShortW_Jac[Fp2[BN254_Snarks], G2] - bn254_snarks_ec_g2_prj = ECP_ShortW_Prj[Fp2[BN254_Snarks], G2] + bn254_snarks_g1_aff = ECP_ShortW_Aff[Fp[BN254_Snarks], G1] + bn254_snarks_g1_jac = ECP_ShortW_Jac[Fp[BN254_Snarks], G1] + bn254_snarks_g1_prj = ECP_ShortW_Prj[Fp[BN254_Snarks], G1] + bn254_snarks_g2_aff = ECP_ShortW_Aff[Fp2[BN254_Snarks], G2] + bn254_snarks_g2_jac = ECP_ShortW_Jac[Fp2[BN254_Snarks], G2] + bn254_snarks_g2_prj = ECP_ShortW_Prj[Fp2[BN254_Snarks], G2] collectBindings(cBindings_bn254_snarks): genBindingsField(bn254_snarks_fr) @@ -66,16 +66,16 @@ collectBindings(cBindings_bn254_snarks): genBindingsFieldSqrt(bn254_snarks_fp) genBindingsExtField(bn254_snarks_fp2) genBindingsExtFieldSqrt(bn254_snarks_fp2) - genBindings_EC_ShortW_Affine(bn254_snarks_ec_g1_aff, bn254_snarks_fp) - genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_jac, bn254_snarks_ec_g1_aff) - genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_prj, bn254_snarks_ec_g1_aff) - genBindings_EC_ShortW_Affine(bn254_snarks_ec_g2_aff, bn254_snarks_fp2) - genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g2_jac, bn254_snarks_ec_g2_aff) - genBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g2_prj, bn254_snarks_ec_g2_aff) + genBindings_EC_ShortW_Affine(bn254_snarks_g1_aff, bn254_snarks_fp) + genBindings_EC_ShortW_NonAffine(bn254_snarks_g1_jac, bn254_snarks_g1_aff) + genBindings_EC_ShortW_NonAffine(bn254_snarks_g1_prj, bn254_snarks_g1_aff) + genBindings_EC_ShortW_Affine(bn254_snarks_g2_aff, bn254_snarks_fp2) + genBindings_EC_ShortW_NonAffine(bn254_snarks_g2_jac, bn254_snarks_g2_aff) + genBindings_EC_ShortW_NonAffine(bn254_snarks_g2_prj, bn254_snarks_g2_aff) collectBindings(cBindings_bn254_snarks_parallel): - genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_jac, bn254_snarks_ec_g1_aff) - genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_ec_g1_prj, bn254_snarks_ec_g1_aff) + genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_g1_jac, bn254_snarks_g1_aff) + genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_g1_prj, bn254_snarks_g1_aff) # ---------------------------------------------------------- diff --git a/bindings/lib_headers.nim b/bindings/lib_headers.nim index 798a5319..e9780bea 100644 --- a/bindings/lib_headers.nim +++ b/bindings/lib_headers.nim @@ -48,17 +48,17 @@ proc writeHeader_pairingFriendly(filepath: string, curve: string, modBits, order header &= '\n' header &= genExtField(&"{curve}_fp2", 2, &"{curve}_fp") header &= '\n' - header &= genEllipticCurvePoint(&"{curve}_ec_g1_aff", "x, y", &"{curve}_fp") + header &= genEllipticCurvePoint(&"{curve}_g1_aff", "x, y", &"{curve}_fp") header &= '\n' - header &= genEllipticCurvePoint(&"{curve}_ec_g1_jac", "x, y, z", &"{curve}_fp") + header &= genEllipticCurvePoint(&"{curve}_g1_jac", "x, y, z", &"{curve}_fp") header &= '\n' - header &= genEllipticCurvePoint(&"{curve}_ec_g1_prj", "x, y, z", &"{curve}_fp") + header &= genEllipticCurvePoint(&"{curve}_g1_prj", "x, y, z", &"{curve}_fp") header &= '\n' - header &= genEllipticCurvePoint(&"{curve}_ec_g2_aff", "x, y", &"{curve}_{fpK}") + header &= genEllipticCurvePoint(&"{curve}_g2_aff", "x, y", &"{curve}_{fpK}") header &= '\n' - header &= genEllipticCurvePoint(&"{curve}_ec_g2_jac", "x, y, z", &"{curve}_{fpK}") + header &= genEllipticCurvePoint(&"{curve}_g2_jac", "x, y, z", &"{curve}_{fpK}") header &= '\n' - header &= genEllipticCurvePoint(&"{curve}_ec_g2_prj", "x, y, z", &"{curve}_{fpK}") + header &= genEllipticCurvePoint(&"{curve}_g2_prj", "x, y, z", &"{curve}_{fpK}") header &= '\n' header &= curve_decls header &= '\n' diff --git a/constantine-rust/constantine-sys/src/bindings.rs b/constantine-rust/constantine-sys/src/bindings.rs index bc85c68f..34161a8a 100644 --- a/constantine-rust/constantine-sys/src/bindings.rs +++ b/constantine-rust/constantine-sys/src/bindings.rs @@ -1,4 +1,4 @@ -/* automatically generated by rust-bindgen 0.68.1 */ +/* automatically generated by rust-bindgen 0.69.1 */ pub type secret_word = usize; pub type secret_bool = usize; @@ -177,31 +177,30 @@ fn bindgen_test_layout_bls12_381_fp2() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bls12_381_ec_g1_aff { +pub struct bls12_381_g1_aff { x: bls12_381_fp, y: bls12_381_fp, } #[test] -fn bindgen_test_layout_bls12_381_ec_g1_aff() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_bls12_381_g1_aff() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 96usize, - concat!("Size of: ", stringify!(bls12_381_ec_g1_aff)) + concat!("Size of: ", stringify!(bls12_381_g1_aff)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bls12_381_ec_g1_aff)) + concat!("Alignment of ", stringify!(bls12_381_g1_aff)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g1_aff), + stringify!(bls12_381_g1_aff), "::", stringify!(x) ) @@ -211,7 +210,7 @@ fn bindgen_test_layout_bls12_381_ec_g1_aff() { 48usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g1_aff), + stringify!(bls12_381_g1_aff), "::", stringify!(y) ) @@ -219,32 +218,31 @@ fn bindgen_test_layout_bls12_381_ec_g1_aff() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bls12_381_ec_g1_jac { +pub struct bls12_381_g1_jac { x: bls12_381_fp, y: bls12_381_fp, z: bls12_381_fp, } #[test] -fn bindgen_test_layout_bls12_381_ec_g1_jac() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_bls12_381_g1_jac() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 144usize, - concat!("Size of: ", stringify!(bls12_381_ec_g1_jac)) + concat!("Size of: ", stringify!(bls12_381_g1_jac)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bls12_381_ec_g1_jac)) + concat!("Alignment of ", stringify!(bls12_381_g1_jac)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g1_jac), + stringify!(bls12_381_g1_jac), "::", stringify!(x) ) @@ -254,7 +252,7 @@ fn bindgen_test_layout_bls12_381_ec_g1_jac() { 48usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g1_jac), + stringify!(bls12_381_g1_jac), "::", stringify!(y) ) @@ -264,7 +262,7 @@ fn bindgen_test_layout_bls12_381_ec_g1_jac() { 96usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g1_jac), + stringify!(bls12_381_g1_jac), "::", stringify!(z) ) @@ -272,32 +270,31 @@ fn bindgen_test_layout_bls12_381_ec_g1_jac() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bls12_381_ec_g1_prj { +pub struct bls12_381_g1_prj { x: bls12_381_fp, y: bls12_381_fp, z: bls12_381_fp, } #[test] -fn bindgen_test_layout_bls12_381_ec_g1_prj() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_bls12_381_g1_prj() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 144usize, - concat!("Size of: ", stringify!(bls12_381_ec_g1_prj)) + concat!("Size of: ", stringify!(bls12_381_g1_prj)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bls12_381_ec_g1_prj)) + concat!("Alignment of ", stringify!(bls12_381_g1_prj)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g1_prj), + stringify!(bls12_381_g1_prj), "::", stringify!(x) ) @@ -307,7 +304,7 @@ fn bindgen_test_layout_bls12_381_ec_g1_prj() { 48usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g1_prj), + stringify!(bls12_381_g1_prj), "::", stringify!(y) ) @@ -317,7 +314,7 @@ fn bindgen_test_layout_bls12_381_ec_g1_prj() { 96usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g1_prj), + stringify!(bls12_381_g1_prj), "::", stringify!(z) ) @@ -325,31 +322,30 @@ fn bindgen_test_layout_bls12_381_ec_g1_prj() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bls12_381_ec_g2_aff { +pub struct bls12_381_g2_aff { x: bls12_381_fp2, y: bls12_381_fp2, } #[test] -fn bindgen_test_layout_bls12_381_ec_g2_aff() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_bls12_381_g2_aff() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 192usize, - concat!("Size of: ", stringify!(bls12_381_ec_g2_aff)) + concat!("Size of: ", stringify!(bls12_381_g2_aff)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bls12_381_ec_g2_aff)) + concat!("Alignment of ", stringify!(bls12_381_g2_aff)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g2_aff), + stringify!(bls12_381_g2_aff), "::", stringify!(x) ) @@ -359,7 +355,7 @@ fn bindgen_test_layout_bls12_381_ec_g2_aff() { 96usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g2_aff), + stringify!(bls12_381_g2_aff), "::", stringify!(y) ) @@ -367,32 +363,31 @@ fn bindgen_test_layout_bls12_381_ec_g2_aff() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bls12_381_ec_g2_jac { +pub struct bls12_381_g2_jac { x: bls12_381_fp2, y: bls12_381_fp2, z: bls12_381_fp2, } #[test] -fn bindgen_test_layout_bls12_381_ec_g2_jac() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_bls12_381_g2_jac() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 288usize, - concat!("Size of: ", stringify!(bls12_381_ec_g2_jac)) + concat!("Size of: ", stringify!(bls12_381_g2_jac)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bls12_381_ec_g2_jac)) + concat!("Alignment of ", stringify!(bls12_381_g2_jac)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g2_jac), + stringify!(bls12_381_g2_jac), "::", stringify!(x) ) @@ -402,7 +397,7 @@ fn bindgen_test_layout_bls12_381_ec_g2_jac() { 96usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g2_jac), + stringify!(bls12_381_g2_jac), "::", stringify!(y) ) @@ -412,7 +407,7 @@ fn bindgen_test_layout_bls12_381_ec_g2_jac() { 192usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g2_jac), + stringify!(bls12_381_g2_jac), "::", stringify!(z) ) @@ -420,32 +415,31 @@ fn bindgen_test_layout_bls12_381_ec_g2_jac() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bls12_381_ec_g2_prj { +pub struct bls12_381_g2_prj { x: bls12_381_fp2, y: bls12_381_fp2, z: bls12_381_fp2, } #[test] -fn bindgen_test_layout_bls12_381_ec_g2_prj() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); +fn bindgen_test_layout_bls12_381_g2_prj() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 288usize, - concat!("Size of: ", stringify!(bls12_381_ec_g2_prj)) + concat!("Size of: ", stringify!(bls12_381_g2_prj)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bls12_381_ec_g2_prj)) + concat!("Alignment of ", stringify!(bls12_381_g2_prj)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g2_prj), + stringify!(bls12_381_g2_prj), "::", stringify!(x) ) @@ -455,7 +449,7 @@ fn bindgen_test_layout_bls12_381_ec_g2_prj() { 96usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g2_prj), + stringify!(bls12_381_g2_prj), "::", stringify!(y) ) @@ -465,7 +459,7 @@ fn bindgen_test_layout_bls12_381_ec_g2_prj() { 192usize, concat!( "Offset of field: ", - stringify!(bls12_381_ec_g2_prj), + stringify!(bls12_381_g2_prj), "::", stringify!(z) ) @@ -884,341 +878,305 @@ extern "C" { pub fn ctt_bls12_381_fp2_sqrt_if_square_in_place(a: *mut bls12_381_fp2) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g1_aff_is_eq( - P: *const bls12_381_ec_g1_aff, - Q: *const bls12_381_ec_g1_aff, + pub fn ctt_bls12_381_g1_aff_is_eq( + P: *const bls12_381_g1_aff, + Q: *const bls12_381_g1_aff, ) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g1_aff_is_inf(P: *const bls12_381_ec_g1_aff) -> secret_bool; + pub fn ctt_bls12_381_g1_aff_is_inf(P: *const bls12_381_g1_aff) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g1_aff_set_inf(P: *mut bls12_381_ec_g1_aff); + pub fn ctt_bls12_381_g1_aff_set_inf(P: *mut bls12_381_g1_aff); } extern "C" { - pub fn ctt_bls12_381_ec_g1_aff_ccopy( - P: *mut bls12_381_ec_g1_aff, - Q: *const bls12_381_ec_g1_aff, + pub fn ctt_bls12_381_g1_aff_ccopy( + P: *mut bls12_381_g1_aff, + Q: *const bls12_381_g1_aff, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bls12_381_ec_g1_aff_is_on_curve( + pub fn ctt_bls12_381_g1_aff_is_on_curve( x: *const bls12_381_fp, y: *const bls12_381_fp, ) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g1_aff_neg(P: *mut bls12_381_ec_g1_aff, Q: *const bls12_381_ec_g1_aff); + pub fn ctt_bls12_381_g1_aff_neg(P: *mut bls12_381_g1_aff, Q: *const bls12_381_g1_aff); } extern "C" { - pub fn ctt_bls12_381_ec_g1_aff_neg_in_place(P: *mut bls12_381_ec_g1_aff); + pub fn ctt_bls12_381_g1_aff_neg_in_place(P: *mut bls12_381_g1_aff); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_is_eq( - P: *const bls12_381_ec_g1_jac, - Q: *const bls12_381_ec_g1_jac, + pub fn ctt_bls12_381_g1_jac_is_eq( + P: *const bls12_381_g1_jac, + Q: *const bls12_381_g1_jac, ) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_is_inf(P: *const bls12_381_ec_g1_jac) -> secret_bool; + pub fn ctt_bls12_381_g1_jac_is_inf(P: *const bls12_381_g1_jac) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_set_inf(P: *mut bls12_381_ec_g1_jac); + pub fn ctt_bls12_381_g1_jac_set_inf(P: *mut bls12_381_g1_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_ccopy( - P: *mut bls12_381_ec_g1_jac, - Q: *const bls12_381_ec_g1_jac, + pub fn ctt_bls12_381_g1_jac_ccopy( + P: *mut bls12_381_g1_jac, + Q: *const bls12_381_g1_jac, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_neg(P: *mut bls12_381_ec_g1_jac, Q: *const bls12_381_ec_g1_jac); + pub fn ctt_bls12_381_g1_jac_neg(P: *mut bls12_381_g1_jac, Q: *const bls12_381_g1_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_neg_in_place(P: *mut bls12_381_ec_g1_jac); + pub fn ctt_bls12_381_g1_jac_neg_in_place(P: *mut bls12_381_g1_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_cneg_in_place(P: *mut bls12_381_ec_g1_jac, ctl: secret_bool); + pub fn ctt_bls12_381_g1_jac_cneg_in_place(P: *mut bls12_381_g1_jac, ctl: secret_bool); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_sum( - r: *mut bls12_381_ec_g1_jac, - P: *const bls12_381_ec_g1_jac, - Q: *const bls12_381_ec_g1_jac, + pub fn ctt_bls12_381_g1_jac_sum( + r: *mut bls12_381_g1_jac, + P: *const bls12_381_g1_jac, + Q: *const bls12_381_g1_jac, ); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_add_in_place( - P: *mut bls12_381_ec_g1_jac, - Q: *const bls12_381_ec_g1_jac, - ); + pub fn ctt_bls12_381_g1_jac_add_in_place(P: *mut bls12_381_g1_jac, Q: *const bls12_381_g1_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_diff( - r: *mut bls12_381_ec_g1_jac, - P: *const bls12_381_ec_g1_jac, - Q: *const bls12_381_ec_g1_jac, + pub fn ctt_bls12_381_g1_jac_diff( + r: *mut bls12_381_g1_jac, + P: *const bls12_381_g1_jac, + Q: *const bls12_381_g1_jac, ); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_double( - r: *mut bls12_381_ec_g1_jac, - P: *const bls12_381_ec_g1_jac, - ); + pub fn ctt_bls12_381_g1_jac_double(r: *mut bls12_381_g1_jac, P: *const bls12_381_g1_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_double_in_place(P: *mut bls12_381_ec_g1_jac); + pub fn ctt_bls12_381_g1_jac_double_in_place(P: *mut bls12_381_g1_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_affine( - dst: *mut bls12_381_ec_g1_aff, - src: *const bls12_381_ec_g1_jac, - ); + pub fn ctt_bls12_381_g1_jac_affine(dst: *mut bls12_381_g1_aff, src: *const bls12_381_g1_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g1_jac_from_affine( - dst: *mut bls12_381_ec_g1_jac, - src: *const bls12_381_ec_g1_aff, + pub fn ctt_bls12_381_g1_jac_from_affine( + dst: *mut bls12_381_g1_jac, + src: *const bls12_381_g1_aff, ); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_is_eq( - P: *const bls12_381_ec_g1_prj, - Q: *const bls12_381_ec_g1_prj, + pub fn ctt_bls12_381_g1_prj_is_eq( + P: *const bls12_381_g1_prj, + Q: *const bls12_381_g1_prj, ) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_is_inf(P: *const bls12_381_ec_g1_prj) -> secret_bool; + pub fn ctt_bls12_381_g1_prj_is_inf(P: *const bls12_381_g1_prj) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_set_inf(P: *mut bls12_381_ec_g1_prj); + pub fn ctt_bls12_381_g1_prj_set_inf(P: *mut bls12_381_g1_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_ccopy( - P: *mut bls12_381_ec_g1_prj, - Q: *const bls12_381_ec_g1_prj, + pub fn ctt_bls12_381_g1_prj_ccopy( + P: *mut bls12_381_g1_prj, + Q: *const bls12_381_g1_prj, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_neg(P: *mut bls12_381_ec_g1_prj, Q: *const bls12_381_ec_g1_prj); + pub fn ctt_bls12_381_g1_prj_neg(P: *mut bls12_381_g1_prj, Q: *const bls12_381_g1_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_neg_in_place(P: *mut bls12_381_ec_g1_prj); + pub fn ctt_bls12_381_g1_prj_neg_in_place(P: *mut bls12_381_g1_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_cneg_in_place(P: *mut bls12_381_ec_g1_prj, ctl: secret_bool); + pub fn ctt_bls12_381_g1_prj_cneg_in_place(P: *mut bls12_381_g1_prj, ctl: secret_bool); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_sum( - r: *mut bls12_381_ec_g1_prj, - P: *const bls12_381_ec_g1_prj, - Q: *const bls12_381_ec_g1_prj, + pub fn ctt_bls12_381_g1_prj_sum( + r: *mut bls12_381_g1_prj, + P: *const bls12_381_g1_prj, + Q: *const bls12_381_g1_prj, ); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_add_in_place( - P: *mut bls12_381_ec_g1_prj, - Q: *const bls12_381_ec_g1_prj, - ); + pub fn ctt_bls12_381_g1_prj_add_in_place(P: *mut bls12_381_g1_prj, Q: *const bls12_381_g1_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_diff( - r: *mut bls12_381_ec_g1_prj, - P: *const bls12_381_ec_g1_prj, - Q: *const bls12_381_ec_g1_prj, + pub fn ctt_bls12_381_g1_prj_diff( + r: *mut bls12_381_g1_prj, + P: *const bls12_381_g1_prj, + Q: *const bls12_381_g1_prj, ); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_double( - r: *mut bls12_381_ec_g1_prj, - P: *const bls12_381_ec_g1_prj, - ); + pub fn ctt_bls12_381_g1_prj_double(r: *mut bls12_381_g1_prj, P: *const bls12_381_g1_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_double_in_place(P: *mut bls12_381_ec_g1_prj); + pub fn ctt_bls12_381_g1_prj_double_in_place(P: *mut bls12_381_g1_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_affine( - dst: *mut bls12_381_ec_g1_aff, - src: *const bls12_381_ec_g1_prj, - ); + pub fn ctt_bls12_381_g1_prj_affine(dst: *mut bls12_381_g1_aff, src: *const bls12_381_g1_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g1_prj_from_affine( - dst: *mut bls12_381_ec_g1_prj, - src: *const bls12_381_ec_g1_aff, + pub fn ctt_bls12_381_g1_prj_from_affine( + dst: *mut bls12_381_g1_prj, + src: *const bls12_381_g1_aff, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_aff_is_eq( - P: *const bls12_381_ec_g2_aff, - Q: *const bls12_381_ec_g2_aff, + pub fn ctt_bls12_381_g2_aff_is_eq( + P: *const bls12_381_g2_aff, + Q: *const bls12_381_g2_aff, ) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g2_aff_is_inf(P: *const bls12_381_ec_g2_aff) -> secret_bool; + pub fn ctt_bls12_381_g2_aff_is_inf(P: *const bls12_381_g2_aff) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g2_aff_set_inf(P: *mut bls12_381_ec_g2_aff); + pub fn ctt_bls12_381_g2_aff_set_inf(P: *mut bls12_381_g2_aff); } extern "C" { - pub fn ctt_bls12_381_ec_g2_aff_ccopy( - P: *mut bls12_381_ec_g2_aff, - Q: *const bls12_381_ec_g2_aff, + pub fn ctt_bls12_381_g2_aff_ccopy( + P: *mut bls12_381_g2_aff, + Q: *const bls12_381_g2_aff, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_aff_is_on_curve( + pub fn ctt_bls12_381_g2_aff_is_on_curve( x: *const bls12_381_fp2, y: *const bls12_381_fp2, ) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g2_aff_neg(P: *mut bls12_381_ec_g2_aff, Q: *const bls12_381_ec_g2_aff); + pub fn ctt_bls12_381_g2_aff_neg(P: *mut bls12_381_g2_aff, Q: *const bls12_381_g2_aff); } extern "C" { - pub fn ctt_bls12_381_ec_g2_aff_neg_in_place(P: *mut bls12_381_ec_g2_aff); + pub fn ctt_bls12_381_g2_aff_neg_in_place(P: *mut bls12_381_g2_aff); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_is_eq( - P: *const bls12_381_ec_g2_jac, - Q: *const bls12_381_ec_g2_jac, + pub fn ctt_bls12_381_g2_jac_is_eq( + P: *const bls12_381_g2_jac, + Q: *const bls12_381_g2_jac, ) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_is_inf(P: *const bls12_381_ec_g2_jac) -> secret_bool; + pub fn ctt_bls12_381_g2_jac_is_inf(P: *const bls12_381_g2_jac) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_set_inf(P: *mut bls12_381_ec_g2_jac); + pub fn ctt_bls12_381_g2_jac_set_inf(P: *mut bls12_381_g2_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_ccopy( - P: *mut bls12_381_ec_g2_jac, - Q: *const bls12_381_ec_g2_jac, + pub fn ctt_bls12_381_g2_jac_ccopy( + P: *mut bls12_381_g2_jac, + Q: *const bls12_381_g2_jac, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_neg(P: *mut bls12_381_ec_g2_jac, Q: *const bls12_381_ec_g2_jac); + pub fn ctt_bls12_381_g2_jac_neg(P: *mut bls12_381_g2_jac, Q: *const bls12_381_g2_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_neg_in_place(P: *mut bls12_381_ec_g2_jac); + pub fn ctt_bls12_381_g2_jac_neg_in_place(P: *mut bls12_381_g2_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_cneg_in_place(P: *mut bls12_381_ec_g2_jac, ctl: secret_bool); + pub fn ctt_bls12_381_g2_jac_cneg_in_place(P: *mut bls12_381_g2_jac, ctl: secret_bool); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_sum( - r: *mut bls12_381_ec_g2_jac, - P: *const bls12_381_ec_g2_jac, - Q: *const bls12_381_ec_g2_jac, + pub fn ctt_bls12_381_g2_jac_sum( + r: *mut bls12_381_g2_jac, + P: *const bls12_381_g2_jac, + Q: *const bls12_381_g2_jac, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_add_in_place( - P: *mut bls12_381_ec_g2_jac, - Q: *const bls12_381_ec_g2_jac, - ); + pub fn ctt_bls12_381_g2_jac_add_in_place(P: *mut bls12_381_g2_jac, Q: *const bls12_381_g2_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_diff( - r: *mut bls12_381_ec_g2_jac, - P: *const bls12_381_ec_g2_jac, - Q: *const bls12_381_ec_g2_jac, + pub fn ctt_bls12_381_g2_jac_diff( + r: *mut bls12_381_g2_jac, + P: *const bls12_381_g2_jac, + Q: *const bls12_381_g2_jac, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_double( - r: *mut bls12_381_ec_g2_jac, - P: *const bls12_381_ec_g2_jac, - ); + pub fn ctt_bls12_381_g2_jac_double(r: *mut bls12_381_g2_jac, P: *const bls12_381_g2_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_double_in_place(P: *mut bls12_381_ec_g2_jac); + pub fn ctt_bls12_381_g2_jac_double_in_place(P: *mut bls12_381_g2_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_affine( - dst: *mut bls12_381_ec_g2_aff, - src: *const bls12_381_ec_g2_jac, - ); + pub fn ctt_bls12_381_g2_jac_affine(dst: *mut bls12_381_g2_aff, src: *const bls12_381_g2_jac); } extern "C" { - pub fn ctt_bls12_381_ec_g2_jac_from_affine( - dst: *mut bls12_381_ec_g2_jac, - src: *const bls12_381_ec_g2_aff, + pub fn ctt_bls12_381_g2_jac_from_affine( + dst: *mut bls12_381_g2_jac, + src: *const bls12_381_g2_aff, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_is_eq( - P: *const bls12_381_ec_g2_prj, - Q: *const bls12_381_ec_g2_prj, + pub fn ctt_bls12_381_g2_prj_is_eq( + P: *const bls12_381_g2_prj, + Q: *const bls12_381_g2_prj, ) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_is_inf(P: *const bls12_381_ec_g2_prj) -> secret_bool; + pub fn ctt_bls12_381_g2_prj_is_inf(P: *const bls12_381_g2_prj) -> secret_bool; } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_set_inf(P: *mut bls12_381_ec_g2_prj); + pub fn ctt_bls12_381_g2_prj_set_inf(P: *mut bls12_381_g2_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_ccopy( - P: *mut bls12_381_ec_g2_prj, - Q: *const bls12_381_ec_g2_prj, + pub fn ctt_bls12_381_g2_prj_ccopy( + P: *mut bls12_381_g2_prj, + Q: *const bls12_381_g2_prj, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_neg(P: *mut bls12_381_ec_g2_prj, Q: *const bls12_381_ec_g2_prj); + pub fn ctt_bls12_381_g2_prj_neg(P: *mut bls12_381_g2_prj, Q: *const bls12_381_g2_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_neg_in_place(P: *mut bls12_381_ec_g2_prj); + pub fn ctt_bls12_381_g2_prj_neg_in_place(P: *mut bls12_381_g2_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_cneg_in_place(P: *mut bls12_381_ec_g2_prj, ctl: secret_bool); + pub fn ctt_bls12_381_g2_prj_cneg_in_place(P: *mut bls12_381_g2_prj, ctl: secret_bool); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_sum( - r: *mut bls12_381_ec_g2_prj, - P: *const bls12_381_ec_g2_prj, - Q: *const bls12_381_ec_g2_prj, + pub fn ctt_bls12_381_g2_prj_sum( + r: *mut bls12_381_g2_prj, + P: *const bls12_381_g2_prj, + Q: *const bls12_381_g2_prj, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_add_in_place( - P: *mut bls12_381_ec_g2_prj, - Q: *const bls12_381_ec_g2_prj, - ); + pub fn ctt_bls12_381_g2_prj_add_in_place(P: *mut bls12_381_g2_prj, Q: *const bls12_381_g2_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_diff( - r: *mut bls12_381_ec_g2_prj, - P: *const bls12_381_ec_g2_prj, - Q: *const bls12_381_ec_g2_prj, + pub fn ctt_bls12_381_g2_prj_diff( + r: *mut bls12_381_g2_prj, + P: *const bls12_381_g2_prj, + Q: *const bls12_381_g2_prj, ); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_double( - r: *mut bls12_381_ec_g2_prj, - P: *const bls12_381_ec_g2_prj, - ); + pub fn ctt_bls12_381_g2_prj_double(r: *mut bls12_381_g2_prj, P: *const bls12_381_g2_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_double_in_place(P: *mut bls12_381_ec_g2_prj); + pub fn ctt_bls12_381_g2_prj_double_in_place(P: *mut bls12_381_g2_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_affine( - dst: *mut bls12_381_ec_g2_aff, - src: *const bls12_381_ec_g2_prj, - ); + pub fn ctt_bls12_381_g2_prj_affine(dst: *mut bls12_381_g2_aff, src: *const bls12_381_g2_prj); } extern "C" { - pub fn ctt_bls12_381_ec_g2_prj_from_affine( - dst: *mut bls12_381_ec_g2_prj, - src: *const bls12_381_ec_g2_aff, + pub fn ctt_bls12_381_g2_prj_from_affine( + dst: *mut bls12_381_g2_prj, + src: *const bls12_381_g2_aff, ); } #[repr(C)] @@ -1313,31 +1271,31 @@ fn bindgen_test_layout_bn254_snarks_fp2() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bn254_snarks_ec_g1_aff { +pub struct bn254_snarks_g1_aff { x: bn254_snarks_fp, y: bn254_snarks_fp, } #[test] -fn bindgen_test_layout_bn254_snarks_ec_g1_aff() { - const UNINIT: ::core::mem::MaybeUninit = +fn bindgen_test_layout_bn254_snarks_g1_aff() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 64usize, - concat!("Size of: ", stringify!(bn254_snarks_ec_g1_aff)) + concat!("Size of: ", stringify!(bn254_snarks_g1_aff)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bn254_snarks_ec_g1_aff)) + concat!("Alignment of ", stringify!(bn254_snarks_g1_aff)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g1_aff), + stringify!(bn254_snarks_g1_aff), "::", stringify!(x) ) @@ -1347,7 +1305,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g1_aff() { 32usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g1_aff), + stringify!(bn254_snarks_g1_aff), "::", stringify!(y) ) @@ -1355,32 +1313,32 @@ fn bindgen_test_layout_bn254_snarks_ec_g1_aff() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bn254_snarks_ec_g1_jac { +pub struct bn254_snarks_g1_jac { x: bn254_snarks_fp, y: bn254_snarks_fp, z: bn254_snarks_fp, } #[test] -fn bindgen_test_layout_bn254_snarks_ec_g1_jac() { - const UNINIT: ::core::mem::MaybeUninit = +fn bindgen_test_layout_bn254_snarks_g1_jac() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 96usize, - concat!("Size of: ", stringify!(bn254_snarks_ec_g1_jac)) + concat!("Size of: ", stringify!(bn254_snarks_g1_jac)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bn254_snarks_ec_g1_jac)) + concat!("Alignment of ", stringify!(bn254_snarks_g1_jac)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g1_jac), + stringify!(bn254_snarks_g1_jac), "::", stringify!(x) ) @@ -1390,7 +1348,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g1_jac() { 32usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g1_jac), + stringify!(bn254_snarks_g1_jac), "::", stringify!(y) ) @@ -1400,7 +1358,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g1_jac() { 64usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g1_jac), + stringify!(bn254_snarks_g1_jac), "::", stringify!(z) ) @@ -1408,32 +1366,32 @@ fn bindgen_test_layout_bn254_snarks_ec_g1_jac() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bn254_snarks_ec_g1_prj { +pub struct bn254_snarks_g1_prj { x: bn254_snarks_fp, y: bn254_snarks_fp, z: bn254_snarks_fp, } #[test] -fn bindgen_test_layout_bn254_snarks_ec_g1_prj() { - const UNINIT: ::core::mem::MaybeUninit = +fn bindgen_test_layout_bn254_snarks_g1_prj() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 96usize, - concat!("Size of: ", stringify!(bn254_snarks_ec_g1_prj)) + concat!("Size of: ", stringify!(bn254_snarks_g1_prj)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bn254_snarks_ec_g1_prj)) + concat!("Alignment of ", stringify!(bn254_snarks_g1_prj)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g1_prj), + stringify!(bn254_snarks_g1_prj), "::", stringify!(x) ) @@ -1443,7 +1401,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g1_prj() { 32usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g1_prj), + stringify!(bn254_snarks_g1_prj), "::", stringify!(y) ) @@ -1453,7 +1411,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g1_prj() { 64usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g1_prj), + stringify!(bn254_snarks_g1_prj), "::", stringify!(z) ) @@ -1461,31 +1419,31 @@ fn bindgen_test_layout_bn254_snarks_ec_g1_prj() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bn254_snarks_ec_g2_aff { +pub struct bn254_snarks_g2_aff { x: bn254_snarks_fp2, y: bn254_snarks_fp2, } #[test] -fn bindgen_test_layout_bn254_snarks_ec_g2_aff() { - const UNINIT: ::core::mem::MaybeUninit = +fn bindgen_test_layout_bn254_snarks_g2_aff() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 128usize, - concat!("Size of: ", stringify!(bn254_snarks_ec_g2_aff)) + concat!("Size of: ", stringify!(bn254_snarks_g2_aff)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bn254_snarks_ec_g2_aff)) + concat!("Alignment of ", stringify!(bn254_snarks_g2_aff)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g2_aff), + stringify!(bn254_snarks_g2_aff), "::", stringify!(x) ) @@ -1495,7 +1453,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g2_aff() { 64usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g2_aff), + stringify!(bn254_snarks_g2_aff), "::", stringify!(y) ) @@ -1503,32 +1461,32 @@ fn bindgen_test_layout_bn254_snarks_ec_g2_aff() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bn254_snarks_ec_g2_jac { +pub struct bn254_snarks_g2_jac { x: bn254_snarks_fp2, y: bn254_snarks_fp2, z: bn254_snarks_fp2, } #[test] -fn bindgen_test_layout_bn254_snarks_ec_g2_jac() { - const UNINIT: ::core::mem::MaybeUninit = +fn bindgen_test_layout_bn254_snarks_g2_jac() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 192usize, - concat!("Size of: ", stringify!(bn254_snarks_ec_g2_jac)) + concat!("Size of: ", stringify!(bn254_snarks_g2_jac)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bn254_snarks_ec_g2_jac)) + concat!("Alignment of ", stringify!(bn254_snarks_g2_jac)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g2_jac), + stringify!(bn254_snarks_g2_jac), "::", stringify!(x) ) @@ -1538,7 +1496,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g2_jac() { 64usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g2_jac), + stringify!(bn254_snarks_g2_jac), "::", stringify!(y) ) @@ -1548,7 +1506,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g2_jac() { 128usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g2_jac), + stringify!(bn254_snarks_g2_jac), "::", stringify!(z) ) @@ -1556,32 +1514,32 @@ fn bindgen_test_layout_bn254_snarks_ec_g2_jac() { } #[repr(C)] #[derive(Copy, Clone)] -pub struct bn254_snarks_ec_g2_prj { +pub struct bn254_snarks_g2_prj { x: bn254_snarks_fp2, y: bn254_snarks_fp2, z: bn254_snarks_fp2, } #[test] -fn bindgen_test_layout_bn254_snarks_ec_g2_prj() { - const UNINIT: ::core::mem::MaybeUninit = +fn bindgen_test_layout_bn254_snarks_g2_prj() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), + ::core::mem::size_of::(), 192usize, - concat!("Size of: ", stringify!(bn254_snarks_ec_g2_prj)) + concat!("Size of: ", stringify!(bn254_snarks_g2_prj)) ); assert_eq!( - ::core::mem::align_of::(), + ::core::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(bn254_snarks_ec_g2_prj)) + concat!("Alignment of ", stringify!(bn254_snarks_g2_prj)) ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g2_prj), + stringify!(bn254_snarks_g2_prj), "::", stringify!(x) ) @@ -1591,7 +1549,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g2_prj() { 64usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g2_prj), + stringify!(bn254_snarks_g2_prj), "::", stringify!(y) ) @@ -1601,7 +1559,7 @@ fn bindgen_test_layout_bn254_snarks_ec_g2_prj() { 128usize, concat!( "Offset of field: ", - stringify!(bn254_snarks_ec_g2_prj), + stringify!(bn254_snarks_g2_prj), "::", stringify!(z) ) @@ -2044,371 +2002,341 @@ extern "C" { pub fn ctt_bn254_snarks_fp2_sqrt_if_square_in_place(a: *mut bn254_snarks_fp2) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_aff_is_eq( - P: *const bn254_snarks_ec_g1_aff, - Q: *const bn254_snarks_ec_g1_aff, + pub fn ctt_bn254_snarks_g1_aff_is_eq( + P: *const bn254_snarks_g1_aff, + Q: *const bn254_snarks_g1_aff, ) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_aff_is_inf(P: *const bn254_snarks_ec_g1_aff) -> secret_bool; + pub fn ctt_bn254_snarks_g1_aff_is_inf(P: *const bn254_snarks_g1_aff) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_aff_set_inf(P: *mut bn254_snarks_ec_g1_aff); + pub fn ctt_bn254_snarks_g1_aff_set_inf(P: *mut bn254_snarks_g1_aff); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_aff_ccopy( - P: *mut bn254_snarks_ec_g1_aff, - Q: *const bn254_snarks_ec_g1_aff, + pub fn ctt_bn254_snarks_g1_aff_ccopy( + P: *mut bn254_snarks_g1_aff, + Q: *const bn254_snarks_g1_aff, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_aff_is_on_curve( + pub fn ctt_bn254_snarks_g1_aff_is_on_curve( x: *const bn254_snarks_fp, y: *const bn254_snarks_fp, ) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_aff_neg( - P: *mut bn254_snarks_ec_g1_aff, - Q: *const bn254_snarks_ec_g1_aff, - ); + pub fn ctt_bn254_snarks_g1_aff_neg(P: *mut bn254_snarks_g1_aff, Q: *const bn254_snarks_g1_aff); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_aff_neg_in_place(P: *mut bn254_snarks_ec_g1_aff); + pub fn ctt_bn254_snarks_g1_aff_neg_in_place(P: *mut bn254_snarks_g1_aff); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_is_eq( - P: *const bn254_snarks_ec_g1_jac, - Q: *const bn254_snarks_ec_g1_jac, + pub fn ctt_bn254_snarks_g1_jac_is_eq( + P: *const bn254_snarks_g1_jac, + Q: *const bn254_snarks_g1_jac, ) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_is_inf(P: *const bn254_snarks_ec_g1_jac) -> secret_bool; + pub fn ctt_bn254_snarks_g1_jac_is_inf(P: *const bn254_snarks_g1_jac) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_set_inf(P: *mut bn254_snarks_ec_g1_jac); + pub fn ctt_bn254_snarks_g1_jac_set_inf(P: *mut bn254_snarks_g1_jac); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_ccopy( - P: *mut bn254_snarks_ec_g1_jac, - Q: *const bn254_snarks_ec_g1_jac, + pub fn ctt_bn254_snarks_g1_jac_ccopy( + P: *mut bn254_snarks_g1_jac, + Q: *const bn254_snarks_g1_jac, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_neg( - P: *mut bn254_snarks_ec_g1_jac, - Q: *const bn254_snarks_ec_g1_jac, - ); + pub fn ctt_bn254_snarks_g1_jac_neg(P: *mut bn254_snarks_g1_jac, Q: *const bn254_snarks_g1_jac); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_neg_in_place(P: *mut bn254_snarks_ec_g1_jac); + pub fn ctt_bn254_snarks_g1_jac_neg_in_place(P: *mut bn254_snarks_g1_jac); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_cneg_in_place( - P: *mut bn254_snarks_ec_g1_jac, - ctl: secret_bool, - ); + pub fn ctt_bn254_snarks_g1_jac_cneg_in_place(P: *mut bn254_snarks_g1_jac, ctl: secret_bool); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_sum( - r: *mut bn254_snarks_ec_g1_jac, - P: *const bn254_snarks_ec_g1_jac, - Q: *const bn254_snarks_ec_g1_jac, + pub fn ctt_bn254_snarks_g1_jac_sum( + r: *mut bn254_snarks_g1_jac, + P: *const bn254_snarks_g1_jac, + Q: *const bn254_snarks_g1_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_add_in_place( - P: *mut bn254_snarks_ec_g1_jac, - Q: *const bn254_snarks_ec_g1_jac, + pub fn ctt_bn254_snarks_g1_jac_add_in_place( + P: *mut bn254_snarks_g1_jac, + Q: *const bn254_snarks_g1_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_diff( - r: *mut bn254_snarks_ec_g1_jac, - P: *const bn254_snarks_ec_g1_jac, - Q: *const bn254_snarks_ec_g1_jac, + pub fn ctt_bn254_snarks_g1_jac_diff( + r: *mut bn254_snarks_g1_jac, + P: *const bn254_snarks_g1_jac, + Q: *const bn254_snarks_g1_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_double( - r: *mut bn254_snarks_ec_g1_jac, - P: *const bn254_snarks_ec_g1_jac, + pub fn ctt_bn254_snarks_g1_jac_double( + r: *mut bn254_snarks_g1_jac, + P: *const bn254_snarks_g1_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_double_in_place(P: *mut bn254_snarks_ec_g1_jac); + pub fn ctt_bn254_snarks_g1_jac_double_in_place(P: *mut bn254_snarks_g1_jac); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_affine( - dst: *mut bn254_snarks_ec_g1_aff, - src: *const bn254_snarks_ec_g1_jac, + pub fn ctt_bn254_snarks_g1_jac_affine( + dst: *mut bn254_snarks_g1_aff, + src: *const bn254_snarks_g1_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_jac_from_affine( - dst: *mut bn254_snarks_ec_g1_jac, - src: *const bn254_snarks_ec_g1_aff, + pub fn ctt_bn254_snarks_g1_jac_from_affine( + dst: *mut bn254_snarks_g1_jac, + src: *const bn254_snarks_g1_aff, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_is_eq( - P: *const bn254_snarks_ec_g1_prj, - Q: *const bn254_snarks_ec_g1_prj, + pub fn ctt_bn254_snarks_g1_prj_is_eq( + P: *const bn254_snarks_g1_prj, + Q: *const bn254_snarks_g1_prj, ) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_is_inf(P: *const bn254_snarks_ec_g1_prj) -> secret_bool; + pub fn ctt_bn254_snarks_g1_prj_is_inf(P: *const bn254_snarks_g1_prj) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_set_inf(P: *mut bn254_snarks_ec_g1_prj); + pub fn ctt_bn254_snarks_g1_prj_set_inf(P: *mut bn254_snarks_g1_prj); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_ccopy( - P: *mut bn254_snarks_ec_g1_prj, - Q: *const bn254_snarks_ec_g1_prj, + pub fn ctt_bn254_snarks_g1_prj_ccopy( + P: *mut bn254_snarks_g1_prj, + Q: *const bn254_snarks_g1_prj, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_neg( - P: *mut bn254_snarks_ec_g1_prj, - Q: *const bn254_snarks_ec_g1_prj, - ); + pub fn ctt_bn254_snarks_g1_prj_neg(P: *mut bn254_snarks_g1_prj, Q: *const bn254_snarks_g1_prj); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_neg_in_place(P: *mut bn254_snarks_ec_g1_prj); + pub fn ctt_bn254_snarks_g1_prj_neg_in_place(P: *mut bn254_snarks_g1_prj); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_cneg_in_place( - P: *mut bn254_snarks_ec_g1_prj, - ctl: secret_bool, - ); + pub fn ctt_bn254_snarks_g1_prj_cneg_in_place(P: *mut bn254_snarks_g1_prj, ctl: secret_bool); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_sum( - r: *mut bn254_snarks_ec_g1_prj, - P: *const bn254_snarks_ec_g1_prj, - Q: *const bn254_snarks_ec_g1_prj, + pub fn ctt_bn254_snarks_g1_prj_sum( + r: *mut bn254_snarks_g1_prj, + P: *const bn254_snarks_g1_prj, + Q: *const bn254_snarks_g1_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_add_in_place( - P: *mut bn254_snarks_ec_g1_prj, - Q: *const bn254_snarks_ec_g1_prj, + pub fn ctt_bn254_snarks_g1_prj_add_in_place( + P: *mut bn254_snarks_g1_prj, + Q: *const bn254_snarks_g1_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_diff( - r: *mut bn254_snarks_ec_g1_prj, - P: *const bn254_snarks_ec_g1_prj, - Q: *const bn254_snarks_ec_g1_prj, + pub fn ctt_bn254_snarks_g1_prj_diff( + r: *mut bn254_snarks_g1_prj, + P: *const bn254_snarks_g1_prj, + Q: *const bn254_snarks_g1_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_double( - r: *mut bn254_snarks_ec_g1_prj, - P: *const bn254_snarks_ec_g1_prj, + pub fn ctt_bn254_snarks_g1_prj_double( + r: *mut bn254_snarks_g1_prj, + P: *const bn254_snarks_g1_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_double_in_place(P: *mut bn254_snarks_ec_g1_prj); + pub fn ctt_bn254_snarks_g1_prj_double_in_place(P: *mut bn254_snarks_g1_prj); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_affine( - dst: *mut bn254_snarks_ec_g1_aff, - src: *const bn254_snarks_ec_g1_prj, + pub fn ctt_bn254_snarks_g1_prj_affine( + dst: *mut bn254_snarks_g1_aff, + src: *const bn254_snarks_g1_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g1_prj_from_affine( - dst: *mut bn254_snarks_ec_g1_prj, - src: *const bn254_snarks_ec_g1_aff, + pub fn ctt_bn254_snarks_g1_prj_from_affine( + dst: *mut bn254_snarks_g1_prj, + src: *const bn254_snarks_g1_aff, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_aff_is_eq( - P: *const bn254_snarks_ec_g2_aff, - Q: *const bn254_snarks_ec_g2_aff, + pub fn ctt_bn254_snarks_g2_aff_is_eq( + P: *const bn254_snarks_g2_aff, + Q: *const bn254_snarks_g2_aff, ) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_aff_is_inf(P: *const bn254_snarks_ec_g2_aff) -> secret_bool; + pub fn ctt_bn254_snarks_g2_aff_is_inf(P: *const bn254_snarks_g2_aff) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_aff_set_inf(P: *mut bn254_snarks_ec_g2_aff); + pub fn ctt_bn254_snarks_g2_aff_set_inf(P: *mut bn254_snarks_g2_aff); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_aff_ccopy( - P: *mut bn254_snarks_ec_g2_aff, - Q: *const bn254_snarks_ec_g2_aff, + pub fn ctt_bn254_snarks_g2_aff_ccopy( + P: *mut bn254_snarks_g2_aff, + Q: *const bn254_snarks_g2_aff, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_aff_is_on_curve( + pub fn ctt_bn254_snarks_g2_aff_is_on_curve( x: *const bn254_snarks_fp2, y: *const bn254_snarks_fp2, ) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_aff_neg( - P: *mut bn254_snarks_ec_g2_aff, - Q: *const bn254_snarks_ec_g2_aff, - ); + pub fn ctt_bn254_snarks_g2_aff_neg(P: *mut bn254_snarks_g2_aff, Q: *const bn254_snarks_g2_aff); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_aff_neg_in_place(P: *mut bn254_snarks_ec_g2_aff); + pub fn ctt_bn254_snarks_g2_aff_neg_in_place(P: *mut bn254_snarks_g2_aff); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_is_eq( - P: *const bn254_snarks_ec_g2_jac, - Q: *const bn254_snarks_ec_g2_jac, + pub fn ctt_bn254_snarks_g2_jac_is_eq( + P: *const bn254_snarks_g2_jac, + Q: *const bn254_snarks_g2_jac, ) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_is_inf(P: *const bn254_snarks_ec_g2_jac) -> secret_bool; + pub fn ctt_bn254_snarks_g2_jac_is_inf(P: *const bn254_snarks_g2_jac) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_set_inf(P: *mut bn254_snarks_ec_g2_jac); + pub fn ctt_bn254_snarks_g2_jac_set_inf(P: *mut bn254_snarks_g2_jac); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_ccopy( - P: *mut bn254_snarks_ec_g2_jac, - Q: *const bn254_snarks_ec_g2_jac, + pub fn ctt_bn254_snarks_g2_jac_ccopy( + P: *mut bn254_snarks_g2_jac, + Q: *const bn254_snarks_g2_jac, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_neg( - P: *mut bn254_snarks_ec_g2_jac, - Q: *const bn254_snarks_ec_g2_jac, - ); + pub fn ctt_bn254_snarks_g2_jac_neg(P: *mut bn254_snarks_g2_jac, Q: *const bn254_snarks_g2_jac); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_neg_in_place(P: *mut bn254_snarks_ec_g2_jac); + pub fn ctt_bn254_snarks_g2_jac_neg_in_place(P: *mut bn254_snarks_g2_jac); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_cneg_in_place( - P: *mut bn254_snarks_ec_g2_jac, - ctl: secret_bool, - ); + pub fn ctt_bn254_snarks_g2_jac_cneg_in_place(P: *mut bn254_snarks_g2_jac, ctl: secret_bool); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_sum( - r: *mut bn254_snarks_ec_g2_jac, - P: *const bn254_snarks_ec_g2_jac, - Q: *const bn254_snarks_ec_g2_jac, + pub fn ctt_bn254_snarks_g2_jac_sum( + r: *mut bn254_snarks_g2_jac, + P: *const bn254_snarks_g2_jac, + Q: *const bn254_snarks_g2_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_add_in_place( - P: *mut bn254_snarks_ec_g2_jac, - Q: *const bn254_snarks_ec_g2_jac, + pub fn ctt_bn254_snarks_g2_jac_add_in_place( + P: *mut bn254_snarks_g2_jac, + Q: *const bn254_snarks_g2_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_diff( - r: *mut bn254_snarks_ec_g2_jac, - P: *const bn254_snarks_ec_g2_jac, - Q: *const bn254_snarks_ec_g2_jac, + pub fn ctt_bn254_snarks_g2_jac_diff( + r: *mut bn254_snarks_g2_jac, + P: *const bn254_snarks_g2_jac, + Q: *const bn254_snarks_g2_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_double( - r: *mut bn254_snarks_ec_g2_jac, - P: *const bn254_snarks_ec_g2_jac, + pub fn ctt_bn254_snarks_g2_jac_double( + r: *mut bn254_snarks_g2_jac, + P: *const bn254_snarks_g2_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_double_in_place(P: *mut bn254_snarks_ec_g2_jac); + pub fn ctt_bn254_snarks_g2_jac_double_in_place(P: *mut bn254_snarks_g2_jac); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_affine( - dst: *mut bn254_snarks_ec_g2_aff, - src: *const bn254_snarks_ec_g2_jac, + pub fn ctt_bn254_snarks_g2_jac_affine( + dst: *mut bn254_snarks_g2_aff, + src: *const bn254_snarks_g2_jac, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_jac_from_affine( - dst: *mut bn254_snarks_ec_g2_jac, - src: *const bn254_snarks_ec_g2_aff, + pub fn ctt_bn254_snarks_g2_jac_from_affine( + dst: *mut bn254_snarks_g2_jac, + src: *const bn254_snarks_g2_aff, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_is_eq( - P: *const bn254_snarks_ec_g2_prj, - Q: *const bn254_snarks_ec_g2_prj, + pub fn ctt_bn254_snarks_g2_prj_is_eq( + P: *const bn254_snarks_g2_prj, + Q: *const bn254_snarks_g2_prj, ) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_is_inf(P: *const bn254_snarks_ec_g2_prj) -> secret_bool; + pub fn ctt_bn254_snarks_g2_prj_is_inf(P: *const bn254_snarks_g2_prj) -> secret_bool; } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_set_inf(P: *mut bn254_snarks_ec_g2_prj); + pub fn ctt_bn254_snarks_g2_prj_set_inf(P: *mut bn254_snarks_g2_prj); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_ccopy( - P: *mut bn254_snarks_ec_g2_prj, - Q: *const bn254_snarks_ec_g2_prj, + pub fn ctt_bn254_snarks_g2_prj_ccopy( + P: *mut bn254_snarks_g2_prj, + Q: *const bn254_snarks_g2_prj, ctl: secret_bool, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_neg( - P: *mut bn254_snarks_ec_g2_prj, - Q: *const bn254_snarks_ec_g2_prj, - ); + pub fn ctt_bn254_snarks_g2_prj_neg(P: *mut bn254_snarks_g2_prj, Q: *const bn254_snarks_g2_prj); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_neg_in_place(P: *mut bn254_snarks_ec_g2_prj); + pub fn ctt_bn254_snarks_g2_prj_neg_in_place(P: *mut bn254_snarks_g2_prj); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_cneg_in_place( - P: *mut bn254_snarks_ec_g2_prj, - ctl: secret_bool, - ); + pub fn ctt_bn254_snarks_g2_prj_cneg_in_place(P: *mut bn254_snarks_g2_prj, ctl: secret_bool); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_sum( - r: *mut bn254_snarks_ec_g2_prj, - P: *const bn254_snarks_ec_g2_prj, - Q: *const bn254_snarks_ec_g2_prj, + pub fn ctt_bn254_snarks_g2_prj_sum( + r: *mut bn254_snarks_g2_prj, + P: *const bn254_snarks_g2_prj, + Q: *const bn254_snarks_g2_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_add_in_place( - P: *mut bn254_snarks_ec_g2_prj, - Q: *const bn254_snarks_ec_g2_prj, + pub fn ctt_bn254_snarks_g2_prj_add_in_place( + P: *mut bn254_snarks_g2_prj, + Q: *const bn254_snarks_g2_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_diff( - r: *mut bn254_snarks_ec_g2_prj, - P: *const bn254_snarks_ec_g2_prj, - Q: *const bn254_snarks_ec_g2_prj, + pub fn ctt_bn254_snarks_g2_prj_diff( + r: *mut bn254_snarks_g2_prj, + P: *const bn254_snarks_g2_prj, + Q: *const bn254_snarks_g2_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_double( - r: *mut bn254_snarks_ec_g2_prj, - P: *const bn254_snarks_ec_g2_prj, + pub fn ctt_bn254_snarks_g2_prj_double( + r: *mut bn254_snarks_g2_prj, + P: *const bn254_snarks_g2_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_double_in_place(P: *mut bn254_snarks_ec_g2_prj); + pub fn ctt_bn254_snarks_g2_prj_double_in_place(P: *mut bn254_snarks_g2_prj); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_affine( - dst: *mut bn254_snarks_ec_g2_aff, - src: *const bn254_snarks_ec_g2_prj, + pub fn ctt_bn254_snarks_g2_prj_affine( + dst: *mut bn254_snarks_g2_aff, + src: *const bn254_snarks_g2_prj, ); } extern "C" { - pub fn ctt_bn254_snarks_ec_g2_prj_from_affine( - dst: *mut bn254_snarks_ec_g2_prj, - src: *const bn254_snarks_ec_g2_aff, + pub fn ctt_bn254_snarks_g2_prj_from_affine( + dst: *mut bn254_snarks_g2_prj, + src: *const bn254_snarks_g2_aff, ); } #[repr(C)] @@ -3532,6 +3460,151 @@ extern "C" { extern "C" { pub fn ctt_vesta_ec_prj_from_affine(dst: *mut vesta_ec_prj, src: *const vesta_ec_aff); } +#[repr(C)] +#[derive(Copy, Clone)] +pub struct ctt_threadpool { + _unused: [u8; 0], +} +extern "C" { + #[doc = " Create a new threadpool that manages `num_threads` threads\n\n Initialize a threadpool that manages `num_threads` threads.\n\n A Constantine's threadpool cannot be instantiated\n on a thread managed by another Constantine's threadpool\n including the root thread.\n\n Mixing with other libraries' threadpools and runtime\n will not impact correctness but may impact performance."] + pub fn ctt_threadpool_new(num_threads: usize) -> *mut ctt_threadpool; +} +extern "C" { + #[doc = " Wait until all pending tasks are processed and then shutdown the threadpool"] + pub fn ctt_threadpool_shutdown(threadpool: *mut ctt_threadpool); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct big255 { + limbs: [secret_word; 4usize], +} +#[test] +fn bindgen_test_layout_big255() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(big255)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(big255)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).limbs) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(big255), + "::", + stringify!(limbs) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct big254 { + limbs: [secret_word; 4usize], +} +#[test] +fn bindgen_test_layout_big254() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(big254)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(big254)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).limbs) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(big254), + "::", + stringify!(limbs) + ) + ); +} +extern "C" { + pub fn ctt_bls12_381_g1_jac_multi_scalar_mul_vartime_parallel( + tp: *const ctt_threadpool, + r: *const bls12_381_g1_jac, + coefs: *const big255, + points: *const bls12_381_g1_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_bls12_381_g1_prj_multi_scalar_mul_vartime_parallel( + tp: *const ctt_threadpool, + r: *const bls12_381_g1_prj, + coefs: *const big255, + points: *const bls12_381_g1_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_bn254_snarks_g1_jac_multi_scalar_mul_vartime_parallel( + tp: *const ctt_threadpool, + r: *const bn254_snarks_g1_jac, + coefs: *const big254, + points: *const bn254_snarks_g1_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel( + tp: *const ctt_threadpool, + r: *const bn254_snarks_g1_prj, + coefs: *const big254, + points: *const bn254_snarks_g1_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel( + tp: *const ctt_threadpool, + r: *const pallas_ec_jac, + coefs: *const big255, + points: *const pallas_ec_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel( + tp: *const ctt_threadpool, + r: *const pallas_ec_prj, + coefs: *const big255, + points: *const pallas_ec_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel( + tp: *const ctt_threadpool, + r: *const vesta_ec_jac, + coefs: *const big255, + points: *const vesta_ec_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel( + tp: *const ctt_threadpool, + r: *const vesta_ec_prj, + coefs: *const big255, + points: *const vesta_ec_aff, + len: usize, + ); +} #[repr(u8)] #[derive(Copy, Clone, Hash, PartialEq, Eq)] pub enum ctt_codec_scalar_status { diff --git a/include/constantine.h b/include/constantine.h index 6ca80d87..9633e361 100644 --- a/include/constantine.h +++ b/include/constantine.h @@ -18,6 +18,11 @@ #include "constantine/curves/pallas.h" #include "constantine/curves/vesta.h" +#include "constantine/curves/bls12_381_parallel.h" +#include "constantine/curves/bn254_snarks_parallel.h" +#include "constantine/curves/pallas_parallel.h" +#include "constantine/curves/vesta_parallel.h" + // Protocols #include "constantine/protocols/ethereum_bls_signatures.h" diff --git a/include/constantine/curves/bls12_381.h b/include/constantine/curves/bls12_381.h index 3f1a4f9f..9ca96b62 100644 --- a/include/constantine/curves/bls12_381.h +++ b/include/constantine/curves/bls12_381.h @@ -18,12 +18,12 @@ extern "C" { typedef struct { secret_word limbs[CTT_WORDS_REQUIRED(255)]; } bls12_381_fr; typedef struct { secret_word limbs[CTT_WORDS_REQUIRED(381)]; } bls12_381_fp; typedef struct { bls12_381_fp c[2]; } bls12_381_fp2; -typedef struct { bls12_381_fp x, y; } bls12_381_ec_g1_aff; -typedef struct { bls12_381_fp x, y, z; } bls12_381_ec_g1_jac; -typedef struct { bls12_381_fp x, y, z; } bls12_381_ec_g1_prj; -typedef struct { bls12_381_fp2 x, y; } bls12_381_ec_g2_aff; -typedef struct { bls12_381_fp2 x, y, z; } bls12_381_ec_g2_jac; -typedef struct { bls12_381_fp2 x, y, z; } bls12_381_ec_g2_prj; +typedef struct { bls12_381_fp x, y; } bls12_381_g1_aff; +typedef struct { bls12_381_fp x, y, z; } bls12_381_g1_jac; +typedef struct { bls12_381_fp x, y, z; } bls12_381_g1_prj; +typedef struct { bls12_381_fp2 x, y; } bls12_381_g2_aff; +typedef struct { bls12_381_fp2 x, y, z; } bls12_381_g2_jac; +typedef struct { bls12_381_fp2 x, y, z; } bls12_381_g2_prj; ctt_bool ctt_bls12_381_fr_unmarshalBE(bls12_381_fr* dst, const byte src[], ptrdiff_t src_len) __attribute__((warn_unused_result)); ctt_bool ctt_bls12_381_fr_marshalBE(byte dst[], ptrdiff_t dst_len, const bls12_381_fr* src) __attribute__((warn_unused_result)); @@ -129,76 +129,76 @@ void ctt_bls12_381_fp2_csub_in_place(bls12_381_fp2* a, const bls12_381_fp secret_bool ctt_bls12_381_fp2_is_square(const bls12_381_fp2* a); void ctt_bls12_381_fp2_sqrt_in_place(bls12_381_fp2* a); secret_bool ctt_bls12_381_fp2_sqrt_if_square_in_place(bls12_381_fp2* a); -secret_bool ctt_bls12_381_ec_g1_aff_is_eq(const bls12_381_ec_g1_aff* P, const bls12_381_ec_g1_aff* Q); -secret_bool ctt_bls12_381_ec_g1_aff_is_inf(const bls12_381_ec_g1_aff* P); -void ctt_bls12_381_ec_g1_aff_set_inf(bls12_381_ec_g1_aff* P); -void ctt_bls12_381_ec_g1_aff_ccopy(bls12_381_ec_g1_aff* P, const bls12_381_ec_g1_aff* Q, secret_bool ctl); -secret_bool ctt_bls12_381_ec_g1_aff_is_on_curve(const bls12_381_fp* x, const bls12_381_fp* y); -void ctt_bls12_381_ec_g1_aff_neg(bls12_381_ec_g1_aff* P, const bls12_381_ec_g1_aff* Q); -void ctt_bls12_381_ec_g1_aff_neg_in_place(bls12_381_ec_g1_aff* P); -secret_bool ctt_bls12_381_ec_g1_jac_is_eq(const bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); -secret_bool ctt_bls12_381_ec_g1_jac_is_inf(const bls12_381_ec_g1_jac* P); -void ctt_bls12_381_ec_g1_jac_set_inf(bls12_381_ec_g1_jac* P); -void ctt_bls12_381_ec_g1_jac_ccopy(bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q, secret_bool ctl); -void ctt_bls12_381_ec_g1_jac_neg(bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); -void ctt_bls12_381_ec_g1_jac_neg_in_place(bls12_381_ec_g1_jac* P); -void ctt_bls12_381_ec_g1_jac_cneg_in_place(bls12_381_ec_g1_jac* P, secret_bool ctl); -void ctt_bls12_381_ec_g1_jac_sum(bls12_381_ec_g1_jac* r, const bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); -void ctt_bls12_381_ec_g1_jac_add_in_place(bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); -void ctt_bls12_381_ec_g1_jac_diff(bls12_381_ec_g1_jac* r, const bls12_381_ec_g1_jac* P, const bls12_381_ec_g1_jac* Q); -void ctt_bls12_381_ec_g1_jac_double(bls12_381_ec_g1_jac* r, const bls12_381_ec_g1_jac* P); -void ctt_bls12_381_ec_g1_jac_double_in_place(bls12_381_ec_g1_jac* P); -void ctt_bls12_381_ec_g1_jac_affine(bls12_381_ec_g1_aff* dst, const bls12_381_ec_g1_jac* src); -void ctt_bls12_381_ec_g1_jac_from_affine(bls12_381_ec_g1_jac* dst, const bls12_381_ec_g1_aff* src); -secret_bool ctt_bls12_381_ec_g1_prj_is_eq(const bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); -secret_bool ctt_bls12_381_ec_g1_prj_is_inf(const bls12_381_ec_g1_prj* P); -void ctt_bls12_381_ec_g1_prj_set_inf(bls12_381_ec_g1_prj* P); -void ctt_bls12_381_ec_g1_prj_ccopy(bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q, secret_bool ctl); -void ctt_bls12_381_ec_g1_prj_neg(bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); -void ctt_bls12_381_ec_g1_prj_neg_in_place(bls12_381_ec_g1_prj* P); -void ctt_bls12_381_ec_g1_prj_cneg_in_place(bls12_381_ec_g1_prj* P, secret_bool ctl); -void ctt_bls12_381_ec_g1_prj_sum(bls12_381_ec_g1_prj* r, const bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); -void ctt_bls12_381_ec_g1_prj_add_in_place(bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); -void ctt_bls12_381_ec_g1_prj_diff(bls12_381_ec_g1_prj* r, const bls12_381_ec_g1_prj* P, const bls12_381_ec_g1_prj* Q); -void ctt_bls12_381_ec_g1_prj_double(bls12_381_ec_g1_prj* r, const bls12_381_ec_g1_prj* P); -void ctt_bls12_381_ec_g1_prj_double_in_place(bls12_381_ec_g1_prj* P); -void ctt_bls12_381_ec_g1_prj_affine(bls12_381_ec_g1_aff* dst, const bls12_381_ec_g1_prj* src); -void ctt_bls12_381_ec_g1_prj_from_affine(bls12_381_ec_g1_prj* dst, const bls12_381_ec_g1_aff* src); -secret_bool ctt_bls12_381_ec_g2_aff_is_eq(const bls12_381_ec_g2_aff* P, const bls12_381_ec_g2_aff* Q); -secret_bool ctt_bls12_381_ec_g2_aff_is_inf(const bls12_381_ec_g2_aff* P); -void ctt_bls12_381_ec_g2_aff_set_inf(bls12_381_ec_g2_aff* P); -void ctt_bls12_381_ec_g2_aff_ccopy(bls12_381_ec_g2_aff* P, const bls12_381_ec_g2_aff* Q, secret_bool ctl); -secret_bool ctt_bls12_381_ec_g2_aff_is_on_curve(const bls12_381_fp2* x, const bls12_381_fp2* y); -void ctt_bls12_381_ec_g2_aff_neg(bls12_381_ec_g2_aff* P, const bls12_381_ec_g2_aff* Q); -void ctt_bls12_381_ec_g2_aff_neg_in_place(bls12_381_ec_g2_aff* P); -secret_bool ctt_bls12_381_ec_g2_jac_is_eq(const bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); -secret_bool ctt_bls12_381_ec_g2_jac_is_inf(const bls12_381_ec_g2_jac* P); -void ctt_bls12_381_ec_g2_jac_set_inf(bls12_381_ec_g2_jac* P); -void ctt_bls12_381_ec_g2_jac_ccopy(bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q, secret_bool ctl); -void ctt_bls12_381_ec_g2_jac_neg(bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); -void ctt_bls12_381_ec_g2_jac_neg_in_place(bls12_381_ec_g2_jac* P); -void ctt_bls12_381_ec_g2_jac_cneg_in_place(bls12_381_ec_g2_jac* P, secret_bool ctl); -void ctt_bls12_381_ec_g2_jac_sum(bls12_381_ec_g2_jac* r, const bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); -void ctt_bls12_381_ec_g2_jac_add_in_place(bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); -void ctt_bls12_381_ec_g2_jac_diff(bls12_381_ec_g2_jac* r, const bls12_381_ec_g2_jac* P, const bls12_381_ec_g2_jac* Q); -void ctt_bls12_381_ec_g2_jac_double(bls12_381_ec_g2_jac* r, const bls12_381_ec_g2_jac* P); -void ctt_bls12_381_ec_g2_jac_double_in_place(bls12_381_ec_g2_jac* P); -void ctt_bls12_381_ec_g2_jac_affine(bls12_381_ec_g2_aff* dst, const bls12_381_ec_g2_jac* src); -void ctt_bls12_381_ec_g2_jac_from_affine(bls12_381_ec_g2_jac* dst, const bls12_381_ec_g2_aff* src); -secret_bool ctt_bls12_381_ec_g2_prj_is_eq(const bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); -secret_bool ctt_bls12_381_ec_g2_prj_is_inf(const bls12_381_ec_g2_prj* P); -void ctt_bls12_381_ec_g2_prj_set_inf(bls12_381_ec_g2_prj* P); -void ctt_bls12_381_ec_g2_prj_ccopy(bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q, secret_bool ctl); -void ctt_bls12_381_ec_g2_prj_neg(bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); -void ctt_bls12_381_ec_g2_prj_neg_in_place(bls12_381_ec_g2_prj* P); -void ctt_bls12_381_ec_g2_prj_cneg_in_place(bls12_381_ec_g2_prj* P, secret_bool ctl); -void ctt_bls12_381_ec_g2_prj_sum(bls12_381_ec_g2_prj* r, const bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); -void ctt_bls12_381_ec_g2_prj_add_in_place(bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); -void ctt_bls12_381_ec_g2_prj_diff(bls12_381_ec_g2_prj* r, const bls12_381_ec_g2_prj* P, const bls12_381_ec_g2_prj* Q); -void ctt_bls12_381_ec_g2_prj_double(bls12_381_ec_g2_prj* r, const bls12_381_ec_g2_prj* P); -void ctt_bls12_381_ec_g2_prj_double_in_place(bls12_381_ec_g2_prj* P); -void ctt_bls12_381_ec_g2_prj_affine(bls12_381_ec_g2_aff* dst, const bls12_381_ec_g2_prj* src); -void ctt_bls12_381_ec_g2_prj_from_affine(bls12_381_ec_g2_prj* dst, const bls12_381_ec_g2_aff* src); +secret_bool ctt_bls12_381_g1_aff_is_eq(const bls12_381_g1_aff* P, const bls12_381_g1_aff* Q); +secret_bool ctt_bls12_381_g1_aff_is_inf(const bls12_381_g1_aff* P); +void ctt_bls12_381_g1_aff_set_inf(bls12_381_g1_aff* P); +void ctt_bls12_381_g1_aff_ccopy(bls12_381_g1_aff* P, const bls12_381_g1_aff* Q, secret_bool ctl); +secret_bool ctt_bls12_381_g1_aff_is_on_curve(const bls12_381_fp* x, const bls12_381_fp* y); +void ctt_bls12_381_g1_aff_neg(bls12_381_g1_aff* P, const bls12_381_g1_aff* Q); +void ctt_bls12_381_g1_aff_neg_in_place(bls12_381_g1_aff* P); +secret_bool ctt_bls12_381_g1_jac_is_eq(const bls12_381_g1_jac* P, const bls12_381_g1_jac* Q); +secret_bool ctt_bls12_381_g1_jac_is_inf(const bls12_381_g1_jac* P); +void ctt_bls12_381_g1_jac_set_inf(bls12_381_g1_jac* P); +void ctt_bls12_381_g1_jac_ccopy(bls12_381_g1_jac* P, const bls12_381_g1_jac* Q, secret_bool ctl); +void ctt_bls12_381_g1_jac_neg(bls12_381_g1_jac* P, const bls12_381_g1_jac* Q); +void ctt_bls12_381_g1_jac_neg_in_place(bls12_381_g1_jac* P); +void ctt_bls12_381_g1_jac_cneg_in_place(bls12_381_g1_jac* P, secret_bool ctl); +void ctt_bls12_381_g1_jac_sum(bls12_381_g1_jac* r, const bls12_381_g1_jac* P, const bls12_381_g1_jac* Q); +void ctt_bls12_381_g1_jac_add_in_place(bls12_381_g1_jac* P, const bls12_381_g1_jac* Q); +void ctt_bls12_381_g1_jac_diff(bls12_381_g1_jac* r, const bls12_381_g1_jac* P, const bls12_381_g1_jac* Q); +void ctt_bls12_381_g1_jac_double(bls12_381_g1_jac* r, const bls12_381_g1_jac* P); +void ctt_bls12_381_g1_jac_double_in_place(bls12_381_g1_jac* P); +void ctt_bls12_381_g1_jac_affine(bls12_381_g1_aff* dst, const bls12_381_g1_jac* src); +void ctt_bls12_381_g1_jac_from_affine(bls12_381_g1_jac* dst, const bls12_381_g1_aff* src); +secret_bool ctt_bls12_381_g1_prj_is_eq(const bls12_381_g1_prj* P, const bls12_381_g1_prj* Q); +secret_bool ctt_bls12_381_g1_prj_is_inf(const bls12_381_g1_prj* P); +void ctt_bls12_381_g1_prj_set_inf(bls12_381_g1_prj* P); +void ctt_bls12_381_g1_prj_ccopy(bls12_381_g1_prj* P, const bls12_381_g1_prj* Q, secret_bool ctl); +void ctt_bls12_381_g1_prj_neg(bls12_381_g1_prj* P, const bls12_381_g1_prj* Q); +void ctt_bls12_381_g1_prj_neg_in_place(bls12_381_g1_prj* P); +void ctt_bls12_381_g1_prj_cneg_in_place(bls12_381_g1_prj* P, secret_bool ctl); +void ctt_bls12_381_g1_prj_sum(bls12_381_g1_prj* r, const bls12_381_g1_prj* P, const bls12_381_g1_prj* Q); +void ctt_bls12_381_g1_prj_add_in_place(bls12_381_g1_prj* P, const bls12_381_g1_prj* Q); +void ctt_bls12_381_g1_prj_diff(bls12_381_g1_prj* r, const bls12_381_g1_prj* P, const bls12_381_g1_prj* Q); +void ctt_bls12_381_g1_prj_double(bls12_381_g1_prj* r, const bls12_381_g1_prj* P); +void ctt_bls12_381_g1_prj_double_in_place(bls12_381_g1_prj* P); +void ctt_bls12_381_g1_prj_affine(bls12_381_g1_aff* dst, const bls12_381_g1_prj* src); +void ctt_bls12_381_g1_prj_from_affine(bls12_381_g1_prj* dst, const bls12_381_g1_aff* src); +secret_bool ctt_bls12_381_g2_aff_is_eq(const bls12_381_g2_aff* P, const bls12_381_g2_aff* Q); +secret_bool ctt_bls12_381_g2_aff_is_inf(const bls12_381_g2_aff* P); +void ctt_bls12_381_g2_aff_set_inf(bls12_381_g2_aff* P); +void ctt_bls12_381_g2_aff_ccopy(bls12_381_g2_aff* P, const bls12_381_g2_aff* Q, secret_bool ctl); +secret_bool ctt_bls12_381_g2_aff_is_on_curve(const bls12_381_fp2* x, const bls12_381_fp2* y); +void ctt_bls12_381_g2_aff_neg(bls12_381_g2_aff* P, const bls12_381_g2_aff* Q); +void ctt_bls12_381_g2_aff_neg_in_place(bls12_381_g2_aff* P); +secret_bool ctt_bls12_381_g2_jac_is_eq(const bls12_381_g2_jac* P, const bls12_381_g2_jac* Q); +secret_bool ctt_bls12_381_g2_jac_is_inf(const bls12_381_g2_jac* P); +void ctt_bls12_381_g2_jac_set_inf(bls12_381_g2_jac* P); +void ctt_bls12_381_g2_jac_ccopy(bls12_381_g2_jac* P, const bls12_381_g2_jac* Q, secret_bool ctl); +void ctt_bls12_381_g2_jac_neg(bls12_381_g2_jac* P, const bls12_381_g2_jac* Q); +void ctt_bls12_381_g2_jac_neg_in_place(bls12_381_g2_jac* P); +void ctt_bls12_381_g2_jac_cneg_in_place(bls12_381_g2_jac* P, secret_bool ctl); +void ctt_bls12_381_g2_jac_sum(bls12_381_g2_jac* r, const bls12_381_g2_jac* P, const bls12_381_g2_jac* Q); +void ctt_bls12_381_g2_jac_add_in_place(bls12_381_g2_jac* P, const bls12_381_g2_jac* Q); +void ctt_bls12_381_g2_jac_diff(bls12_381_g2_jac* r, const bls12_381_g2_jac* P, const bls12_381_g2_jac* Q); +void ctt_bls12_381_g2_jac_double(bls12_381_g2_jac* r, const bls12_381_g2_jac* P); +void ctt_bls12_381_g2_jac_double_in_place(bls12_381_g2_jac* P); +void ctt_bls12_381_g2_jac_affine(bls12_381_g2_aff* dst, const bls12_381_g2_jac* src); +void ctt_bls12_381_g2_jac_from_affine(bls12_381_g2_jac* dst, const bls12_381_g2_aff* src); +secret_bool ctt_bls12_381_g2_prj_is_eq(const bls12_381_g2_prj* P, const bls12_381_g2_prj* Q); +secret_bool ctt_bls12_381_g2_prj_is_inf(const bls12_381_g2_prj* P); +void ctt_bls12_381_g2_prj_set_inf(bls12_381_g2_prj* P); +void ctt_bls12_381_g2_prj_ccopy(bls12_381_g2_prj* P, const bls12_381_g2_prj* Q, secret_bool ctl); +void ctt_bls12_381_g2_prj_neg(bls12_381_g2_prj* P, const bls12_381_g2_prj* Q); +void ctt_bls12_381_g2_prj_neg_in_place(bls12_381_g2_prj* P); +void ctt_bls12_381_g2_prj_cneg_in_place(bls12_381_g2_prj* P, secret_bool ctl); +void ctt_bls12_381_g2_prj_sum(bls12_381_g2_prj* r, const bls12_381_g2_prj* P, const bls12_381_g2_prj* Q); +void ctt_bls12_381_g2_prj_add_in_place(bls12_381_g2_prj* P, const bls12_381_g2_prj* Q); +void ctt_bls12_381_g2_prj_diff(bls12_381_g2_prj* r, const bls12_381_g2_prj* P, const bls12_381_g2_prj* Q); +void ctt_bls12_381_g2_prj_double(bls12_381_g2_prj* r, const bls12_381_g2_prj* P); +void ctt_bls12_381_g2_prj_double_in_place(bls12_381_g2_prj* P); +void ctt_bls12_381_g2_prj_affine(bls12_381_g2_aff* dst, const bls12_381_g2_prj* src); +void ctt_bls12_381_g2_prj_from_affine(bls12_381_g2_prj* dst, const bls12_381_g2_aff* src); #ifdef __cplusplus } diff --git a/include/constantine/curves/bls12_381_parallel.h b/include/constantine/curves/bls12_381_parallel.h index 01c5a65d..eadbfcdf 100644 --- a/include/constantine/curves/bls12_381_parallel.h +++ b/include/constantine/curves/bls12_381_parallel.h @@ -18,8 +18,8 @@ extern "C" { #endif -void ctt_bls12_381_ec_g1_jac_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const bls12_381_ec_g1_jac* r, const big255 coefs[], const bls12_381_ec_g1_aff points[], size_t len); -void ctt_bls12_381_ec_g1_prj_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const bls12_381_ec_g1_prj* r, const big255 coefs[], const bls12_381_ec_g1_aff points[], size_t len); +void ctt_bls12_381_g1_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const bls12_381_g1_jac* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); +void ctt_bls12_381_g1_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const bls12_381_g1_prj* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/bn254_snarks.h b/include/constantine/curves/bn254_snarks.h index 6507e664..d925a934 100644 --- a/include/constantine/curves/bn254_snarks.h +++ b/include/constantine/curves/bn254_snarks.h @@ -18,12 +18,12 @@ extern "C" { typedef struct { secret_word limbs[CTT_WORDS_REQUIRED(254)]; } bn254_snarks_fr; typedef struct { secret_word limbs[CTT_WORDS_REQUIRED(254)]; } bn254_snarks_fp; typedef struct { bn254_snarks_fp c[2]; } bn254_snarks_fp2; -typedef struct { bn254_snarks_fp x, y; } bn254_snarks_ec_g1_aff; -typedef struct { bn254_snarks_fp x, y, z; } bn254_snarks_ec_g1_jac; -typedef struct { bn254_snarks_fp x, y, z; } bn254_snarks_ec_g1_prj; -typedef struct { bn254_snarks_fp2 x, y; } bn254_snarks_ec_g2_aff; -typedef struct { bn254_snarks_fp2 x, y, z; } bn254_snarks_ec_g2_jac; -typedef struct { bn254_snarks_fp2 x, y, z; } bn254_snarks_ec_g2_prj; +typedef struct { bn254_snarks_fp x, y; } bn254_snarks_g1_aff; +typedef struct { bn254_snarks_fp x, y, z; } bn254_snarks_g1_jac; +typedef struct { bn254_snarks_fp x, y, z; } bn254_snarks_g1_prj; +typedef struct { bn254_snarks_fp2 x, y; } bn254_snarks_g2_aff; +typedef struct { bn254_snarks_fp2 x, y, z; } bn254_snarks_g2_jac; +typedef struct { bn254_snarks_fp2 x, y, z; } bn254_snarks_g2_prj; ctt_bool ctt_bn254_snarks_fr_unmarshalBE(bn254_snarks_fr* dst, const byte src[], ptrdiff_t src_len) __attribute__((warn_unused_result)); ctt_bool ctt_bn254_snarks_fr_marshalBE(byte dst[], ptrdiff_t dst_len, const bn254_snarks_fr* src) __attribute__((warn_unused_result)); @@ -129,76 +129,76 @@ void ctt_bn254_snarks_fp2_csub_in_place(bn254_snarks_fp2* a, const bn254_ secret_bool ctt_bn254_snarks_fp2_is_square(const bn254_snarks_fp2* a); void ctt_bn254_snarks_fp2_sqrt_in_place(bn254_snarks_fp2* a); secret_bool ctt_bn254_snarks_fp2_sqrt_if_square_in_place(bn254_snarks_fp2* a); -secret_bool ctt_bn254_snarks_ec_g1_aff_is_eq(const bn254_snarks_ec_g1_aff* P, const bn254_snarks_ec_g1_aff* Q); -secret_bool ctt_bn254_snarks_ec_g1_aff_is_inf(const bn254_snarks_ec_g1_aff* P); -void ctt_bn254_snarks_ec_g1_aff_set_inf(bn254_snarks_ec_g1_aff* P); -void ctt_bn254_snarks_ec_g1_aff_ccopy(bn254_snarks_ec_g1_aff* P, const bn254_snarks_ec_g1_aff* Q, secret_bool ctl); -secret_bool ctt_bn254_snarks_ec_g1_aff_is_on_curve(const bn254_snarks_fp* x, const bn254_snarks_fp* y); -void ctt_bn254_snarks_ec_g1_aff_neg(bn254_snarks_ec_g1_aff* P, const bn254_snarks_ec_g1_aff* Q); -void ctt_bn254_snarks_ec_g1_aff_neg_in_place(bn254_snarks_ec_g1_aff* P); -secret_bool ctt_bn254_snarks_ec_g1_jac_is_eq(const bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); -secret_bool ctt_bn254_snarks_ec_g1_jac_is_inf(const bn254_snarks_ec_g1_jac* P); -void ctt_bn254_snarks_ec_g1_jac_set_inf(bn254_snarks_ec_g1_jac* P); -void ctt_bn254_snarks_ec_g1_jac_ccopy(bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q, secret_bool ctl); -void ctt_bn254_snarks_ec_g1_jac_neg(bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); -void ctt_bn254_snarks_ec_g1_jac_neg_in_place(bn254_snarks_ec_g1_jac* P); -void ctt_bn254_snarks_ec_g1_jac_cneg_in_place(bn254_snarks_ec_g1_jac* P, secret_bool ctl); -void ctt_bn254_snarks_ec_g1_jac_sum(bn254_snarks_ec_g1_jac* r, const bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); -void ctt_bn254_snarks_ec_g1_jac_add_in_place(bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); -void ctt_bn254_snarks_ec_g1_jac_diff(bn254_snarks_ec_g1_jac* r, const bn254_snarks_ec_g1_jac* P, const bn254_snarks_ec_g1_jac* Q); -void ctt_bn254_snarks_ec_g1_jac_double(bn254_snarks_ec_g1_jac* r, const bn254_snarks_ec_g1_jac* P); -void ctt_bn254_snarks_ec_g1_jac_double_in_place(bn254_snarks_ec_g1_jac* P); -void ctt_bn254_snarks_ec_g1_jac_affine(bn254_snarks_ec_g1_aff* dst, const bn254_snarks_ec_g1_jac* src); -void ctt_bn254_snarks_ec_g1_jac_from_affine(bn254_snarks_ec_g1_jac* dst, const bn254_snarks_ec_g1_aff* src); -secret_bool ctt_bn254_snarks_ec_g1_prj_is_eq(const bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); -secret_bool ctt_bn254_snarks_ec_g1_prj_is_inf(const bn254_snarks_ec_g1_prj* P); -void ctt_bn254_snarks_ec_g1_prj_set_inf(bn254_snarks_ec_g1_prj* P); -void ctt_bn254_snarks_ec_g1_prj_ccopy(bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q, secret_bool ctl); -void ctt_bn254_snarks_ec_g1_prj_neg(bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); -void ctt_bn254_snarks_ec_g1_prj_neg_in_place(bn254_snarks_ec_g1_prj* P); -void ctt_bn254_snarks_ec_g1_prj_cneg_in_place(bn254_snarks_ec_g1_prj* P, secret_bool ctl); -void ctt_bn254_snarks_ec_g1_prj_sum(bn254_snarks_ec_g1_prj* r, const bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); -void ctt_bn254_snarks_ec_g1_prj_add_in_place(bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); -void ctt_bn254_snarks_ec_g1_prj_diff(bn254_snarks_ec_g1_prj* r, const bn254_snarks_ec_g1_prj* P, const bn254_snarks_ec_g1_prj* Q); -void ctt_bn254_snarks_ec_g1_prj_double(bn254_snarks_ec_g1_prj* r, const bn254_snarks_ec_g1_prj* P); -void ctt_bn254_snarks_ec_g1_prj_double_in_place(bn254_snarks_ec_g1_prj* P); -void ctt_bn254_snarks_ec_g1_prj_affine(bn254_snarks_ec_g1_aff* dst, const bn254_snarks_ec_g1_prj* src); -void ctt_bn254_snarks_ec_g1_prj_from_affine(bn254_snarks_ec_g1_prj* dst, const bn254_snarks_ec_g1_aff* src); -secret_bool ctt_bn254_snarks_ec_g2_aff_is_eq(const bn254_snarks_ec_g2_aff* P, const bn254_snarks_ec_g2_aff* Q); -secret_bool ctt_bn254_snarks_ec_g2_aff_is_inf(const bn254_snarks_ec_g2_aff* P); -void ctt_bn254_snarks_ec_g2_aff_set_inf(bn254_snarks_ec_g2_aff* P); -void ctt_bn254_snarks_ec_g2_aff_ccopy(bn254_snarks_ec_g2_aff* P, const bn254_snarks_ec_g2_aff* Q, secret_bool ctl); -secret_bool ctt_bn254_snarks_ec_g2_aff_is_on_curve(const bn254_snarks_fp2* x, const bn254_snarks_fp2* y); -void ctt_bn254_snarks_ec_g2_aff_neg(bn254_snarks_ec_g2_aff* P, const bn254_snarks_ec_g2_aff* Q); -void ctt_bn254_snarks_ec_g2_aff_neg_in_place(bn254_snarks_ec_g2_aff* P); -secret_bool ctt_bn254_snarks_ec_g2_jac_is_eq(const bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); -secret_bool ctt_bn254_snarks_ec_g2_jac_is_inf(const bn254_snarks_ec_g2_jac* P); -void ctt_bn254_snarks_ec_g2_jac_set_inf(bn254_snarks_ec_g2_jac* P); -void ctt_bn254_snarks_ec_g2_jac_ccopy(bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q, secret_bool ctl); -void ctt_bn254_snarks_ec_g2_jac_neg(bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); -void ctt_bn254_snarks_ec_g2_jac_neg_in_place(bn254_snarks_ec_g2_jac* P); -void ctt_bn254_snarks_ec_g2_jac_cneg_in_place(bn254_snarks_ec_g2_jac* P, secret_bool ctl); -void ctt_bn254_snarks_ec_g2_jac_sum(bn254_snarks_ec_g2_jac* r, const bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); -void ctt_bn254_snarks_ec_g2_jac_add_in_place(bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); -void ctt_bn254_snarks_ec_g2_jac_diff(bn254_snarks_ec_g2_jac* r, const bn254_snarks_ec_g2_jac* P, const bn254_snarks_ec_g2_jac* Q); -void ctt_bn254_snarks_ec_g2_jac_double(bn254_snarks_ec_g2_jac* r, const bn254_snarks_ec_g2_jac* P); -void ctt_bn254_snarks_ec_g2_jac_double_in_place(bn254_snarks_ec_g2_jac* P); -void ctt_bn254_snarks_ec_g2_jac_affine(bn254_snarks_ec_g2_aff* dst, const bn254_snarks_ec_g2_jac* src); -void ctt_bn254_snarks_ec_g2_jac_from_affine(bn254_snarks_ec_g2_jac* dst, const bn254_snarks_ec_g2_aff* src); -secret_bool ctt_bn254_snarks_ec_g2_prj_is_eq(const bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); -secret_bool ctt_bn254_snarks_ec_g2_prj_is_inf(const bn254_snarks_ec_g2_prj* P); -void ctt_bn254_snarks_ec_g2_prj_set_inf(bn254_snarks_ec_g2_prj* P); -void ctt_bn254_snarks_ec_g2_prj_ccopy(bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q, secret_bool ctl); -void ctt_bn254_snarks_ec_g2_prj_neg(bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); -void ctt_bn254_snarks_ec_g2_prj_neg_in_place(bn254_snarks_ec_g2_prj* P); -void ctt_bn254_snarks_ec_g2_prj_cneg_in_place(bn254_snarks_ec_g2_prj* P, secret_bool ctl); -void ctt_bn254_snarks_ec_g2_prj_sum(bn254_snarks_ec_g2_prj* r, const bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); -void ctt_bn254_snarks_ec_g2_prj_add_in_place(bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); -void ctt_bn254_snarks_ec_g2_prj_diff(bn254_snarks_ec_g2_prj* r, const bn254_snarks_ec_g2_prj* P, const bn254_snarks_ec_g2_prj* Q); -void ctt_bn254_snarks_ec_g2_prj_double(bn254_snarks_ec_g2_prj* r, const bn254_snarks_ec_g2_prj* P); -void ctt_bn254_snarks_ec_g2_prj_double_in_place(bn254_snarks_ec_g2_prj* P); -void ctt_bn254_snarks_ec_g2_prj_affine(bn254_snarks_ec_g2_aff* dst, const bn254_snarks_ec_g2_prj* src); -void ctt_bn254_snarks_ec_g2_prj_from_affine(bn254_snarks_ec_g2_prj* dst, const bn254_snarks_ec_g2_aff* src); +secret_bool ctt_bn254_snarks_g1_aff_is_eq(const bn254_snarks_g1_aff* P, const bn254_snarks_g1_aff* Q); +secret_bool ctt_bn254_snarks_g1_aff_is_inf(const bn254_snarks_g1_aff* P); +void ctt_bn254_snarks_g1_aff_set_inf(bn254_snarks_g1_aff* P); +void ctt_bn254_snarks_g1_aff_ccopy(bn254_snarks_g1_aff* P, const bn254_snarks_g1_aff* Q, secret_bool ctl); +secret_bool ctt_bn254_snarks_g1_aff_is_on_curve(const bn254_snarks_fp* x, const bn254_snarks_fp* y); +void ctt_bn254_snarks_g1_aff_neg(bn254_snarks_g1_aff* P, const bn254_snarks_g1_aff* Q); +void ctt_bn254_snarks_g1_aff_neg_in_place(bn254_snarks_g1_aff* P); +secret_bool ctt_bn254_snarks_g1_jac_is_eq(const bn254_snarks_g1_jac* P, const bn254_snarks_g1_jac* Q); +secret_bool ctt_bn254_snarks_g1_jac_is_inf(const bn254_snarks_g1_jac* P); +void ctt_bn254_snarks_g1_jac_set_inf(bn254_snarks_g1_jac* P); +void ctt_bn254_snarks_g1_jac_ccopy(bn254_snarks_g1_jac* P, const bn254_snarks_g1_jac* Q, secret_bool ctl); +void ctt_bn254_snarks_g1_jac_neg(bn254_snarks_g1_jac* P, const bn254_snarks_g1_jac* Q); +void ctt_bn254_snarks_g1_jac_neg_in_place(bn254_snarks_g1_jac* P); +void ctt_bn254_snarks_g1_jac_cneg_in_place(bn254_snarks_g1_jac* P, secret_bool ctl); +void ctt_bn254_snarks_g1_jac_sum(bn254_snarks_g1_jac* r, const bn254_snarks_g1_jac* P, const bn254_snarks_g1_jac* Q); +void ctt_bn254_snarks_g1_jac_add_in_place(bn254_snarks_g1_jac* P, const bn254_snarks_g1_jac* Q); +void ctt_bn254_snarks_g1_jac_diff(bn254_snarks_g1_jac* r, const bn254_snarks_g1_jac* P, const bn254_snarks_g1_jac* Q); +void ctt_bn254_snarks_g1_jac_double(bn254_snarks_g1_jac* r, const bn254_snarks_g1_jac* P); +void ctt_bn254_snarks_g1_jac_double_in_place(bn254_snarks_g1_jac* P); +void ctt_bn254_snarks_g1_jac_affine(bn254_snarks_g1_aff* dst, const bn254_snarks_g1_jac* src); +void ctt_bn254_snarks_g1_jac_from_affine(bn254_snarks_g1_jac* dst, const bn254_snarks_g1_aff* src); +secret_bool ctt_bn254_snarks_g1_prj_is_eq(const bn254_snarks_g1_prj* P, const bn254_snarks_g1_prj* Q); +secret_bool ctt_bn254_snarks_g1_prj_is_inf(const bn254_snarks_g1_prj* P); +void ctt_bn254_snarks_g1_prj_set_inf(bn254_snarks_g1_prj* P); +void ctt_bn254_snarks_g1_prj_ccopy(bn254_snarks_g1_prj* P, const bn254_snarks_g1_prj* Q, secret_bool ctl); +void ctt_bn254_snarks_g1_prj_neg(bn254_snarks_g1_prj* P, const bn254_snarks_g1_prj* Q); +void ctt_bn254_snarks_g1_prj_neg_in_place(bn254_snarks_g1_prj* P); +void ctt_bn254_snarks_g1_prj_cneg_in_place(bn254_snarks_g1_prj* P, secret_bool ctl); +void ctt_bn254_snarks_g1_prj_sum(bn254_snarks_g1_prj* r, const bn254_snarks_g1_prj* P, const bn254_snarks_g1_prj* Q); +void ctt_bn254_snarks_g1_prj_add_in_place(bn254_snarks_g1_prj* P, const bn254_snarks_g1_prj* Q); +void ctt_bn254_snarks_g1_prj_diff(bn254_snarks_g1_prj* r, const bn254_snarks_g1_prj* P, const bn254_snarks_g1_prj* Q); +void ctt_bn254_snarks_g1_prj_double(bn254_snarks_g1_prj* r, const bn254_snarks_g1_prj* P); +void ctt_bn254_snarks_g1_prj_double_in_place(bn254_snarks_g1_prj* P); +void ctt_bn254_snarks_g1_prj_affine(bn254_snarks_g1_aff* dst, const bn254_snarks_g1_prj* src); +void ctt_bn254_snarks_g1_prj_from_affine(bn254_snarks_g1_prj* dst, const bn254_snarks_g1_aff* src); +secret_bool ctt_bn254_snarks_g2_aff_is_eq(const bn254_snarks_g2_aff* P, const bn254_snarks_g2_aff* Q); +secret_bool ctt_bn254_snarks_g2_aff_is_inf(const bn254_snarks_g2_aff* P); +void ctt_bn254_snarks_g2_aff_set_inf(bn254_snarks_g2_aff* P); +void ctt_bn254_snarks_g2_aff_ccopy(bn254_snarks_g2_aff* P, const bn254_snarks_g2_aff* Q, secret_bool ctl); +secret_bool ctt_bn254_snarks_g2_aff_is_on_curve(const bn254_snarks_fp2* x, const bn254_snarks_fp2* y); +void ctt_bn254_snarks_g2_aff_neg(bn254_snarks_g2_aff* P, const bn254_snarks_g2_aff* Q); +void ctt_bn254_snarks_g2_aff_neg_in_place(bn254_snarks_g2_aff* P); +secret_bool ctt_bn254_snarks_g2_jac_is_eq(const bn254_snarks_g2_jac* P, const bn254_snarks_g2_jac* Q); +secret_bool ctt_bn254_snarks_g2_jac_is_inf(const bn254_snarks_g2_jac* P); +void ctt_bn254_snarks_g2_jac_set_inf(bn254_snarks_g2_jac* P); +void ctt_bn254_snarks_g2_jac_ccopy(bn254_snarks_g2_jac* P, const bn254_snarks_g2_jac* Q, secret_bool ctl); +void ctt_bn254_snarks_g2_jac_neg(bn254_snarks_g2_jac* P, const bn254_snarks_g2_jac* Q); +void ctt_bn254_snarks_g2_jac_neg_in_place(bn254_snarks_g2_jac* P); +void ctt_bn254_snarks_g2_jac_cneg_in_place(bn254_snarks_g2_jac* P, secret_bool ctl); +void ctt_bn254_snarks_g2_jac_sum(bn254_snarks_g2_jac* r, const bn254_snarks_g2_jac* P, const bn254_snarks_g2_jac* Q); +void ctt_bn254_snarks_g2_jac_add_in_place(bn254_snarks_g2_jac* P, const bn254_snarks_g2_jac* Q); +void ctt_bn254_snarks_g2_jac_diff(bn254_snarks_g2_jac* r, const bn254_snarks_g2_jac* P, const bn254_snarks_g2_jac* Q); +void ctt_bn254_snarks_g2_jac_double(bn254_snarks_g2_jac* r, const bn254_snarks_g2_jac* P); +void ctt_bn254_snarks_g2_jac_double_in_place(bn254_snarks_g2_jac* P); +void ctt_bn254_snarks_g2_jac_affine(bn254_snarks_g2_aff* dst, const bn254_snarks_g2_jac* src); +void ctt_bn254_snarks_g2_jac_from_affine(bn254_snarks_g2_jac* dst, const bn254_snarks_g2_aff* src); +secret_bool ctt_bn254_snarks_g2_prj_is_eq(const bn254_snarks_g2_prj* P, const bn254_snarks_g2_prj* Q); +secret_bool ctt_bn254_snarks_g2_prj_is_inf(const bn254_snarks_g2_prj* P); +void ctt_bn254_snarks_g2_prj_set_inf(bn254_snarks_g2_prj* P); +void ctt_bn254_snarks_g2_prj_ccopy(bn254_snarks_g2_prj* P, const bn254_snarks_g2_prj* Q, secret_bool ctl); +void ctt_bn254_snarks_g2_prj_neg(bn254_snarks_g2_prj* P, const bn254_snarks_g2_prj* Q); +void ctt_bn254_snarks_g2_prj_neg_in_place(bn254_snarks_g2_prj* P); +void ctt_bn254_snarks_g2_prj_cneg_in_place(bn254_snarks_g2_prj* P, secret_bool ctl); +void ctt_bn254_snarks_g2_prj_sum(bn254_snarks_g2_prj* r, const bn254_snarks_g2_prj* P, const bn254_snarks_g2_prj* Q); +void ctt_bn254_snarks_g2_prj_add_in_place(bn254_snarks_g2_prj* P, const bn254_snarks_g2_prj* Q); +void ctt_bn254_snarks_g2_prj_diff(bn254_snarks_g2_prj* r, const bn254_snarks_g2_prj* P, const bn254_snarks_g2_prj* Q); +void ctt_bn254_snarks_g2_prj_double(bn254_snarks_g2_prj* r, const bn254_snarks_g2_prj* P); +void ctt_bn254_snarks_g2_prj_double_in_place(bn254_snarks_g2_prj* P); +void ctt_bn254_snarks_g2_prj_affine(bn254_snarks_g2_aff* dst, const bn254_snarks_g2_prj* src); +void ctt_bn254_snarks_g2_prj_from_affine(bn254_snarks_g2_prj* dst, const bn254_snarks_g2_aff* src); #ifdef __cplusplus } diff --git a/include/constantine/curves/bn254_snarks_parallel.h b/include/constantine/curves/bn254_snarks_parallel.h index f7cc0663..8a9a5954 100644 --- a/include/constantine/curves/bn254_snarks_parallel.h +++ b/include/constantine/curves/bn254_snarks_parallel.h @@ -18,8 +18,8 @@ extern "C" { #endif -void ctt_bn254_snarks_ec_g1_jac_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const bn254_snarks_ec_g1_jac* r, const big254 coefs[], const bn254_snarks_ec_g1_aff points[], size_t len); -void ctt_bn254_snarks_ec_g1_prj_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const bn254_snarks_ec_g1_prj* r, const big254 coefs[], const bn254_snarks_ec_g1_aff points[], size_t len); +void ctt_bn254_snarks_g1_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const bn254_snarks_g1_jac* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); +void ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const bn254_snarks_g1_prj* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/pallas_parallel.h b/include/constantine/curves/pallas_parallel.h index 7f43d6df..c07bbe43 100644 --- a/include/constantine/curves/pallas_parallel.h +++ b/include/constantine/curves/pallas_parallel.h @@ -18,8 +18,8 @@ extern "C" { #endif -void ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const pallas_ec_jac* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); -void ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const pallas_ec_prj* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const pallas_ec_jac* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const pallas_ec_prj* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/vesta_parallel.h b/include/constantine/curves/vesta_parallel.h index 314b6870..fbc08884 100644 --- a/include/constantine/curves/vesta_parallel.h +++ b/include/constantine/curves/vesta_parallel.h @@ -18,8 +18,8 @@ extern "C" { #endif -void ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const vesta_ec_jac* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); -void ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel(ctt_threadpool* tp, const vesta_ec_prj* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const vesta_ec_jac* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const vesta_ec_prj* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); #ifdef __cplusplus } From 4c479cf66bf5b0d4324348090a83587c8fed5859 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Fri, 1 Dec 2023 20:01:38 +0100 Subject: [PATCH 06/24] zal: now compiles with halo2curves and can call Nim --- Cargo.toml | 2 - bindings/c_curve_decls_parallel.nim | 4 +- .../constantine-curves/Cargo.toml | 9 -- .../constantine-curves/src/lib.rs | 40 ------- .../Cargo.toml | 9 -- .../src/lib.rs | 14 --- .../constantine-sys/src/bindings.rs | 16 +-- .../constantine-zal-halo2kzg/Cargo.toml | 8 +- .../constantine-zal-halo2kzg/src/lib.rs | 105 +++++++++++++++++- .../constantine/curves/bls12_381_parallel.h | 4 +- .../curves/bn254_snarks_parallel.h | 4 +- include/constantine/curves/pallas_parallel.h | 4 +- include/constantine/curves/vesta_parallel.h | 4 +- 13 files changed, 125 insertions(+), 98 deletions(-) delete mode 100644 constantine-rust/constantine-curves/Cargo.toml delete mode 100644 constantine-rust/constantine-curves/src/lib.rs delete mode 100644 constantine-rust/constantine-proto-ethereum-bls-signatures/Cargo.toml delete mode 100644 constantine-rust/constantine-proto-ethereum-bls-signatures/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 0fade026..9a8c91dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,9 +2,7 @@ resolver = "2" members = [ "constantine-rust/constantine-sys", - "constantine-rust/constantine-curves", "constantine-rust/constantine-zal-halo2kzg", - "constantine-rust/constantine-proto-ethereum-bls-signatures", ] # If Nim static library is compiled with Clang ThinLTO, enable it on Rust side diff --git a/bindings/c_curve_decls_parallel.nim b/bindings/c_curve_decls_parallel.nim index f81bc6b6..f9c5fcb2 100644 --- a/bindings/c_curve_decls_parallel.nim +++ b/bindings/c_curve_decls_parallel.nim @@ -28,8 +28,8 @@ template genParallelBindings_EC_ShortW_NonAffine*(ECP, ECP_Aff: untyped) = # -------------------------------------------------------------------------------------- proc `ctt _ ECP _ multi_scalar_mul_vartime_parallel`( tp: Threadpool, - r: ptr ECP, + r: var ECP, coefs: ptr UncheckedArray[BigInt[ECP.F.C.getCurveOrderBitwidth()]], points: ptr UncheckedArray[ECP_Aff], len: csize_t) {.libExport.} = - tp.multiScalarMul_vartime_parallel(r, coefs, points, cast[int](len)) + tp.multiScalarMul_vartime_parallel(r.addr, coefs, points, cast[int](len)) diff --git a/constantine-rust/constantine-curves/Cargo.toml b/constantine-rust/constantine-curves/Cargo.toml deleted file mode 100644 index 65dc12de..00000000 --- a/constantine-rust/constantine-curves/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "constantine-curves" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -constantine-sys = { path = "../constantine-sys" } \ No newline at end of file diff --git a/constantine-rust/constantine-curves/src/lib.rs b/constantine-rust/constantine-curves/src/lib.rs deleted file mode 100644 index f4f216dc..00000000 --- a/constantine-rust/constantine-curves/src/lib.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! 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. - -use constantine_sys::*; - -pub struct CttThreadpool { - ctx: *mut ctt_threadpool, -} - -impl CttThreadpool { - #[inline(always)] - pub fn new(num_threads: usize) -> CttThreadpool { - let ctx = unsafe{ ctt_threadpool_new(num_threads) }; - CttThreadpool{ctx} - } -} - -impl Drop for CttThreadpool { - fn drop(&mut self) { - unsafe { ctt_threadpool_shutdown(self.ctx) } - } -} - - - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn t_threadpool() { - let tp = CttThreadpool::new(4); - drop(tp); - } -} diff --git a/constantine-rust/constantine-proto-ethereum-bls-signatures/Cargo.toml b/constantine-rust/constantine-proto-ethereum-bls-signatures/Cargo.toml deleted file mode 100644 index 15ec5f3a..00000000 --- a/constantine-rust/constantine-proto-ethereum-bls-signatures/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "constantine-proto-ethereum-bls-signatures" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -constantine-sys = { path = "../constantine-sys" } \ No newline at end of file diff --git a/constantine-rust/constantine-proto-ethereum-bls-signatures/src/lib.rs b/constantine-rust/constantine-proto-ethereum-bls-signatures/src/lib.rs deleted file mode 100644 index 7d12d9af..00000000 --- a/constantine-rust/constantine-proto-ethereum-bls-signatures/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/constantine-rust/constantine-sys/src/bindings.rs b/constantine-rust/constantine-sys/src/bindings.rs index 34161a8a..da448b64 100644 --- a/constantine-rust/constantine-sys/src/bindings.rs +++ b/constantine-rust/constantine-sys/src/bindings.rs @@ -3536,7 +3536,7 @@ fn bindgen_test_layout_big254() { extern "C" { pub fn ctt_bls12_381_g1_jac_multi_scalar_mul_vartime_parallel( tp: *const ctt_threadpool, - r: *const bls12_381_g1_jac, + r: *mut bls12_381_g1_jac, coefs: *const big255, points: *const bls12_381_g1_aff, len: usize, @@ -3545,7 +3545,7 @@ extern "C" { extern "C" { pub fn ctt_bls12_381_g1_prj_multi_scalar_mul_vartime_parallel( tp: *const ctt_threadpool, - r: *const bls12_381_g1_prj, + r: *mut bls12_381_g1_prj, coefs: *const big255, points: *const bls12_381_g1_aff, len: usize, @@ -3554,7 +3554,7 @@ extern "C" { extern "C" { pub fn ctt_bn254_snarks_g1_jac_multi_scalar_mul_vartime_parallel( tp: *const ctt_threadpool, - r: *const bn254_snarks_g1_jac, + r: *mut bn254_snarks_g1_jac, coefs: *const big254, points: *const bn254_snarks_g1_aff, len: usize, @@ -3563,7 +3563,7 @@ extern "C" { extern "C" { pub fn ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel( tp: *const ctt_threadpool, - r: *const bn254_snarks_g1_prj, + r: *mut bn254_snarks_g1_prj, coefs: *const big254, points: *const bn254_snarks_g1_aff, len: usize, @@ -3572,7 +3572,7 @@ extern "C" { extern "C" { pub fn ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel( tp: *const ctt_threadpool, - r: *const pallas_ec_jac, + r: *mut pallas_ec_jac, coefs: *const big255, points: *const pallas_ec_aff, len: usize, @@ -3581,7 +3581,7 @@ extern "C" { extern "C" { pub fn ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel( tp: *const ctt_threadpool, - r: *const pallas_ec_prj, + r: *mut pallas_ec_prj, coefs: *const big255, points: *const pallas_ec_aff, len: usize, @@ -3590,7 +3590,7 @@ extern "C" { extern "C" { pub fn ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel( tp: *const ctt_threadpool, - r: *const vesta_ec_jac, + r: *mut vesta_ec_jac, coefs: *const big255, points: *const vesta_ec_aff, len: usize, @@ -3599,7 +3599,7 @@ extern "C" { extern "C" { pub fn ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel( tp: *const ctt_threadpool, - r: *const vesta_ec_prj, + r: *mut vesta_ec_prj, coefs: *const big255, points: *const vesta_ec_aff, len: usize, diff --git a/constantine-rust/constantine-zal-halo2kzg/Cargo.toml b/constantine-rust/constantine-zal-halo2kzg/Cargo.toml index 9ab2f431..dafb0531 100644 --- a/constantine-rust/constantine-zal-halo2kzg/Cargo.toml +++ b/constantine-rust/constantine-zal-halo2kzg/Cargo.toml @@ -6,4 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -constantine-curves = { path = "../constantine-curves" } \ No newline at end of file +constantine-sys = { path = "../constantine-sys" } +halo2curves = { git = 'https://github.com/taikoxyz/halo2curves', branch = "pr-pse-exec-engine" } + +[dev-dependencies] +ark-std = "0.3" +rand_core = { version = "0.6", default-features = false } +num_cpus = "1.16.0" \ No newline at end of file diff --git a/constantine-rust/constantine-zal-halo2kzg/src/lib.rs b/constantine-rust/constantine-zal-halo2kzg/src/lib.rs index 7d12d9af..9c746183 100644 --- a/constantine-rust/constantine-zal-halo2kzg/src/lib.rs +++ b/constantine-rust/constantine-zal-halo2kzg/src/lib.rs @@ -1,14 +1,109 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +//! 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. + +//! See https://github.com/privacy-scaling-explorations/halo2/issues/216 + +use std::mem; +use ::core::mem::MaybeUninit; +use constantine_sys::*; +use halo2curves::bn256; +use halo2curves::zal::{ZalEngine, MsmAccel}; + +pub struct CttEngine { + ctx: *mut ctt_threadpool, +} + +impl CttEngine { + #[inline(always)] + pub fn new(num_threads: usize) -> CttEngine { + let ctx = unsafe{ ctt_threadpool_new(num_threads) }; + CttEngine{ctx} + } +} + +impl Drop for CttEngine { + fn drop(&mut self) { + unsafe { ctt_threadpool_shutdown(self.ctx) } + } +} + +impl ZalEngine for CttEngine{} + +impl MsmAccel for CttEngine { + fn msm(&self, coeffs: &[bn256::Fr], bases: &[bn256::G1Affine]) -> bn256::G1 { + + assert_eq!(coeffs.len(), bases.len()); + let mut result: MaybeUninit = MaybeUninit::uninit(); + unsafe { + ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel( + self.ctx, + result.as_mut_ptr(), + coeffs.as_ptr() as *const big254, + bases.as_ptr() as *const bn254_snarks_g1_aff, + bases.len() + ); + mem::transmute::, bn256::G1>(result) + } + } } #[cfg(test)] mod tests { use super::*; + use ark_std::{end_timer, start_timer}; + use rand_core::OsRng; + + use halo2curves::bn256; + use halo2curves::ff::Field; + use halo2curves::group::{Curve, Group}; + use halo2curves::group::prime::PrimeCurveAffine; + use halo2curves::zal::MsmAccel; + use halo2curves::msm::best_multiexp; + #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); + fn t_threadpool() { + let tp = CttEngine::new(4); + drop(tp); } + + fn run_msm_zal(min_k: usize, max_k: usize) { + let points = (0..1 << max_k) + .map(|_| bn256::G1::random(OsRng)) + .collect::>(); + let mut affine_points = vec![bn256::G1Affine::identity(); 1 << max_k]; + bn256::G1::batch_normalize(&points[..], &mut affine_points[..]); + let points = affine_points; + + let scalars = (0..1 << max_k) + .map(|_| bn256::Fr::random(OsRng)) + .collect::>(); + + for k in min_k..=max_k { + let points = &points[..1 << k]; + let scalars = &scalars[..1 << k]; + + let t0 = start_timer!(|| format!("freestanding msm k={}", k)); + let e0 = best_multiexp(scalars, points); + end_timer!(t0); + + let engine = CttEngine::new(num_cpus::get()); + let t1 = start_timer!(|| format!("CttEngine msm k={}", k)); + let e1 = engine.msm(scalars, points); + end_timer!(t1); + + assert_eq!(e0, e1); + } + } + + #[test] + fn t_msm_zal() { + run_msm_zal(3, 14); + } + } diff --git a/include/constantine/curves/bls12_381_parallel.h b/include/constantine/curves/bls12_381_parallel.h index eadbfcdf..9a9a0a94 100644 --- a/include/constantine/curves/bls12_381_parallel.h +++ b/include/constantine/curves/bls12_381_parallel.h @@ -18,8 +18,8 @@ extern "C" { #endif -void ctt_bls12_381_g1_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const bls12_381_g1_jac* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); -void ctt_bls12_381_g1_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const bls12_381_g1_prj* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); +void ctt_bls12_381_g1_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, bls12_381_g1_jac* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); +void ctt_bls12_381_g1_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, bls12_381_g1_prj* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/bn254_snarks_parallel.h b/include/constantine/curves/bn254_snarks_parallel.h index 8a9a5954..565aaf71 100644 --- a/include/constantine/curves/bn254_snarks_parallel.h +++ b/include/constantine/curves/bn254_snarks_parallel.h @@ -18,8 +18,8 @@ extern "C" { #endif -void ctt_bn254_snarks_g1_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const bn254_snarks_g1_jac* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); -void ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const bn254_snarks_g1_prj* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); +void ctt_bn254_snarks_g1_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, bn254_snarks_g1_jac* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); +void ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, bn254_snarks_g1_prj* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/pallas_parallel.h b/include/constantine/curves/pallas_parallel.h index c07bbe43..d4a29e44 100644 --- a/include/constantine/curves/pallas_parallel.h +++ b/include/constantine/curves/pallas_parallel.h @@ -18,8 +18,8 @@ extern "C" { #endif -void ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const pallas_ec_jac* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); -void ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const pallas_ec_prj* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, pallas_ec_jac* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, pallas_ec_prj* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/vesta_parallel.h b/include/constantine/curves/vesta_parallel.h index fbc08884..e52002d9 100644 --- a/include/constantine/curves/vesta_parallel.h +++ b/include/constantine/curves/vesta_parallel.h @@ -18,8 +18,8 @@ extern "C" { #endif -void ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const vesta_ec_jac* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); -void ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, const vesta_ec_prj* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, vesta_ec_jac* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, vesta_ec_prj* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); #ifdef __cplusplus } From a0e358c72f9e569289a0d30962b375891b2c84ad Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Fri, 1 Dec 2023 21:11:12 +0100 Subject: [PATCH 07/24] zal: Pass tests --- bindings/c_curve_decls_parallel.nim | 26 +++++- bindings/lib_curves.nim | 16 ++-- .../constantine-sys/src/bindings.rs | 88 +++++++++++++++++-- .../constantine-zal-halo2kzg/src/lib.rs | 4 +- constantine/curves_primitives.nim | 3 + .../constantine/curves/bls12_381_parallel.h | 6 +- .../curves/bn254_snarks_parallel.h | 6 +- include/constantine/curves/pallas_parallel.h | 6 +- include/constantine/curves/vesta_parallel.h | 6 +- 9 files changed, 132 insertions(+), 29 deletions(-) diff --git a/bindings/c_curve_decls_parallel.nim b/bindings/c_curve_decls_parallel.nim index f9c5fcb2..43824f62 100644 --- a/bindings/c_curve_decls_parallel.nim +++ b/bindings/c_curve_decls_parallel.nim @@ -8,11 +8,13 @@ import ../constantine/math/config/curves, - ../constantine/curves_primitives_parallel + ../constantine/curves_primitives_parallel, + ../constantine/platforms/allocs, + ../constantine/threadpool export curves_primitives_parallel -template genParallelBindings_EC_ShortW_NonAffine*(ECP, ECP_Aff: untyped) = +template genParallelBindings_EC_ShortW_NonAffine*(ECP, ECP_Aff, ScalarField: untyped) = # For some unknown reason {.push noconv.} # would overwrite the threadpool {.nimcall.} # in the parallel for-loop `generateClosure` @@ -26,10 +28,28 @@ template genParallelBindings_EC_ShortW_NonAffine*(ECP, ECP_Aff: untyped) = {.pragma: libExport, exportc, raises: [].} # No exceptions allowed # -------------------------------------------------------------------------------------- - proc `ctt _ ECP _ multi_scalar_mul_vartime_parallel`( + proc `ctt _ ECP _ multi_scalar_mul_big_coefs_vartime_parallel`( tp: Threadpool, r: var ECP, coefs: ptr UncheckedArray[BigInt[ECP.F.C.getCurveOrderBitwidth()]], points: ptr UncheckedArray[ECP_Aff], len: csize_t) {.libExport.} = tp.multiScalarMul_vartime_parallel(r.addr, coefs, points, cast[int](len)) + + proc `ctt _ ECP _ multi_scalar_mul_fr_coefs_vartime_parallel`( + tp: Threadpool, + r: var ECP, + coefs: ptr UncheckedArray[ScalarField], + points: ptr UncheckedArray[ECP_Aff], + len: csize_t) {.libExport.} = + + let n = cast[int](len) + let coefs_fr = allocHeapArrayAligned(matchingOrderBigInt(ECP.F.C), n, alignment = 64) + + syncScope: + tp.parallelFor i in 0 ..< n: + captures: {coefs, coefs_fr} + coefs_fr[i].fromField(coefs[i]) + tp.multiScalarMul_vartime_parallel(r.addr, coefs_fr, points, n) + + freeHeapAligned(coefs_fr) \ No newline at end of file diff --git a/bindings/lib_curves.nim b/bindings/lib_curves.nim index 00ee069a..da857ab2 100644 --- a/bindings/lib_curves.nim +++ b/bindings/lib_curves.nim @@ -45,8 +45,8 @@ collectBindings(cBindings_bls12_381): genBindings_EC_ShortW_NonAffine(bls12_381_g2_prj, bls12_381_g2_aff) collectBindings(cBindings_bls12_381_parallel): - genParallelBindings_EC_ShortW_NonAffine(bls12_381_g1_jac, bls12_381_g1_aff) - genParallelBindings_EC_ShortW_NonAffine(bls12_381_g1_prj, bls12_381_g1_aff) + genParallelBindings_EC_ShortW_NonAffine(bls12_381_g1_jac, bls12_381_g1_aff, bls12_381_fr) + genParallelBindings_EC_ShortW_NonAffine(bls12_381_g1_prj, bls12_381_g1_aff, bls12_381_fr) # ---------------------------------------------------------- type @@ -74,8 +74,8 @@ collectBindings(cBindings_bn254_snarks): genBindings_EC_ShortW_NonAffine(bn254_snarks_g2_prj, bn254_snarks_g2_aff) collectBindings(cBindings_bn254_snarks_parallel): - genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_g1_jac, bn254_snarks_g1_aff) - genParallelBindings_EC_ShortW_NonAffine(bn254_snarks_g1_prj, bn254_snarks_g1_aff) + 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) # ---------------------------------------------------------- @@ -95,8 +95,8 @@ collectBindings(cBindings_pallas): genBindings_EC_ShortW_NonAffine(pallas_ec_prj, pallas_ec_aff) collectBindings(cBindings_pallas_parallel): - genParallelBindings_EC_ShortW_NonAffine(pallas_ec_jac, pallas_ec_aff) - genParallelBindings_EC_ShortW_NonAffine(pallas_ec_prj, pallas_ec_aff) + genParallelBindings_EC_ShortW_NonAffine(pallas_ec_jac, pallas_ec_aff, pallas_fr) + genParallelBindings_EC_ShortW_NonAffine(pallas_ec_prj, pallas_ec_aff, pallas_fr) type vesta_fr = Fr[Vesta] @@ -114,7 +114,7 @@ collectBindings(cBindings_vesta): genBindings_EC_ShortW_NonAffine(vesta_ec_prj, vesta_ec_aff) collectBindings(cBindings_vesta_parallel): - genParallelBindings_EC_ShortW_NonAffine(vesta_ec_jac, vesta_ec_aff) - genParallelBindings_EC_ShortW_NonAffine(vesta_ec_prj, vesta_ec_aff) + genParallelBindings_EC_ShortW_NonAffine(vesta_ec_jac, vesta_ec_aff, vesta_fr) + genParallelBindings_EC_ShortW_NonAffine(vesta_ec_prj, vesta_ec_aff, vesta_fr) # ---------------------------------------------------------- diff --git a/constantine-rust/constantine-sys/src/bindings.rs b/constantine-rust/constantine-sys/src/bindings.rs index da448b64..670ff463 100644 --- a/constantine-rust/constantine-sys/src/bindings.rs +++ b/constantine-rust/constantine-sys/src/bindings.rs @@ -3534,7 +3534,7 @@ fn bindgen_test_layout_big254() { ); } extern "C" { - pub fn ctt_bls12_381_g1_jac_multi_scalar_mul_vartime_parallel( + pub fn ctt_bls12_381_g1_jac_multi_scalar_mul_big_coefs_vartime_parallel( tp: *const ctt_threadpool, r: *mut bls12_381_g1_jac, coefs: *const big255, @@ -3543,7 +3543,16 @@ extern "C" { ); } extern "C" { - pub fn ctt_bls12_381_g1_prj_multi_scalar_mul_vartime_parallel( + pub fn ctt_bls12_381_g1_jac_multi_scalar_mul_fr_coefs_vartime_parallel( + tp: *const ctt_threadpool, + r: *mut bls12_381_g1_jac, + coefs: *const bls12_381_fr, + points: *const bls12_381_g1_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_bls12_381_g1_prj_multi_scalar_mul_big_coefs_vartime_parallel( tp: *const ctt_threadpool, r: *mut bls12_381_g1_prj, coefs: *const big255, @@ -3552,7 +3561,16 @@ extern "C" { ); } extern "C" { - pub fn ctt_bn254_snarks_g1_jac_multi_scalar_mul_vartime_parallel( + pub fn ctt_bls12_381_g1_prj_multi_scalar_mul_fr_coefs_vartime_parallel( + tp: *const ctt_threadpool, + r: *mut bls12_381_g1_prj, + coefs: *const bls12_381_fr, + points: *const bls12_381_g1_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_bn254_snarks_g1_jac_multi_scalar_mul_big_coefs_vartime_parallel( tp: *const ctt_threadpool, r: *mut bn254_snarks_g1_jac, coefs: *const big254, @@ -3561,7 +3579,16 @@ extern "C" { ); } extern "C" { - pub fn ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel( + pub fn ctt_bn254_snarks_g1_jac_multi_scalar_mul_fr_coefs_vartime_parallel( + tp: *const ctt_threadpool, + r: *mut bn254_snarks_g1_jac, + coefs: *const bn254_snarks_fr, + points: *const bn254_snarks_g1_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_bn254_snarks_g1_prj_multi_scalar_mul_big_coefs_vartime_parallel( tp: *const ctt_threadpool, r: *mut bn254_snarks_g1_prj, coefs: *const big254, @@ -3570,7 +3597,16 @@ extern "C" { ); } extern "C" { - pub fn ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel( + pub fn ctt_bn254_snarks_g1_prj_multi_scalar_mul_fr_coefs_vartime_parallel( + tp: *const ctt_threadpool, + r: *mut bn254_snarks_g1_prj, + coefs: *const bn254_snarks_fr, + points: *const bn254_snarks_g1_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_pallas_ec_jac_multi_scalar_mul_big_coefs_vartime_parallel( tp: *const ctt_threadpool, r: *mut pallas_ec_jac, coefs: *const big255, @@ -3579,7 +3615,16 @@ extern "C" { ); } extern "C" { - pub fn ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel( + pub fn ctt_pallas_ec_jac_multi_scalar_mul_fr_coefs_vartime_parallel( + tp: *const ctt_threadpool, + r: *mut pallas_ec_jac, + coefs: *const pallas_fr, + points: *const pallas_ec_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_pallas_ec_prj_multi_scalar_mul_big_coefs_vartime_parallel( tp: *const ctt_threadpool, r: *mut pallas_ec_prj, coefs: *const big255, @@ -3588,7 +3633,16 @@ extern "C" { ); } extern "C" { - pub fn ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel( + pub fn ctt_pallas_ec_prj_multi_scalar_mul_fr_coefs_vartime_parallel( + tp: *const ctt_threadpool, + r: *mut pallas_ec_prj, + coefs: *const pallas_fr, + points: *const pallas_ec_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_vesta_ec_jac_multi_scalar_mul_big_coefs_vartime_parallel( tp: *const ctt_threadpool, r: *mut vesta_ec_jac, coefs: *const big255, @@ -3597,7 +3651,16 @@ extern "C" { ); } extern "C" { - pub fn ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel( + pub fn ctt_vesta_ec_jac_multi_scalar_mul_fr_coefs_vartime_parallel( + tp: *const ctt_threadpool, + r: *mut vesta_ec_jac, + coefs: *const vesta_fr, + points: *const vesta_ec_aff, + len: usize, + ); +} +extern "C" { + pub fn ctt_vesta_ec_prj_multi_scalar_mul_big_coefs_vartime_parallel( tp: *const ctt_threadpool, r: *mut vesta_ec_prj, coefs: *const big255, @@ -3605,6 +3668,15 @@ extern "C" { len: usize, ); } +extern "C" { + pub fn ctt_vesta_ec_prj_multi_scalar_mul_fr_coefs_vartime_parallel( + tp: *const ctt_threadpool, + r: *mut vesta_ec_prj, + coefs: *const vesta_fr, + points: *const vesta_ec_aff, + len: usize, + ); +} #[repr(u8)] #[derive(Copy, Clone, Hash, PartialEq, Eq)] pub enum ctt_codec_scalar_status { diff --git a/constantine-rust/constantine-zal-halo2kzg/src/lib.rs b/constantine-rust/constantine-zal-halo2kzg/src/lib.rs index 9c746183..0b6690f2 100644 --- a/constantine-rust/constantine-zal-halo2kzg/src/lib.rs +++ b/constantine-rust/constantine-zal-halo2kzg/src/lib.rs @@ -40,10 +40,10 @@ impl MsmAccel for CttEngine { assert_eq!(coeffs.len(), bases.len()); let mut result: MaybeUninit = MaybeUninit::uninit(); unsafe { - ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel( + ctt_bn254_snarks_g1_prj_multi_scalar_mul_fr_coefs_vartime_parallel( self.ctx, result.as_mut_ptr(), - coeffs.as_ptr() as *const big254, + coeffs.as_ptr() as *const bn254_snarks_fr, bases.as_ptr() as *const bn254_snarks_g1_aff, bases.len() ); diff --git a/constantine/curves_primitives.nim b/constantine/curves_primitives.nim index 2fb299b3..a0958eb2 100644 --- a/constantine/curves_primitives.nim +++ b/constantine/curves_primitives.nim @@ -67,6 +67,9 @@ func marshalBE*(dst: var openarray[byte], src: FF): bool = raw.fromField(src) return dst.marshal(src, bigEndian) +export arithmetic.fromBig +export arithmetic.fromField + export arithmetic.ccopy export arithmetic.cswap diff --git a/include/constantine/curves/bls12_381_parallel.h b/include/constantine/curves/bls12_381_parallel.h index 9a9a0a94..b7687b55 100644 --- a/include/constantine/curves/bls12_381_parallel.h +++ b/include/constantine/curves/bls12_381_parallel.h @@ -18,8 +18,10 @@ extern "C" { #endif -void ctt_bls12_381_g1_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, bls12_381_g1_jac* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); -void ctt_bls12_381_g1_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, bls12_381_g1_prj* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); +void ctt_bls12_381_g1_jac_multi_scalar_mul_big_coefs_vartime_parallel(const ctt_threadpool* tp, bls12_381_g1_jac* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); +void ctt_bls12_381_g1_jac_multi_scalar_mul_fr_coefs_vartime_parallel(const ctt_threadpool* tp, bls12_381_g1_jac* r, const bls12_381_fr coefs[], const bls12_381_g1_aff points[], size_t len); +void ctt_bls12_381_g1_prj_multi_scalar_mul_big_coefs_vartime_parallel(const ctt_threadpool* tp, bls12_381_g1_prj* r, const big255 coefs[], const bls12_381_g1_aff points[], size_t len); +void ctt_bls12_381_g1_prj_multi_scalar_mul_fr_coefs_vartime_parallel(const ctt_threadpool* tp, bls12_381_g1_prj* r, const bls12_381_fr coefs[], const bls12_381_g1_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/bn254_snarks_parallel.h b/include/constantine/curves/bn254_snarks_parallel.h index 565aaf71..5b9ed334 100644 --- a/include/constantine/curves/bn254_snarks_parallel.h +++ b/include/constantine/curves/bn254_snarks_parallel.h @@ -18,8 +18,10 @@ extern "C" { #endif -void ctt_bn254_snarks_g1_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, bn254_snarks_g1_jac* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); -void ctt_bn254_snarks_g1_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, bn254_snarks_g1_prj* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); +void ctt_bn254_snarks_g1_jac_multi_scalar_mul_big_coefs_vartime_parallel(const ctt_threadpool* tp, bn254_snarks_g1_jac* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); +void ctt_bn254_snarks_g1_jac_multi_scalar_mul_fr_coefs_vartime_parallel(const ctt_threadpool* tp, bn254_snarks_g1_jac* r, const bn254_snarks_fr coefs[], const bn254_snarks_g1_aff points[], size_t len); +void ctt_bn254_snarks_g1_prj_multi_scalar_mul_big_coefs_vartime_parallel(const ctt_threadpool* tp, bn254_snarks_g1_prj* r, const big254 coefs[], const bn254_snarks_g1_aff points[], size_t len); +void ctt_bn254_snarks_g1_prj_multi_scalar_mul_fr_coefs_vartime_parallel(const ctt_threadpool* tp, bn254_snarks_g1_prj* r, const bn254_snarks_fr coefs[], const bn254_snarks_g1_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/pallas_parallel.h b/include/constantine/curves/pallas_parallel.h index d4a29e44..17a4e973 100644 --- a/include/constantine/curves/pallas_parallel.h +++ b/include/constantine/curves/pallas_parallel.h @@ -18,8 +18,10 @@ extern "C" { #endif -void ctt_pallas_ec_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, pallas_ec_jac* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); -void ctt_pallas_ec_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, pallas_ec_prj* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_jac_multi_scalar_mul_big_coefs_vartime_parallel(const ctt_threadpool* tp, pallas_ec_jac* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_jac_multi_scalar_mul_fr_coefs_vartime_parallel(const ctt_threadpool* tp, pallas_ec_jac* r, const pallas_fr coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_prj_multi_scalar_mul_big_coefs_vartime_parallel(const ctt_threadpool* tp, pallas_ec_prj* r, const big255 coefs[], const pallas_ec_aff points[], size_t len); +void ctt_pallas_ec_prj_multi_scalar_mul_fr_coefs_vartime_parallel(const ctt_threadpool* tp, pallas_ec_prj* r, const pallas_fr coefs[], const pallas_ec_aff points[], size_t len); #ifdef __cplusplus } diff --git a/include/constantine/curves/vesta_parallel.h b/include/constantine/curves/vesta_parallel.h index e52002d9..cc5531ff 100644 --- a/include/constantine/curves/vesta_parallel.h +++ b/include/constantine/curves/vesta_parallel.h @@ -18,8 +18,10 @@ extern "C" { #endif -void ctt_vesta_ec_jac_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, vesta_ec_jac* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); -void ctt_vesta_ec_prj_multi_scalar_mul_vartime_parallel(const ctt_threadpool* tp, vesta_ec_prj* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_jac_multi_scalar_mul_big_coefs_vartime_parallel(const ctt_threadpool* tp, vesta_ec_jac* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_jac_multi_scalar_mul_fr_coefs_vartime_parallel(const ctt_threadpool* tp, vesta_ec_jac* r, const vesta_fr coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_prj_multi_scalar_mul_big_coefs_vartime_parallel(const ctt_threadpool* tp, vesta_ec_prj* r, const big255 coefs[], const vesta_ec_aff points[], size_t len); +void ctt_vesta_ec_prj_multi_scalar_mul_fr_coefs_vartime_parallel(const ctt_threadpool* tp, vesta_ec_prj* r, const vesta_fr coefs[], const vesta_ec_aff points[], size_t len); #ifdef __cplusplus } From 5fe449cfba3d4aa43d9922702d9b94068ebf3276 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 2 Dec 2023 09:06:39 +0100 Subject: [PATCH 08/24] zal: add benches Halo2curves vs Constantine --- Cargo.toml | 9 +- constantine-rust/constantine-sys/Cargo.toml | 4 +- constantine-rust/constantine-sys/build.rs | 45 ++++--- constantine-rust/constantine-sys/src/lib.rs | 2 +- .../constantine-zal-halo2kzg/Cargo.toml | 20 ++- .../constantine-zal-halo2kzg/benches/msm.rs | 114 ++++++++++++++++++ .../constantine-zal-halo2kzg/src/lib.rs | 27 ++--- 7 files changed, 187 insertions(+), 34 deletions(-) create mode 100644 constantine-rust/constantine-zal-halo2kzg/benches/msm.rs diff --git a/Cargo.toml b/Cargo.toml index 9a8c91dd..4475912c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,11 @@ members = [ # lto = "thin" # # [profile.bench] -# lto = "thin" \ No newline at end of file +# lto = "thin" + +[profile.bench] +opt-level = 3 +debug = false +debug-assertions = false +overflow-checks = false +codegen-units = 1 diff --git a/constantine-rust/constantine-sys/Cargo.toml b/constantine-rust/constantine-sys/Cargo.toml index 6355fe55..da004ff3 100644 --- a/constantine-rust/constantine-sys/Cargo.toml +++ b/constantine-rust/constantine-sys/Cargo.toml @@ -3,6 +3,8 @@ name = "constantine-sys" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +authors = ["Mamy André-Ratsimbazafy"] +license = "MIT/Apache-2.0" +repository = "https://github.com/mratsim/constantine" [dependencies] diff --git a/constantine-rust/constantine-sys/build.rs b/constantine-rust/constantine-sys/build.rs index 4887e130..39c13716 100644 --- a/constantine-rust/constantine-sys/build.rs +++ b/constantine-rust/constantine-sys/build.rs @@ -14,24 +14,41 @@ fn main() { // Avoid full recompilation println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=Cargo.toml"); - println!("cargo:rerun-if-changed={}", cargo_dir.join(".cargo").join("config.toml").display()); - println!("cargo:rerun-if-changed={}", root_dir.join("Cargo.toml").display()); - println!("cargo:rerun-if-changed={}", root_dir.join("constantine").display()); - println!("cargo:rerun-if-changed={}", root_dir.join("bindings").display()); - println!("cargo:rerun-if-changed={}", root_dir.join("include").display()); - println!("cargo:rerun-if-changed={}", root_dir.join("constantine.nimble").display()); + println!( + "cargo:rerun-if-changed={}", + cargo_dir.join(".cargo").join("config.toml").display() + ); + println!( + "cargo:rerun-if-changed={}", + root_dir.join("Cargo.toml").display() + ); + println!( + "cargo:rerun-if-changed={}", + root_dir.join("constantine").display() + ); + println!( + "cargo:rerun-if-changed={}", + root_dir.join("bindings").display() + ); + println!( + "cargo:rerun-if-changed={}", + root_dir.join("include").display() + ); + println!( + "cargo:rerun-if-changed={}", + root_dir.join("constantine.nimble").display() + ); println!("Building Constantine library ..."); Command::new("nimble") - .arg("make_lib_rust") - .current_dir(root_dir) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .status() - .expect("failed to execute process"); + .arg("make_lib_rust") + .current_dir(root_dir) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .status() + .expect("failed to execute process"); println!("cargo:rustc-link-search=native={}", out_dir.display()); println!("cargo:rustc-link-lib=static=constantine"); - -} \ No newline at end of file +} diff --git a/constantine-rust/constantine-sys/src/lib.rs b/constantine-rust/constantine-sys/src/lib.rs index 5e6c9215..dad9d322 100644 --- a/constantine-rust/constantine-sys/src/lib.rs +++ b/constantine-rust/constantine-sys/src/lib.rs @@ -2,4 +2,4 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] -include!("bindings.rs"); \ No newline at end of file +include!("bindings.rs"); diff --git a/constantine-rust/constantine-zal-halo2kzg/Cargo.toml b/constantine-rust/constantine-zal-halo2kzg/Cargo.toml index dafb0531..f4e83720 100644 --- a/constantine-rust/constantine-zal-halo2kzg/Cargo.toml +++ b/constantine-rust/constantine-zal-halo2kzg/Cargo.toml @@ -1,9 +1,11 @@ [package] -name = "constantine-zal-halo2curves" +name = "constantine-zal-halo2kzg" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +authors = ["Mamy André-Ratsimbazafy"] +license = "MIT/Apache-2.0" +repository = "https://github.com/mratsim/constantine" [dependencies] constantine-sys = { path = "../constantine-sys" } @@ -12,4 +14,16 @@ halo2curves = { git = 'https://github.com/taikoxyz/halo2curves', branch = "pr-ps [dev-dependencies] ark-std = "0.3" rand_core = { version = "0.6", default-features = false } -num_cpus = "1.16.0" \ No newline at end of file +num_cpus = "1.16.0" + +# Benchmark-only dependencies +criterion = { version = "0.3", features = ["html_reports"] } +rand_xorshift = "0.3" +maybe-rayon = { version = "0.1.0", default-features = false } + +# Ensure we bench Halo2curves with full optimizations +halo2curves = { git = 'https://github.com/taikoxyz/halo2curves', branch = "pr-pse-exec-engine", features = ["multicore", "asm"]} + +[[bench]] +name = "msm" +harness = false diff --git a/constantine-rust/constantine-zal-halo2kzg/benches/msm.rs b/constantine-rust/constantine-zal-halo2kzg/benches/msm.rs new file mode 100644 index 00000000..d9133fb1 --- /dev/null +++ b/constantine-rust/constantine-zal-halo2kzg/benches/msm.rs @@ -0,0 +1,114 @@ +//! 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). + +//! To run this benchmark: +//! +//! cargo bench -- msm + +#[macro_use] +extern crate criterion; + +use constantine_zal_halo2kzg::CttEngine; +use criterion::{BenchmarkId, Criterion}; +use halo2curves::bn256::{Fr as Scalar, G1Affine as Point}; +use halo2curves::ff::Field; +use halo2curves::msm::best_multiexp; +use halo2curves::zal::MsmAccel; +use maybe_rayon::current_thread_index; +use maybe_rayon::prelude::{IntoParallelIterator, ParallelIterator}; +use rand_core::SeedableRng; +use rand_xorshift::XorShiftRng; +use std::time::SystemTime; + +const SAMPLE_SIZE: usize = 10; +const SIZES: [u8; 9] = [3, 8, 10, 12, 14, 16, 18, 20, 22]; +const SEED: [u8; 16] = [ + 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, +]; + +fn generate_coefficients_and_curvepoints(k: u8) -> (Vec, Vec) { + let n: u64 = { + assert!(k < 64); + 1 << k + }; + + println!("\n\nGenerating 2^{k} = {n} coefficients and curve points..",); + let timer = SystemTime::now(); + let coeffs = (0..n) + .into_par_iter() + .map_init( + || { + let mut thread_seed = SEED; + let uniq = current_thread_index().unwrap().to_ne_bytes(); + assert!(std::mem::size_of::() == 8); + for i in 0..uniq.len() { + thread_seed[i] += uniq[i]; + thread_seed[i + 8] += uniq[i]; + } + XorShiftRng::from_seed(thread_seed) + }, + |rng, _| Scalar::random(rng), + ) + .collect(); + let bases = (0..n) + .into_par_iter() + .map_init( + || { + let mut thread_seed = SEED; + let uniq = current_thread_index().unwrap().to_ne_bytes(); + assert!(std::mem::size_of::() == 8); + for i in 0..uniq.len() { + thread_seed[i] += uniq[i]; + thread_seed[i + 8] += uniq[i]; + } + XorShiftRng::from_seed(thread_seed) + }, + |rng, _| Point::random(rng), + ) + .collect(); + let end = timer.elapsed().unwrap(); + println!( + "Generating 2^{k} = {n} coefficients and curve points took: {} sec.\n\n", + end.as_secs() + ); + + (coeffs, bases) +} + +fn msm(c: &mut Criterion) { + let mut group = c.benchmark_group("msm"); + let max_k = *SIZES.iter().max().unwrap_or(&16); + let (coeffs, bases) = generate_coefficients_and_curvepoints(max_k); + + for k in SIZES { + group + .bench_function(BenchmarkId::new("halo2curves", k), |b| { + assert!(k < 64); + let n: usize = 1 << k; + b.iter(|| { + best_multiexp(&coeffs[..n], &bases[..n]); + }) + }) + .sample_size(SAMPLE_SIZE); + + let engine = CttEngine::new(num_cpus::get()); + group + .bench_function(BenchmarkId::new("constantine", k), |b| { + assert!(k < 64); + let n: usize = 1 << k; + b.iter(|| { + engine.msm(&coeffs[..n], &bases[..n]); + }) + }) + .sample_size(SAMPLE_SIZE); + drop(engine); // Explicitly drop engine out of timer measurement + } + group.finish(); +} + +criterion_group!(benches, msm); +criterion_main!(benches); diff --git a/constantine-rust/constantine-zal-halo2kzg/src/lib.rs b/constantine-rust/constantine-zal-halo2kzg/src/lib.rs index 0b6690f2..d68bdc77 100644 --- a/constantine-rust/constantine-zal-halo2kzg/src/lib.rs +++ b/constantine-rust/constantine-zal-halo2kzg/src/lib.rs @@ -6,13 +6,14 @@ //! * 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. +//! Implementation of the ZK Accel Layer using Constantine as a backend //! See https://github.com/privacy-scaling-explorations/halo2/issues/216 -use std::mem; use ::core::mem::MaybeUninit; use constantine_sys::*; use halo2curves::bn256; -use halo2curves::zal::{ZalEngine, MsmAccel}; +use halo2curves::zal::{MsmAccel, ZalEngine}; +use std::mem; pub struct CttEngine { ctx: *mut ctt_threadpool, @@ -21,8 +22,8 @@ pub struct CttEngine { impl CttEngine { #[inline(always)] pub fn new(num_threads: usize) -> CttEngine { - let ctx = unsafe{ ctt_threadpool_new(num_threads) }; - CttEngine{ctx} + let ctx = unsafe { ctt_threadpool_new(num_threads) }; + CttEngine { ctx } } } @@ -32,20 +33,19 @@ impl Drop for CttEngine { } } -impl ZalEngine for CttEngine{} +impl ZalEngine for CttEngine {} impl MsmAccel for CttEngine { fn msm(&self, coeffs: &[bn256::Fr], bases: &[bn256::G1Affine]) -> bn256::G1 { - assert_eq!(coeffs.len(), bases.len()); let mut result: MaybeUninit = MaybeUninit::uninit(); unsafe { ctt_bn254_snarks_g1_prj_multi_scalar_mul_fr_coefs_vartime_parallel( - self.ctx, - result.as_mut_ptr(), - coeffs.as_ptr() as *const bn254_snarks_fr, - bases.as_ptr() as *const bn254_snarks_g1_aff, - bases.len() + self.ctx, + result.as_mut_ptr(), + coeffs.as_ptr() as *const bn254_snarks_fr, + bases.as_ptr() as *const bn254_snarks_g1_aff, + bases.len(), ); mem::transmute::, bn256::G1>(result) } @@ -61,10 +61,10 @@ mod tests { use halo2curves::bn256; use halo2curves::ff::Field; - use halo2curves::group::{Curve, Group}; use halo2curves::group::prime::PrimeCurveAffine; - use halo2curves::zal::MsmAccel; + use halo2curves::group::{Curve, Group}; use halo2curves::msm::best_multiexp; + use halo2curves::zal::MsmAccel; #[test] fn t_threadpool() { @@ -105,5 +105,4 @@ mod tests { fn t_msm_zal() { run_msm_zal(3, 14); } - } From d4391176872041890ddcb39b57c5bbfce61abea7 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 2 Dec 2023 10:20:42 +0100 Subject: [PATCH 09/24] CI: add constantine-rust / ZAL to CI --- .github/workflows/ci.yml | 64 ++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ecd5f6d..cad8b27a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,42 +8,51 @@ jobs: max-parallel: 20 matrix: nim_version: [version-1-6] # [version-1-4, devel] + rust_toolchain: [stable] # [beta, nightly] target: - os: linux cpu: i386 TEST_LANG: c BACKEND: NO_ASM + SHELL: bash - os: linux cpu: i386 TEST_LANG: c BACKEND: ASM + SHELL: bash - os: linux cpu: amd64 TEST_LANG: c BACKEND: NO_ASM + SHELL: bash - os: linux cpu: amd64 TEST_LANG: c BACKEND: ASM + SHELL: bash - os: windows cpu: amd64 TEST_LANG: c BACKEND: NO_ASM + SHELL: msys2 {0} - os: windows cpu: amd64 TEST_LANG: c BACKEND: ASM + SHELL: msys2 {0} - os: macos cpu: amd64 TEST_LANG: c BACKEND: NO_ASM + SHELL: bash - os: macos cpu: amd64 TEST_LANG: c BACKEND: ASM + SHELL: bash include: - target: os: linux @@ -241,43 +250,66 @@ jobs: nim -v gcc -v - - name: Run Constantine tests (UNIX with Assembly) - if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM' - shell: bash + - name: Run Constantine as C library tests (with Assembly) + if: matrix.target.BACKEND == 'ASM' + shell: ${{ matrix.target.SHELL }} run: | cd constantine nimble make_lib --verbose nimble make_headers --verbose nimble test_lib --verbose + - name: Run Constantine as C library tests (NO Assembly) + if: matrix.target.BACKEND == 'NO_ASM' + shell: ${{ matrix.target.SHELL }} + run: | + cd constantine + CTT_ASM=0 nimble make_lib --verbose + nimble make_headers --verbose + nimble test_lib --verbose + + - name: Run Constantine as Rust library tests (with Assembly) + if: matrix.target.BACKEND == 'ASM' + shell: ${{ matrix.target.SHELL }} + run: | + cd constantine + rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} + cargo build --verbose + cargo test --verbose + - name: Run Constantine as Rust library tests (NO Assembly) + if: matrix.target.BACKEND == 'NO_ASM' + shell: ${{ matrix.target.SHELL }} + run: | + cd constantine + rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} + CTT_ASM=0 cargo build --verbose + CTT_ASM=0 cargo test --verbose + + - name: Run Constantine in-depth tests (with GMP, with Assembly) + if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM' + shell: msys2 {0} + run: | + cd constantine nimble test_parallel --verbose - - name: Run Constantine tests (UNIX no Assembly) + - name: Run Constantine in-depth tests (with GMP, no Assembly) if: runner.os != 'Windows' && matrix.target.BACKEND == 'NO_ASM' - shell: bash + shell: msys2 {0} run: | cd constantine - CTT_ASM=0 nimble make_lib --verbose - nimble make_headers --verbose - nimble test_lib --verbose CTT_ASM=0 nimble test_parallel --verbose - - name: Run Constantine tests (Windows with Assembly) + + - name: Run Constantine in-depth tests (no GMP, with Assembly) # So "test_bindings" uses C and can find GMP # but nim-gmp cannot find GMP on Windows CI if: runner.os == 'Windows' && matrix.target.BACKEND == 'ASM' shell: msys2 {0} run: | cd constantine - nimble make_lib --verbose - nimble make_headers --verbose - nimble test_lib --verbose nimble test_parallel_no_gmp --verbose - - name: Run Constantine tests (Windows no Assembly) + - name: Run Constantine in-depth tests (no GMP, no Assembly) # So "test_bindings" uses C and can find GMP # but nim-gmp cannot find GMP on Windows CI if: runner.os == 'Windows' && matrix.target.BACKEND == 'NO_ASM' shell: msys2 {0} run: | cd constantine - CTT_ASM=0 nimble make_lib --verbose - nimble make_headers --verbose - nimble test_lib --verbose CTT_ASM=0 nimble test_parallel_no_gmp --verbose From 2f23497aa6ef5f650314931092f73b0de3803777 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 2 Dec 2023 10:45:08 +0100 Subject: [PATCH 10/24] CI: can't use variables for shell --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cad8b27a..f37c8332 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,45 +14,37 @@ jobs: cpu: i386 TEST_LANG: c BACKEND: NO_ASM - SHELL: bash - os: linux cpu: i386 TEST_LANG: c BACKEND: ASM - SHELL: bash - os: linux cpu: amd64 TEST_LANG: c BACKEND: NO_ASM - SHELL: bash - os: linux cpu: amd64 TEST_LANG: c BACKEND: ASM - SHELL: bash - os: windows cpu: amd64 TEST_LANG: c BACKEND: NO_ASM - SHELL: msys2 {0} - os: windows cpu: amd64 TEST_LANG: c BACKEND: ASM - SHELL: msys2 {0} - os: macos cpu: amd64 TEST_LANG: c BACKEND: NO_ASM - SHELL: bash - os: macos cpu: amd64 TEST_LANG: c BACKEND: ASM - SHELL: bash include: - target: os: linux @@ -252,7 +244,7 @@ jobs: - name: Run Constantine as C library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' - shell: ${{ matrix.target.SHELL }} + shell: bash run: | cd constantine nimble make_lib --verbose @@ -260,7 +252,24 @@ jobs: nimble test_lib --verbose - name: Run Constantine as C library tests (NO Assembly) if: matrix.target.BACKEND == 'NO_ASM' - shell: ${{ matrix.target.SHELL }} + shell: bash + run: | + cd constantine + CTT_ASM=0 nimble make_lib --verbose + nimble make_headers --verbose + nimble test_lib --verbose + + - name: Run Constantine as C library tests (with Assembly) + if: matrix.target.BACKEND == 'ASM' + shell: bash + run: | + cd constantine + nimble make_lib --verbose + nimble make_headers --verbose + nimble test_lib --verbose + - name: Run Constantine as C library tests (no Assembly) + if: matrix.target.BACKEND == 'NO_ASM' + shell: bash run: | cd constantine CTT_ASM=0 nimble make_lib --verbose @@ -269,7 +278,7 @@ jobs: - name: Run Constantine as Rust library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' - shell: ${{ matrix.target.SHELL }} + shell: bash run: | cd constantine rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} @@ -277,27 +286,27 @@ jobs: cargo test --verbose - name: Run Constantine as Rust library tests (NO Assembly) if: matrix.target.BACKEND == 'NO_ASM' - shell: ${{ matrix.target.SHELL }} + shell: bash run: | cd constantine rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} CTT_ASM=0 cargo build --verbose CTT_ASM=0 cargo test --verbose - - name: Run Constantine in-depth tests (with GMP, with Assembly) + - name: Run Constantine in-depth tests (Unix - with GMP, with Assembly) if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM' - shell: msys2 {0} + shell: bash run: | cd constantine nimble test_parallel --verbose - - name: Run Constantine in-depth tests (with GMP, no Assembly) + - name: Run Constantine in-depth tests (Unix - with GMP, no Assembly) if: runner.os != 'Windows' && matrix.target.BACKEND == 'NO_ASM' - shell: msys2 {0} + shell: bash run: | cd constantine CTT_ASM=0 nimble test_parallel --verbose - - name: Run Constantine in-depth tests (no GMP, with Assembly) + - name: Run Constantine in-depth tests (Windows - no GMP, with Assembly) # So "test_bindings" uses C and can find GMP # but nim-gmp cannot find GMP on Windows CI if: runner.os == 'Windows' && matrix.target.BACKEND == 'ASM' @@ -305,7 +314,7 @@ jobs: run: | cd constantine nimble test_parallel_no_gmp --verbose - - name: Run Constantine in-depth tests (no GMP, no Assembly) + - name: Run Constantine in-depth tests (Windows - no GMP, no Assembly) # So "test_bindings" uses C and can find GMP # but nim-gmp cannot find GMP on Windows CI if: runner.os == 'Windows' && matrix.target.BACKEND == 'NO_ASM' From 23ee65245d11e038df39ffbc1af2da1b0e11c2d0 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 2 Dec 2023 12:44:55 +0100 Subject: [PATCH 11/24] CI: display rust version --- .github/workflows/ci.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f37c8332..cbbf9e57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -235,12 +235,19 @@ jobs: nimble refresh --verbose -y nimble install --verbose -y gmp jsony asynctools yaml@1.1.0 - - name: Print Nim & compiler versions + - name: Install Rust + shell: bash + run: rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} + + - name: Print Nim, Rust & compilers' versions shell: bash # gcc is an alias to Clang on MacOS run: | nim -v gcc -v + clang -v + llvm-config --version + rustup --version - name: Run Constantine as C library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' @@ -281,7 +288,6 @@ jobs: shell: bash run: | cd constantine - rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} cargo build --verbose cargo test --verbose - name: Run Constantine as Rust library tests (NO Assembly) From ddc06f819e6df68fef43f1f2e41f3a422db2ca6d Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 2 Dec 2023 20:35:32 +0100 Subject: [PATCH 12/24] Rust: force clang for building (Rust regression following #309 removal of rustBuild in .nimble) --- constantine-rust/constantine-sys/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/constantine-rust/constantine-sys/build.rs b/constantine-rust/constantine-sys/build.rs index 39c13716..a29b34d4 100644 --- a/constantine-rust/constantine-sys/build.rs +++ b/constantine-rust/constantine-sys/build.rs @@ -42,6 +42,7 @@ fn main() { println!("Building Constantine library ..."); Command::new("nimble") + .env("CC", "clang") .arg("make_lib_rust") .current_dir(root_dir) .stdout(Stdio::inherit()) From c31ab8477f236b6154e0b14c45f323d3e112b7b2 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 2 Dec 2023 20:38:33 +0100 Subject: [PATCH 13/24] LLVM (hence llvm-config) isn't installed in Github Actions CI --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbbf9e57..5ea48cb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -246,7 +246,6 @@ jobs: nim -v gcc -v clang -v - llvm-config --version rustup --version - name: Run Constantine as C library tests (with Assembly) From 877888f01e7ab313872cd005e5af13446c13947c Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 2 Dec 2023 20:48:13 +0100 Subject: [PATCH 14/24] documentation of compile options --- constantine.nimble | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/constantine.nimble b/constantine.nimble index 77e6f6ca..68435a1a 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -20,10 +20,14 @@ import std/[strformat, strutils, os] # Compile-time environment variables # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # -# - CTT_ASM=0 +# - CC="clang" or "nim c --cc:clang ..." +# Specify the compiler. +# Clang is recommended for fastest performance. +# +# - CTT_ASM=0 or "nim c -d:CTT_ASM=0 ..." # Disable assembly backend. Otherwise use ASM for supported CPUs and fallback to generic code otherwise. # -# - CTT_LTO=1 +# - CTT_LTO=1 or "nim c -d:lto ..." or "nim c -d:lto_incremental ..." # Enable LTO builds. # By default this is: # - Disabled for binaries @@ -40,23 +44,23 @@ import std/[strformat, strutils, os] # Developer, debug, profiling and metrics environment variables # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # -# - CTT_32 +# - CTT_32 or "nim c -d:CTT_32 ..." # Compile Constantine with 32-bit backend. Otherwise autodetect. # -# - CTT_DEBUG +# - "nim c -d:CTT_DEBUG ..." # Add preconditions, invariants and post-conditions checks. # This may leak the erroring data. Do not use with secrets. # -# - CTT_GENERATE_HEADERS -# - CTT_TEST_CURVES +# - "nim c -d:CTT_GENERATE_HEADERS ..." +# - "nim c -d:CTT_TEST_CURVES ..." # -# - CTT_THREADPOOL_ASSERTS -# - CTT_THREADPOOL_METRICS -# - CTT_THREADPOOL_PROFILE +# - "nim c -d:CTT_THREADPOOL_ASSERTS ..." +# - "nim c -d:CTT_THREADPOOL_METRICS ..." +# - "nim c -d:CTT_THREADPOOL_PROFILE ..." # -# - CTT_THREADPOOL_DEBUG -# - CTT_THREADPOOL_DEBUG_SPLIT -# - CTT_THREADPOOL_DEBUG_TERMINATION +# - "nim c -d:CTT_THREADPOOL_DEBUG" +# - "nim c -d:CTT_THREADPOOL_DEBUG_SPLIT" +# - "nim c -d:CTT_THREADPOOL_DEBUG_TERMINATION" proc getEnvVars(): tuple[useAsmIfAble, force32, forceLto, useLtoDefault: bool] = if existsEnv"CTT_ASM": From 330a65e498400b2dc8d5dca5ec89a1ab6bc3d4f8 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 2 Dec 2023 20:50:06 +0100 Subject: [PATCH 15/24] reduce rust verbosity --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ea48cb8..0ac20bfc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -287,16 +287,16 @@ jobs: shell: bash run: | cd constantine - cargo build --verbose - cargo test --verbose + cargo build + cargo test - name: Run Constantine as Rust library tests (NO Assembly) if: matrix.target.BACKEND == 'NO_ASM' shell: bash run: | cd constantine rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} - CTT_ASM=0 cargo build --verbose - CTT_ASM=0 cargo test --verbose + CTT_ASM=0 cargo build + CTT_ASM=0 cargo test - name: Run Constantine in-depth tests (Unix - with GMP, with Assembly) if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM' From 0c0bc25a8458cc9f71aed8171870939234ed66bb Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sun, 3 Dec 2023 00:08:51 +0100 Subject: [PATCH 16/24] cargo in CI, spray and pray --- .github/workflows/ci.yml | 7 +++-- constantine-rust/constantine-sys/build.rs | 31 ++++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ac20bfc..d938c752 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -287,16 +287,15 @@ jobs: shell: bash run: | cd constantine - cargo build - cargo test + rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} + cargo test -vv - name: Run Constantine as Rust library tests (NO Assembly) if: matrix.target.BACKEND == 'NO_ASM' shell: bash run: | cd constantine rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} - CTT_ASM=0 cargo build - CTT_ASM=0 cargo test + CTT_ASM=0 cargo test -vv - name: Run Constantine in-depth tests (Unix - with GMP, with Assembly) if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM' diff --git a/constantine-rust/constantine-sys/build.rs b/constantine-rust/constantine-sys/build.rs index a29b34d4..d9b31450 100644 --- a/constantine-rust/constantine-sys/build.rs +++ b/constantine-rust/constantine-sys/build.rs @@ -11,12 +11,27 @@ fn main() { .parent() .expect("constantine-rust is nested"); + println!("Building Constantine library ..."); + + Command::new("nimble") + .env("CC", "clang") + .arg("make_lib_rust") + .current_dir(root_dir) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .status() + .expect("failed to execute process"); + + println!("cargo:rustc-link-search=native={}", out_dir.display()); + println!("cargo:rustc-link-lib=static=constantine"); + // Avoid full recompilation println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=Cargo.toml"); + println!("cargo:rerun-if-changed=src"); println!( "cargo:rerun-if-changed={}", - cargo_dir.join(".cargo").join("config.toml").display() + root_dir.join(".cargo").join("config.toml").display() ); println!( "cargo:rerun-if-changed={}", @@ -38,18 +53,4 @@ fn main() { "cargo:rerun-if-changed={}", root_dir.join("constantine.nimble").display() ); - - println!("Building Constantine library ..."); - - Command::new("nimble") - .env("CC", "clang") - .arg("make_lib_rust") - .current_dir(root_dir) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .status() - .expect("failed to execute process"); - - println!("cargo:rustc-link-search=native={}", out_dir.display()); - println!("cargo:rustc-link-lib=static=constantine"); } From f7d4235b8532e840cb36bafb010f689c2a521ceb Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sun, 3 Dec 2023 00:11:13 +0100 Subject: [PATCH 17/24] don't update Rust twice --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d938c752..4d45afce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -287,14 +287,12 @@ jobs: shell: bash run: | cd constantine - rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} cargo test -vv - name: Run Constantine as Rust library tests (NO Assembly) if: matrix.target.BACKEND == 'NO_ASM' shell: bash run: | cd constantine - rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} CTT_ASM=0 cargo test -vv - name: Run Constantine in-depth tests (Unix - with GMP, with Assembly) From cce7236a3be57134cf72bffeb1ae93b19755752a Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sun, 3 Dec 2023 00:44:06 +0100 Subject: [PATCH 18/24] if using clang, Nim expects llvm-ar for static libraries archiver --- .github/workflows/ci.yml | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d45afce..33946e35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -158,10 +158,12 @@ jobs: run: | sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \ --no-install-recommends -yq \ - libgmp-dev + libgmp-dev \ + llvm - name: Install test dependencies (Linux i386) if: runner.os == 'Linux' && matrix.target.cpu == 'i386' + # We don't install LLVM as the Rust libraries that call Constantine are 64-bit only. run: | sudo dpkg --add-architecture i386 sudo apt-fast update -qq @@ -224,7 +226,7 @@ jobs: if: runner.os == 'Windows' shell: msys2 {0} run: | - pacman -S --needed --noconfirm mingw-w64-x86_64-gmp + pacman -S --needed --noconfirm mingw-w64-x86_64-gmp mingw-w64-x86_64-llvm nimble refresh --verbose -y nimble install --verbose -y gmp jsony asynctools yaml@1.1.0 @@ -241,12 +243,15 @@ jobs: - name: Print Nim, Rust & compilers' versions shell: bash - # gcc is an alias to Clang on MacOS + # gcc is an alias to Apple Clang on MacOS run: | nim -v gcc -v clang -v rustup --version + if [[ '${{ matrix.target.cpu }}' != 'i386' ]]; then + llvm-config --version + fi - name: Run Constantine as C library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' @@ -265,23 +270,6 @@ jobs: nimble make_headers --verbose nimble test_lib --verbose - - name: Run Constantine as C library tests (with Assembly) - if: matrix.target.BACKEND == 'ASM' - shell: bash - run: | - cd constantine - nimble make_lib --verbose - nimble make_headers --verbose - nimble test_lib --verbose - - name: Run Constantine as C library tests (no Assembly) - if: matrix.target.BACKEND == 'NO_ASM' - shell: bash - run: | - cd constantine - CTT_ASM=0 nimble make_lib --verbose - nimble make_headers --verbose - nimble test_lib --verbose - - name: Run Constantine as Rust library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' shell: bash From d7b866841af8e72869a3fab971eeed5c565a85c0 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sun, 3 Dec 2023 01:00:38 +0100 Subject: [PATCH 19/24] Expose full LLVM on MacOS, no Rust for i386, CPU features --- .github/workflows/ci.yml | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33946e35..8099b279 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -201,18 +201,20 @@ jobs: # Furthermore, Apple Clang can delete symbols when building a static library # in particular the hasAdxImpl bool for CPU runtime detection. - run: | - mkdir -p external/bin - cat << EOF > external/bin/clang - #!/bin/bash - exec $(brew --prefix llvm@15)/bin/clang "\$@" - EOF - cat << EOF > external/bin/clang++ - #!/bin/bash - exec $(brew --prefix llvm@15)/bin/clang++ "\$@" - EOF - chmod 755 external/bin/{clang,clang++} - echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH + + # run: | + # mkdir -p external/bin + # cat << EOF > external/bin/clang + # #!/bin/bash + # exec $(brew --prefix llvm@15)/bin/clang "\$@" + # EOF + # cat << EOF > external/bin/clang++ + # #!/bin/bash + # exec $(brew --prefix llvm@15)/bin/clang++ "\$@" + # EOF + # chmod 755 external/bin/{clang,clang++} + # echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH + run: echo "$(brew --prefix llvm@15)/bin" >> $GITHUB_PATH - name: Setup MSYS2 (Windows) if: runner.os == 'Windows' @@ -241,7 +243,7 @@ jobs: shell: bash run: rustup update ${{ matrix.rust_toolchain }} && rustup default ${{ matrix.rust_toolchain }} - - name: Print Nim, Rust & compilers' versions + - name: Print Nim, Rust, LLVM versions and CPU specs. shell: bash # gcc is an alias to Apple Clang on MacOS run: | @@ -252,6 +254,9 @@ jobs: if [[ '${{ matrix.target.cpu }}' != 'i386' ]]; then llvm-config --version fi + if [[ '${{ runner.os }}' != 'Windows' ]]; then + cat /proc/cpuinfo + fi - name: Run Constantine as C library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' @@ -271,17 +276,17 @@ jobs: nimble test_lib --verbose - name: Run Constantine as Rust library tests (with Assembly) - if: matrix.target.BACKEND == 'ASM' + if: matrix.target.BACKEND == 'ASM' && matrix.target.cpu != 'i386' shell: bash run: | cd constantine - cargo test -vv + cargo test - name: Run Constantine as Rust library tests (NO Assembly) - if: matrix.target.BACKEND == 'NO_ASM' + if: matrix.target.BACKEND == 'NO_ASM' && matrix.target.cpu != 'i386' shell: bash run: | cd constantine - CTT_ASM=0 cargo test -vv + CTT_ASM=0 cargo test - name: Run Constantine in-depth tests (Unix - with GMP, with Assembly) if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM' From 7563a21d7138937c4aefeab9e855e6e498c55e0b Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sun, 3 Dec 2023 01:14:21 +0100 Subject: [PATCH 20/24] fix HW info --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8099b279..8cd25a4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -251,12 +251,17 @@ jobs: gcc -v clang -v rustup --version - if [[ '${{ matrix.target.cpu }}' != 'i386' ]]; then + if [[ '${{ matrix.target.cpu }}' != 'i386' && '${{ runner.os }}' != 'Windows' ]]; then llvm-config --version fi - if [[ '${{ runner.os }}' != 'Windows' ]]; then + if [[ '${{ runner.os }}' == 'Linux' ]]; then cat /proc/cpuinfo fi + if [[ '${{ runner.os }}' == 'macOS' ]]; then + sysctl -a | grep machdep.cpu + sysctl -a | grep hw | grep cpu + sysctl -a | grep hw.optional + fi - name: Run Constantine as C library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' From 143fd8ce30a734207c35574455d7a52ee270604f Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sun, 3 Dec 2023 01:24:46 +0100 Subject: [PATCH 21/24] the light at the end of the CI tunnel --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cd25a4a..ad07b943 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -263,22 +263,42 @@ jobs: sysctl -a | grep hw.optional fi - - name: Run Constantine as C library tests (with Assembly) - if: matrix.target.BACKEND == 'ASM' + - name: Run Constantine as C library tests (UNIX with Assembly) + if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM' shell: bash run: | cd constantine nimble make_lib --verbose nimble make_headers --verbose nimble test_lib --verbose - - name: Run Constantine as C library tests (NO Assembly) - if: matrix.target.BACKEND == 'NO_ASM' + - name: Run Constantine as C library tests (UNIX no Assembly) + if: runner.os != 'Windows' && matrix.target.BACKEND == 'NO_ASM' shell: bash run: | cd constantine CTT_ASM=0 nimble make_lib --verbose nimble make_headers --verbose nimble test_lib --verbose + - name: Run Constantine as C library tests (Windows with Assembly) + # So "test_bindings" uses C and can find GMP + # but nim-gmp cannot find GMP on Windows CI + if: runner.os == 'Windows' && matrix.target.BACKEND == 'ASM' + shell: msys2 {0} + run: | + cd constantine + nimble make_lib --verbose + nimble make_headers --verbose + nimble test_lib --verbose + - name: Run Constantine as C library tests (Windows no Assembly) + # So "test_bindings" uses C and can find GMP + # but nim-gmp cannot find GMP on Windows CI + if: runner.os == 'Windows' && matrix.target.BACKEND == 'NO_ASM' + shell: msys2 {0} + run: | + cd constantine + CTT_ASM=0 nimble make_lib --verbose + nimble make_headers --verbose + nimble test_lib --verbose - name: Run Constantine as Rust library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' && matrix.target.cpu != 'i386' From 9d5e6213b3ce964d4caed2843cc675643197906f Mon Sep 17 00:00:00 2001 From: mMay Date: Sun, 3 Dec 2023 23:45:54 +0100 Subject: [PATCH 22/24] ensure autoloading kernel32.dll threading API --- .gitignore | 1 + bindings/lib_autoload.nim | 48 ++++++++++++++++++++ bindings/lib_constantine.nim | 5 +- constantine-rust/constantine-sys/build.rs | 10 +++- constantine.nimble | 10 ++++ constantine/platforms/loadtime_functions.nim | 2 +- constantine/threadpool/dll_autoload.nim | 24 ++++++++++ constantine/threadpool/threadpool.nim | 8 ++-- include/constantine.h | 5 ++ tests/c_api/t_threadpool.c | 30 ++++++++++++ 10 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 bindings/lib_autoload.nim create mode 100644 constantine/threadpool/dll_autoload.nim create mode 100644 tests/c_api/t_threadpool.c diff --git a/.gitignore b/.gitignore index 1c2f5bb6..62bcb2b7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ build/ *.so.* *.dylib *.a +*.lib *.la *.dll *.exe diff --git a/bindings/lib_autoload.nim b/bindings/lib_autoload.nim new file mode 100644 index 00000000..1f822d22 --- /dev/null +++ b/bindings/lib_autoload.nim @@ -0,0 +1,48 @@ +# 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. + +import ../constantine/platforms/loadtime_functions + +# When Constantine is built as a library, we want to minimize friction of using it. +# Hence we want to users to be able to directly use it without special ceremony. +# +# This is possible for dynamic libraries if --noMain isn't used. +# +# https://github.com/nim-lang/Nim/blob/v2.0.0/compiler/cgen.nim#L1572-L1583 +# https://github.com/nim-lang/Nim/blob/v2.0.0/lib/nimbase.h#L513 +# +# The function DllMain is autoloaded on Windows +# Functions tagged __attribute__((constructor)) are autoloaded on UNIX OSes +# +# Alas, Nim doesn't provide such facilities for static libraries +# so we provide our own {.loadTime.} macro for autoloading: +# - any proc +# - on any OS +# - whether using a dynamic or static library +# +# We use them for runtime CPU features detection. +# +# And on Windows as functions in DLLs (kernel APIs for the threadpool for example) are loaded +# as global variables + +when defined(windows) and (appType == "lib" or appType == "staticlib"): + proc ctt_init_NimMain() {.importc, cdecl.} + ## Setup Nim globals, including loading library dependencies on Windows + ## We assume that Constantine was compiled with --nimMainPrefix:ctt_init_ + + proc ctt_autoload_NimMain() {.load_time.} = + ## Autosetup Constantine globals on library load. + ## This must be referenced from an another module + ## to not be optimized away by the static linker + ctt_init_NimMain() + + proc ctt_autoloader_addr*(): pointer = + ## This returns an runtime reference to the autoloader + ## so that it cannot be optimized away. + ## Compare it with "nil" + cast[pointer](ctt_autoload_NimMain) \ No newline at end of file diff --git a/bindings/lib_constantine.nim b/bindings/lib_constantine.nim index c08e7d3b..c9b9df6d 100644 --- a/bindings/lib_constantine.nim +++ b/bindings/lib_constantine.nim @@ -19,4 +19,7 @@ import ./lib_hashes, ./lib_curves, # Protocols - ../constantine/ethereum_bls_signatures \ No newline at end of file + ../constantine/ethereum_bls_signatures, + + # Ensure globals like proc from kernel32.dll are populated at library load time + ./lib_autoload diff --git a/constantine-rust/constantine-sys/build.rs b/constantine-rust/constantine-sys/build.rs index d9b31450..bf723871 100644 --- a/constantine-rust/constantine-sys/build.rs +++ b/constantine-rust/constantine-sys/build.rs @@ -23,7 +23,15 @@ fn main() { .expect("failed to execute process"); println!("cargo:rustc-link-search=native={}", out_dir.display()); - println!("cargo:rustc-link-lib=static=constantine"); + + // On windows stable channel (msvc) expects constantine.lib + // while stable-gnu channel (gcc) expects libconstantine.a + // hence we use +verbatim + #[cfg(target_family = "windows")] + println!("cargo:rustc-link-lib=static:+verbatim=constantine.lib"); + + #[cfg(target_family = "unix")] + println!("cargo:rustc-link-lib=static:+verbatim=libconstantine.a"); // Avoid full recompilation println!("cargo:rerun-if-changed=build.rs"); diff --git a/constantine.nimble b/constantine.nimble index 68435a1a..c5fa8e22 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -184,9 +184,18 @@ proc releaseBuildOptions(buildMode = bmBinary): string = elif forceLto: ltoFlags else: "" + let osSpecific = + # Remove the auto __chkstk, which are: 1. slower, 2. not supported on Rust "stable-gnu" channel. + if defined(windows): " --passC:-mno-stack-arg-probe " + else: "" + + let threadLocalStorage = " --tlsEmulation=off " + compiler & envASM & env32 & ltoOptions & + osSpecific & + threadLocalStorage & compilerFlags() proc genDynamicLib(outdir, nimcache: string) = @@ -292,6 +301,7 @@ task test_lib, "Test C library": exec "mkdir -p build/test_lib" testLib("examples_c", "t_libctt_bls12_381", useGMP = true) testLib("examples_c", "ethereum_bls_signatures", useGMP = false) + testLib("tests"/"c_api", "t_threadpool", useGMP = false) # Test config # ---------------------------------------------------------------- diff --git a/constantine/platforms/loadtime_functions.nim b/constantine/platforms/loadtime_functions.nim index 39175afd..4d32d12e 100644 --- a/constantine/platforms/loadtime_functions.nim +++ b/constantine/platforms/loadtime_functions.nim @@ -36,7 +36,7 @@ macro loadTime*(procAst: untyped): untyped = result = procAst elif defined(vcc): - warning "CPU feature autodetection at Constantine load time has not been tested with MSVC" + warning "Constantine autoloaded functions have not been tested with MSVC" template msvcInitSection(procDef: untyped): untyped = let procName = astToStr(def) diff --git a/constantine/threadpool/dll_autoload.nim b/constantine/threadpool/dll_autoload.nim new file mode 100644 index 00000000..b10ade0d --- /dev/null +++ b/constantine/threadpool/dll_autoload.nim @@ -0,0 +1,24 @@ +# 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. + +# To ensure that __attribute__((constructor)) procs are not +# removed because they are unaccessible, we force symbol reference +when defined(windows) and (appType == "lib" or appType == "staticlib"): + import ../../bindings/lib_autoload + + proc check_lib_dependency_loader*() = + ## This prevents the linker from deleting our constructor function + ## that loads Windows kernel, synchronization and threading related functions. + ## We only need to have any symbol in the translation unit being used. + doAssert ctt_autoloader_addr() != nil +else: + template check_lib_dependency_loader*() = + ## This prevents the linker from deleting our constructor function + ## that loads Windows kernel, synchronization and threading related functions. + ## We only need to have any symbol in the translation unit being used. + discard \ No newline at end of file diff --git a/constantine/threadpool/threadpool.nim b/constantine/threadpool/threadpool.nim index f53b70f7..c97b62c5 100644 --- a/constantine/threadpool/threadpool.nim +++ b/constantine/threadpool/threadpool.nim @@ -23,7 +23,7 @@ import ./parallel_offloading, ../platforms/[allocs, bithacks] -import ../zoo_exports +import ../zoo_exports, dll_autoload export # flowvars @@ -953,18 +953,20 @@ proc new*(T: type Threadpool, numThreads = countProcessors()): T {.raises: [Reso type TpObj = typeof(default(Threadpool)[]) # due to C import, we need a dynamic sizeof let tp = allocHeapUncheckedAlignedPtr(Threadpool, sizeof(TpObj), alignment = 64) - tp.barrier.init(numThreads.uint32) tp.globalBackoff.initialize() tp.numThreads = numThreads.int32 tp.workerQueues = allocHeapArrayAligned(Taskqueue, numThreads, alignment = 64) tp.workers = allocHeapArrayAligned(Thread[(Threadpool, WorkerID)], numThreads, alignment = 64) tp.workerSignals = allocHeapArrayAligned(Signal, numThreads, alignment = 64) - # Setup master thread workerContext.id = 0 workerContext.threadpool = tp + # We use kernel functions for threading and synchronization next, + # ensure they are loaded and static constructor procs are not removed by the linker. + check_lib_dependency_loader() + # Start worker threads for i in 1 ..< numThreads: createThread(tp.workers[i], workerEntryFn, (tp, WorkerID(i))) diff --git a/include/constantine.h b/include/constantine.h index 9633e361..8ad2b536 100644 --- a/include/constantine.h +++ b/include/constantine.h @@ -9,6 +9,11 @@ #ifndef __CTT_H_CONSTANTINE__ #define __CTT_H_CONSTANTINE__ +// Core functions +#include "constantine/core/datatypes.h" +#include "constantine/core/serialization.h" +#include "constantine/core/threadpool.h" + // Hash functions #include "constantine/hashes/sha256.h" diff --git a/tests/c_api/t_threadpool.c b/tests/c_api/t_threadpool.c new file mode 100644 index 00000000..b8fac9e4 --- /dev/null +++ b/tests/c_api/t_threadpool.c @@ -0,0 +1,30 @@ +/** 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. + */ + +// This is a test to ensure the C API for the threadpool works on all platforms +// and: +// if special options like -d:tlsEmulation:off are needed +// if NimMain is done implicitly at load time. + +#include +#include + +void ctt_init_NimMain(void); + +int main(){ + printf("Constantine: Testing the C API for the threadpool.\n"); + // ctt_init_NimMain(); + + struct ctt_threadpool* tp = ctt_threadpool_new(4); + printf("Constantine: Threadpool init successful.\n"); + ctt_threadpool_shutdown(tp); + printf("Constantine: Threadpool shutdown successful.\n"); + + return 0; +} \ No newline at end of file From 0dfe2e4e3242639a10606ad21b2f7cc4d7e19e39 Mon Sep 17 00:00:00 2001 From: mMay Date: Mon, 4 Dec 2023 01:07:02 +0100 Subject: [PATCH 23/24] Keep stack guard pages on Windows --- constantine.nimble | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/constantine.nimble b/constantine.nimble index c5fa8e22..b2286ad5 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -185,8 +185,10 @@ proc releaseBuildOptions(buildMode = bmBinary): string = else: "" let osSpecific = - # Remove the auto __chkstk, which are: 1. slower, 2. not supported on Rust "stable-gnu" channel. - if defined(windows): " --passC:-mno-stack-arg-probe " + if defined(windows): "" # " --passC:-mno-stack-arg-probe " + # Remove the auto __chkstk, which are: 1. slower, 2. not supported on Rust "stable-gnu" channel. + # However functions that uses a large stack like `sum_reduce_vartime` become incorrect. + # Hence deactivated by default. else: "" let threadLocalStorage = " --tlsEmulation=off " From 231ccc7acea7975267a49e88e50035b137539b61 Mon Sep 17 00:00:00 2001 From: mMay Date: Mon, 4 Dec 2023 12:19:06 +0100 Subject: [PATCH 24/24] MacOS CI: some agents don't support ADX instructions and SIGILL --- .github/workflows/ci.yml | 6 ++++-- constantine-rust/constantine-zal-halo2kzg/Cargo.toml | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad07b943..dde695d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -303,15 +303,17 @@ jobs: - name: Run Constantine as Rust library tests (with Assembly) if: matrix.target.BACKEND == 'ASM' && matrix.target.cpu != 'i386' shell: bash + # We need to deactivate the assembly (used by default for benches) run: | cd constantine - cargo test + cargo test --no-default-features halo2curves --features halo2curves/multicore - name: Run Constantine as Rust library tests (NO Assembly) if: matrix.target.BACKEND == 'NO_ASM' && matrix.target.cpu != 'i386' shell: bash + # We need to deactivate the assembly (used by default for benches) run: | cd constantine - CTT_ASM=0 cargo test + CTT_ASM=0 cargo test --no-default-features halo2curves --features halo2curves/multicore - name: Run Constantine in-depth tests (Unix - with GMP, with Assembly) if: runner.os != 'Windows' && matrix.target.BACKEND == 'ASM' diff --git a/constantine-rust/constantine-zal-halo2kzg/Cargo.toml b/constantine-rust/constantine-zal-halo2kzg/Cargo.toml index f4e83720..c041c0bc 100644 --- a/constantine-rust/constantine-zal-halo2kzg/Cargo.toml +++ b/constantine-rust/constantine-zal-halo2kzg/Cargo.toml @@ -22,6 +22,7 @@ rand_xorshift = "0.3" maybe-rayon = { version = "0.1.0", default-features = false } # Ensure we bench Halo2curves with full optimizations +# In CI "asm" needs to be disabled as some agents don't support ADX. halo2curves = { git = 'https://github.com/taikoxyz/halo2curves', branch = "pr-pse-exec-engine", features = ["multicore", "asm"]} [[bench]]