rm Miracl and remaining i386 (32-bit) build support (#2250)

This commit is contained in:
tersec 2024-05-30 19:08:09 +00:00 committed by GitHub
parent 0f430c70fd
commit 828fd63348
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 119 additions and 254 deletions

View File

@ -36,9 +36,6 @@ jobs:
- os: linux - os: linux
cpu: amd64 cpu: amd64
evmc: evmc evmc: evmc
#- os: linux
# cpu: i386
# evmc: evmc
- os: macos - os: macos
cpu: amd64 cpu: amd64
evmc: evmc evmc: evmc
@ -48,9 +45,6 @@ jobs:
- os: linux - os: linux
cpu: amd64 cpu: amd64
evmc: nimvm evmc: nimvm
#- os: linux
# cpu: i386
# evmc: nimvm
- os: windows - os: windows
cpu: amd64 cpu: amd64
evmc: nimvm evmc: nimvm
@ -93,12 +87,6 @@ jobs:
echo "GOARCH=${GOARCH}" >> $GITHUB_ENV echo "GOARCH=${GOARCH}" >> $GITHUB_ENV
echo "USE_MIRACL=${USE_MIRACL}" >> $GITHUB_ENV echo "USE_MIRACL=${USE_MIRACL}" >> $GITHUB_ENV
# libminiupnp / natpmp
if [[ '${{ runner.os }}' == 'Linux' && '${{ matrix.target.cpu }}' == 'i386' ]]; then
export CFLAGS="${CFLAGS} -m32 -mno-adx"
echo "CFLAGS=${CFLAGS}" >> $GITHUB_ENV
fi
ncpu='' ncpu=''
case '${{ runner.os }}' in case '${{ runner.os }}' in
'Linux') 'Linux')
@ -120,26 +108,6 @@ jobs:
echo "ENABLE_EVMC=0" >> $GITHUB_ENV echo "ENABLE_EVMC=0" >> $GITHUB_ENV
fi fi
- name: Install build dependencies (Linux i386)
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
run: |
sudo dpkg --add-architecture i386
sudo apt-fast update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq gcc-multilib g++-multilib \
libz-dev:i386 libbz2-dev:i386 libssl-dev:i386 libpcre3-dev:i386
mkdir -p external/bin
cat << EOF > external/bin/gcc
#!/bin/bash
exec $(which gcc) -m32 "\$@"
EOF
cat << EOF > external/bin/g++
#!/bin/bash
exec $(which g++) -m32 "\$@"
EOF
chmod 755 external/bin/gcc external/bin/g++
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
- name: Install build dependencies (Macos) - name: Install build dependencies (Macos)
# Some home brew modules were reported missing # Some home brew modules were reported missing
if: runner.os == 'Macos' if: runner.os == 'Macos'
@ -155,13 +123,6 @@ jobs:
path: rocks-db-cache-${{ matrix.target.cpu }} path: rocks-db-cache-${{ matrix.target.cpu }}
key: 'rocksdb-v2-${{ matrix.target.os }}-${{ matrix.target.cpu }}' key: 'rocksdb-v2-${{ matrix.target.os }}-${{ matrix.target.cpu }}'
- name: Build and install rocksdb (Linux i386)
# no librocksdb-dev:i386
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
run: |
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_rocksdb.sh
bash build_rocksdb.sh rocks-db-cache-${{ matrix.target.cpu }}
- name: Install rocksdb (Linux amd64) - name: Install rocksdb (Linux amd64)
# mysterious illegal instruction error if we build our own librocksdb # mysterious illegal instruction error if we build our own librocksdb
if: runner.os == 'Linux' && matrix.target.cpu == 'amd64' if: runner.os == 'Linux' && matrix.target.cpu == 'amd64'
@ -282,17 +243,12 @@ jobs:
env CC=gcc make ${DEFAULT_MAKE_FLAGS} env CC=gcc make ${DEFAULT_MAKE_FLAGS}
build/nimbus --help build/nimbus --help
# CC, GOARCH, and CGO_ENABLED are needed to select correct compiler 32/64 bit # CC, GOARCH, and CGO_ENABLED are needed to select correct compiler 32/64 bit
if [[ '${{ matrix.target.cpu }}' == 'i386' ]]; then # pushd vendor/nimbus-eth2
# hide CI failures # env NIMBUSEL_BINARY=../../build/nimbus NIMBUSEL_GENESIS=scripts/nimbusel_genesis.json \
env CC=gcc GOARCH=${GOARCH} CXX=g++ CGO_ENABLED=1 make ${DEFAULT_MAKE_FLAGS} test || true # ./scripts/launch_local_testnet.sh --nodes=3 --stop-at-epoch=7 \
else # --disable-htop --reuse-binaries --run-nimbus-el --dl-eth2 --verbose --kill-old-processes
# pushd vendor/nimbus-eth2 # popd
# env NIMBUSEL_BINARY=../../build/nimbus NIMBUSEL_GENESIS=scripts/nimbusel_genesis.json \ env CC=gcc GOARCH=${GOARCH} CXX=g++ CGO_ENABLED=1 make ${DEFAULT_MAKE_FLAGS} test
# ./scripts/launch_local_testnet.sh --nodes=3 --stop-at-epoch=7 \
# --disable-htop --reuse-binaries --run-nimbus-el --dl-eth2 --verbose --kill-old-processes
# popd
env CC=gcc GOARCH=${GOARCH} CXX=g++ CGO_ENABLED=1 make ${DEFAULT_MAKE_FLAGS} test
fi
- name: Run nimbus-eth1 tests (Macos) - name: Run nimbus-eth1 tests (Macos)
if: runner.os == 'Macos' if: runner.os == 'Macos'

View File

@ -158,9 +158,6 @@ all: | $(TOOLS) nimbus
# must be included after the default target # must be included after the default target
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk -include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk
# default: use blst
USE_MIRACL := 0
# default: use nim native evm # default: use nim native evm
ENABLE_EVMC := 0 ENABLE_EVMC := 0
@ -182,10 +179,6 @@ ifneq ($(USE_LIBBACKTRACE), 0)
deps: | libbacktrace deps: | libbacktrace
endif endif
ifneq ($(USE_MIRACL), 0)
NIM_PARAMS += -d:BLS_FORCE_BACKEND=miracl
endif
ifneq ($(ENABLE_EVMC), 0) ifneq ($(ENABLE_EVMC), 0)
NIM_PARAMS += -d:evmc_enabled NIM_PARAMS += -d:evmc_enabled
T8N_PARAMS := -d:chronicles_enabled=off T8N_PARAMS := -d:chronicles_enabled=off

View File

@ -152,11 +152,6 @@ switch("warning", "ObservableStores:off")
# Too many false positives for "Warning: method has lock level <unknown>, but another method has 0 [LockLevel]" # Too many false positives for "Warning: method has lock level <unknown>, but another method has 0 [LockLevel]"
switch("warning", "LockLevel:off") switch("warning", "LockLevel:off")
if defined(windows) and defined(i386):
# avoid undefined reference to 'sqrx_mont_384x' when compiling in 32 bit mode
# without actually using __BLST_PORTABLE__ or __BLST_NO_ASM__
switch("define", "BLS_FORCE_BACKEND:miracl")
# nim-kzg shipping their own blst, nimbus-eth1 too. # nim-kzg shipping their own blst, nimbus-eth1 too.
# disable nim-kzg's blst # disable nim-kzg's blst
switch("define", "kzgExternalBlst") switch("define", "kzgExternalBlst")

View File

@ -1,5 +1,5 @@
# Nimbus # Nimbus
# Copyright (c) 2020-2023 Status Research & Development GmbH # Copyright (c) 2020-2024 Status Research & Development GmbH
# Licensed under either of # Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0) # http://www.apache.org/licenses/LICENSE-2.0)
@ -10,189 +10,128 @@
import blscurve/bls_backend, stint import blscurve/bls_backend, stint
when BLS_BACKEND == Miracl: import blscurve/blst/[blst_lowlevel]
import blscurve/miracl/[common, milagro, hash_to_curve, miracl_min_pubkey_sig_core]
import map_to_curve_g1
export common
export miracl_min_pubkey_sig_core.subgroupCheck
type type
BLS_G1* = ECP_BLS12381 BLS_G1* = blst_p1
BLS_G2* = ECP2_BLS12381 BLS_G2* = blst_p2
BLS_FP* = BIG_384 BLS_FP* = blst_fp
BLS_FP2* = FP2_BLS12381 BLS_FP2* = blst_fp2
BLS_SCALAR* = BIG_384 BLS_SCALAR* = blst_scalar
BLS_FE* = FP_BLS12381 BLS_FE* = blst_fp
BLS_FE2* = FP2_BLS12381 BLS_FE2* = blst_fp2
BLS_ACC* = FP12_BLS12381 BLS_ACC* = blst_fp12
BLS_G1P* = BLS_G1 BLS_G1P* = blst_p1_affine
BLS_G2P* = BLS_G2 BLS_G2P* = blst_p2_affine
func pack(g: var BLS_G1, x, y: BLS_FP): bool {.inline.} = func fromBytes*(ret: var BLS_SCALAR, raw: openArray[byte]): bool =
discard ECP_BLS12381_set(g.addr, x, y) const L = 32
let xx = x.nres if raw.len < L:
let yy = y.nres return false
isOnCurve(xx, yy) let pa = cast[ptr array[L, byte]](raw[0].unsafeAddr)
blst_scalar_from_bendian(ret, pa[])
true
func unpack(g: BLS_G1, x, y: var BLS_FP): bool {.inline.} = func fromBytes(ret: var BLS_FP, raw: openArray[byte]): bool =
discard g.get(x, y) const L = 48
true if raw.len < L:
return false
let pa = cast[ptr array[L, byte]](raw[0].unsafeAddr)
blst_fp_from_bendian(ret, pa[])
true
func pack(g: var BLS_G2, x0, x1, y0, y1: BLS_FP): bool = func toBytes(fp: BLS_FP, output: var openArray[byte]): bool =
var x, y: BLS_FP2 const L = 48
x.fromBigs(x0, x1) if output.len < L:
y.fromBigs(y0, y1) return false
discard ECP2_BLS12381_set(g.addr, x.addr, y.addr) let pa = cast[ptr array[L, byte]](output[0].unsafeAddr)
isOnCurve(x, y) blst_bendian_from_fp(pa[], fp)
true
func unpack(g: BLS_G2, x0, x1, y0, y1: var BLS_FP): bool = func pack(g: var BLS_G1, x, y: BLS_FP): bool =
var x, y: BLS_FP2 let src = blst_p1_affine(x: x, y: y)
result = g.get(x, y) <= 0.cint blst_p1_from_affine(g, src)
FP_BLS12381_redc(x0, addr x.a) blst_p1_on_curve(g).int == 1
FP_BLS12381_redc(x1, addr x.b)
FP_BLS12381_redc(y0, addr y.a)
FP_BLS12381_redc(y1, addr y.b)
func mapFPToG1*(fp: BLS_FE): BLS_G1 {.inline.} = func unpack(g: BLS_G1, x, y: var BLS_FP): bool =
mapToCurveG1(fp) var dst: blst_p1_affine
blst_p1_to_affine(dst, g)
x = dst.x
y = dst.y
true
func mapFPToG2*(fp: BLS_FE2): BLS_G2 {.inline.} = func pack(g: var BLS_G2, x0, x1, y0, y1: BLS_FP): bool =
result = mapToCurveG2(fp) let src = blst_p2_affine(x: blst_fp2(fp: [x0, x1]), y: blst_fp2(fp: [y0, y1]))
result.clearCofactor() blst_p2_from_affine(g, src)
blst_p2_on_curve(g).int == 1
func millerLoop*(g1: BLS_G1, g2: BLS_G2): BLS_ACC {.inline.} = func unpack(g: BLS_G2, x0, x1, y0, y1: var BLS_FP): bool =
PAIR_BLS12381_ate(result.addr, g2.unsafeAddr, g1.unsafeAddr) var dst: blst_p2_affine
blst_p2_to_affine(dst, g)
x0 = dst.x.fp[0]
x1 = dst.x.fp[1]
y0 = dst.y.fp[0]
y1 = dst.y.fp[1]
true
proc mul*(a: var BLS_ACC, b: BLS_ACC) {.inline.} = func nbits(s: BLS_SCALAR): uint =
FP12_BLS12381_mul(a.addr, b.unsafeAddr) var k = sizeof(s.l) - 1
while k >= 0 and s.l[k] == 0: dec k
if k < 0: return 0
var
bts = k shl 3
c = s.l[k]
func check*(x: BLS_ACC): bool {.inline.} = while c != 0:
PAIR_BLS12381_fexp(x.unsafeAddr) c = c shr 1
FP12_BLS12381_isunity(x.unsafeAddr).int == 1 inc bts
else: result = bts.uint
import blscurve/blst/[blst_lowlevel]
type func add*(a: var BLS_G1, b: BLS_G1) {.inline.} =
BLS_G1* = blst_p1 blst_p1_add_or_double(a, a, b)
BLS_G2* = blst_p2
BLS_FP* = blst_fp
BLS_FP2* = blst_fp2
BLS_SCALAR* = blst_scalar
BLS_FE* = blst_fp
BLS_FE2* = blst_fp2
BLS_ACC* = blst_fp12
BLS_G1P* = blst_p1_affine
BLS_G2P* = blst_p2_affine
func fromBytes*(ret: var BLS_SCALAR, raw: openArray[byte]): bool = func mul*(a: var BLS_G1, b: BLS_SCALAR) {.inline.} =
const L = 32 blst_p1_mult(a, a, b, b.nbits)
if raw.len < L:
return false
let pa = cast[ptr array[L, byte]](raw[0].unsafeAddr)
blst_scalar_from_bendian(ret, pa[])
true
func fromBytes(ret: var BLS_FP, raw: openArray[byte]): bool = func add*(a: var BLS_G2, b: BLS_G2) {.inline.} =
const L = 48 blst_p2_add_or_double(a, a, b)
if raw.len < L:
return false
let pa = cast[ptr array[L, byte]](raw[0].unsafeAddr)
blst_fp_from_bendian(ret, pa[])
true
func toBytes(fp: BLS_FP, output: var openArray[byte]): bool = func mul*(a: var BLS_G2, b: BLS_SCALAR) {.inline.} =
const L = 48 blst_p2_mult(a, a, b, b.nbits)
if output.len < L:
return false
let pa = cast[ptr array[L, byte]](output[0].unsafeAddr)
blst_bendian_from_fp(pa[], fp)
true
func pack(g: var BLS_G1, x, y: BLS_FP): bool = func mapFPToG1*(fp: BLS_FE): BLS_G1 {.inline.} =
let src = blst_p1_affine(x: x, y: y) let z: ptr blst_fp = nil
blst_p1_from_affine(g, src) blst_map_to_g1(result, fp, z[])
blst_p1_on_curve(g).int == 1
func unpack(g: BLS_G1, x, y: var BLS_FP): bool = func mapFPToG2*(fp: BLS_FE2): BLS_G2 {.inline.} =
var dst: blst_p1_affine let z: ptr blst_fp2 = nil
blst_p1_to_affine(dst, g) blst_map_to_g2(result, fp, z[])
x = dst.x
y = dst.y
true
func pack(g: var BLS_G2, x0, x1, y0, y1: BLS_FP): bool = func pack(g: var BLS_G1P, x, y: BLS_FP): bool =
let src = blst_p2_affine(x: blst_fp2(fp: [x0, x1]), y: blst_fp2(fp: [y0, y1])) g = blst_p1_affine(x: x, y: y)
blst_p2_from_affine(g, src) blst_p1_affine_on_curve(g).int == 1
blst_p2_on_curve(g).int == 1
func unpack(g: BLS_G2, x0, x1, y0, y1: var BLS_FP): bool = func pack(g: var BLS_G2P, x0, x1, y0, y1: BLS_FP): bool =
var dst: blst_p2_affine g = blst_p2_affine(x: blst_fp2(fp: [x0, x1]), y: blst_fp2(fp: [y0, y1]))
blst_p2_to_affine(dst, g) blst_p2_affine_on_curve(g).int == 1
x0 = dst.x.fp[0]
x1 = dst.x.fp[1]
y0 = dst.y.fp[0]
y1 = dst.y.fp[1]
true
func nbits(s: BLS_SCALAR): uint = func subgroupCheck*(P: BLS_G1P): bool {.inline.} =
var k = sizeof(s.l) - 1 blst_p1_affine_in_g1(P).int == 1
while k >= 0 and s.l[k] == 0: dec k
if k < 0: return 0
var
bts = k shl 3
c = s.l[k]
while c != 0: func subgroupCheck*(P: BLS_G2P): bool {.inline.} =
c = c shr 1 blst_p2_affine_in_g2(P).int == 1
inc bts
result = bts.uint func millerLoop*(P: BLS_G1P, Q: BLS_G2P): BLS_ACC {.inline.} =
blst_miller_loop(result, Q, P)
func add*(a: var BLS_G1, b: BLS_G1) {.inline.} = proc mul*(a: var BLS_ACC, b: BLS_ACC) {.inline.} =
blst_p1_add_or_double(a, a, b) blst_fp12_mul(a, a, b)
func mul*(a: var BLS_G1, b: BLS_SCALAR) {.inline.} = func check*(x: BLS_ACC): bool {.inline.} =
blst_p1_mult(a, a, b, b.nbits) var ret: BLS_ACC
ret.blst_final_exp(x)
func add*(a: var BLS_G2, b: BLS_G2) {.inline.} = ret.blst_fp12_is_one().int == 1
blst_p2_add_or_double(a, a, b)
func mul*(a: var BLS_G2, b: BLS_SCALAR) {.inline.} =
blst_p2_mult(a, a, b, b.nbits)
func mapFPToG1*(fp: BLS_FE): BLS_G1 {.inline.} =
let z: ptr blst_fp = nil
blst_map_to_g1(result, fp, z[])
func mapFPToG2*(fp: BLS_FE2): BLS_G2 {.inline.} =
let z: ptr blst_fp2 = nil
blst_map_to_g2(result, fp, z[])
func pack(g: var BLS_G1P, x, y: BLS_FP): bool =
g = blst_p1_affine(x: x, y: y)
blst_p1_affine_on_curve(g).int == 1
func pack(g: var BLS_G2P, x0, x1, y0, y1: BLS_FP): bool =
g = blst_p2_affine(x: blst_fp2(fp: [x0, x1]), y: blst_fp2(fp: [y0, y1]))
blst_p2_affine_on_curve(g).int == 1
func subgroupCheck*(P: BLS_G1P): bool {.inline.} =
blst_p1_affine_in_g1(P).int == 1
func subgroupCheck*(P: BLS_G2P): bool {.inline.} =
blst_p2_affine_in_g2(P).int == 1
func millerLoop*(P: BLS_G1P, Q: BLS_G2P): BLS_ACC {.inline.} =
blst_miller_loop(result, Q, P)
proc mul*(a: var BLS_ACC, b: BLS_ACC) {.inline.} =
blst_fp12_mul(a, a, b)
func check*(x: BLS_ACC): bool {.inline.} =
var ret: BLS_ACC
ret.blst_final_exp(x)
ret.blst_fp12_is_one().int == 1
# decodeFieldElement expects 64 byte input with zero top 16 bytes, # decodeFieldElement expects 64 byte input with zero top 16 bytes,
# returns lower 48 bytes. # returns lower 48 bytes.
@ -207,40 +146,22 @@ func decodeFieldElement*(res: var BLS_FP, input: openArray[byte]): bool =
res.fromBytes input.toOpenArray(16, 63) res.fromBytes input.toOpenArray(16, 63)
when BLS_BACKEND == Miracl: func decodeFE*(res: var BLS_FE, input: openArray[byte]): bool =
proc decodeFE*(res: var BLS_FE, input: openArray[byte]): bool = const
var big: BLS_FP fieldModulus = StUint[512].fromHex "0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"
if not big.decodeFieldElement(input): if not res.decodeFieldElement(input):
return false return false
res = big.nres() var z: StUint[512]
# fieldModulus > big z.initFromBytesBE(input)
BIG_384_comp(FIELD_Modulus, big).int == 1 z < fieldModulus
proc decodeFE*(res: var BLS_FE2, input: openArray[byte]): bool = func decodeFE*(res: var BLS_FE2, input: openArray[byte]): bool =
if input.len != 128: if input.len != 128:
return false return false
if res.a.decodeFE(input.toOpenArray(0, 63)) and if res.fp[0].decodeFE(input.toOpenArray(0, 63)) and
res.b.decodeFE(input.toOpenArray(64, 127)): res.fp[1].decodeFE(input.toOpenArray(64, 127)):
result = true result = true
else:
func decodeFE*(res: var BLS_FE, input: openArray[byte]): bool =
const
fieldModulus = StUint[512].fromHex "0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"
if not res.decodeFieldElement(input):
return false
var z: StUint[512]
z.initFromBytesBE(input)
z < fieldModulus
func decodeFE*(res: var BLS_FE2, input: openArray[byte]): bool =
if input.len != 128:
return false
if res.fp[0].decodeFE(input.toOpenArray(0, 63)) and
res.fp[1].decodeFE(input.toOpenArray(64, 127)):
result = true
# DecodePoint given encoded (x, y) coordinates in 128 bytes returns a valid G1 Point. # DecodePoint given encoded (x, y) coordinates in 128 bytes returns a valid G1 Point.
func decodePoint*(g: var (BLS_G1 | BLS_G1P), data: openArray[byte]): bool = func decodePoint*(g: var (BLS_G1 | BLS_G1P), data: openArray[byte]): bool =