chore: use cross instead of rustup for building rln

This commit is contained in:
Richard Ramos 2022-06-29 15:55:46 -04:00
parent e0e31478e3
commit 8c4e6bb25f
No known key found for this signature in database
GPG Key ID: BD36D48BC9FFC88C
28 changed files with 84 additions and 62 deletions

View File

@ -1,5 +1,5 @@
.PHONY: rlnlib
rlnlib:
sh scripts/build.sh
scripts/build.sh
cd lib/rln && cbindgen --config ../cbindgen.toml --crate rln --output ../../rln/librln.h --lang c

View File

@ -10,3 +10,14 @@ Further research can be found here:
The goal of this is to create a rate-limiter for blockchains where block production is cheap. I started playing around with this
after talking to the team at [Celestia](https://celestia.org/).
###
The following architectures require newer versions of glibc.
- `x86_64-pc-windows-gnu`
- `aarch64-unknown-linux-gnu`
- `x86_64-unknown-linux-gnu`
- `arm-unknown-linux-gnueabi`
This [PR](https://github.com/cross-rs/cross/pull/591) will update ubuntu base version on cross. But while it's merged, follow the instructions from [here](https://github.com/cross-rs/cross/wiki/FAQ#newer-linux-versions) to locally build docker images for those architectures.

@ -1 +1 @@
Subproject commit 628fd742237f49347469dfcbbe57fd591d6629b1
Subproject commit 7ac74183f8b69b399e3bc96c1ae8ab61c026dc43

View File

@ -0,0 +1 @@
/target/aarch64-linux-android/release/librln.so: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/aarch64-linux-android/release/build/num-bigint-4ba1a00c5942ed3b/out/radix_bases.rs build.rs

Binary file not shown.

View File

@ -0,0 +1 @@
/target/aarch64-unknown-linux-gnu/release/librln.so: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/aarch64-unknown-linux-gnu/release/build/num-bigint-69b80aa090dc4b25/out/radix_bases.rs build.rs

Binary file not shown.

View File

@ -0,0 +1 @@
/target/arm-unknown-linux-gnueabi/release/librln.so: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/arm-unknown-linux-gnueabi/release/build/num-bigint-9bbf2c096f81fccc/out/radix_bases.rs build.rs

Binary file not shown.

View File

@ -0,0 +1 @@
/target/armv7-linux-androideabi/release/librln.so: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/armv7-linux-androideabi/release/build/num-bigint-8fa42ea69abd53fb/out/radix_bases.rs build.rs

Binary file not shown.

View File

@ -0,0 +1 @@
/target/i686-linux-android/release/librln.so: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/i686-linux-android/release/build/num-bigint-5b002515a3c1c3de/out/radix_bases.rs build.rs

Binary file not shown.

View File

@ -0,0 +1 @@
/target/x86_64-linux-android/release/librln.so: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/x86_64-linux-android/release/build/num-bigint-a07eaff1eafc61a9/out/radix_bases.rs build.rs

Binary file not shown.

View File

@ -0,0 +1 @@
/target/x86_64-pc-windows-gnu/release/librln.rlib: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/x86_64-pc-windows-gnu/release/build/num-bigint-2d87d54ca5f526b6/out/radix_bases.rs build.rs

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
/target/x86_64-unknown-linux-gnu/release/librln.so: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/x86_64-unknown-linux-gnu/release/build/num-bigint-e05ef1c2b46a8adc/out/radix_bases.rs build.rs

Binary file not shown.

View File

@ -1 +1 @@
/Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/target/x86_64-unknown-linux-musl/release/librln.rlib: /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/mod.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/polynomial.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/poseidon.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/circuit/rln.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/ffi.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/lib.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/merkle.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/poseidon.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/public.rs /Users/deaneigenmann/go/src/github.com/decanus/go-rln/lib/rln/src/utils.rs
/target/x86_64-unknown-linux-musl/release/librln.rlib: /project/src/circuit/mod.rs /project/src/circuit/polynomial.rs /project/src/circuit/poseidon.rs /project/src/circuit/rln.rs /project/src/ffi.rs /project/src/hash_to_field.rs /project/src/lib.rs /project/src/merkle.rs /project/src/poseidon.rs /project/src/public.rs /project/src/utils.rs /target/x86_64-unknown-linux-musl/release/build/num-bigint-11903a3d0fc503f2/out/radix_bases.rs build.rs

View File

@ -14,11 +14,6 @@ typedef struct Buffer {
uintptr_t len;
} Buffer;
typedef struct Auth {
const struct Buffer *secret_buffer;
uintptr_t index;
} Auth;
bool new_circuit_from_params(uintptr_t merkle_depth,
const struct Buffer *parameters_buffer,
struct RLN_Bn256 **ctx);
@ -31,14 +26,12 @@ bool delete_member(struct RLN_Bn256 *ctx, uintptr_t index);
bool generate_proof(const struct RLN_Bn256 *ctx,
const struct Buffer *input_buffer,
const struct Auth *auth,
struct Buffer *output_buffer);
bool verify(const struct RLN_Bn256 *ctx, struct Buffer *proof_buffer, uint32_t *result_ptr);
bool verify(const struct RLN_Bn256 *ctx, const struct Buffer *proof_buffer, uint32_t *result_ptr);
bool hash(const struct RLN_Bn256 *ctx,
const struct Buffer *inputs_buffer,
uintptr_t input_len,
struct Buffer *output_buffer);
bool signal_to_field(const struct RLN_Bn256 *ctx,
const struct Buffer *inputs_buffer,
struct Buffer *output_buffer);
bool key_gen(const struct RLN_Bn256 *ctx, struct Buffer *keypair_buffer);
bool key_gen(const struct RLN_Bn256 *ctx, struct Buffer *input_buffer);

View File

@ -64,8 +64,7 @@ func (r *RLN) GenerateKey() (*KeyPair, error) {
return key, nil
}
// Hash hashes a given input using the underlying function.
func (r *RLN) Hash(input []byte) ([]byte, error) {
func (r *RLN) SignalToField(input []byte) ([]byte, error) {
buf := toBuffer(input)
size := int(unsafe.Sizeof(buf))
@ -75,7 +74,7 @@ func (r *RLN) Hash(input []byte) ([]byte, error) {
var output []byte
out := toBuffer(output)
if !bool(C.hash(r.ptr, in, 1, &out)) {
if !bool(C.signal_to_field(r.ptr, in, &out)) {
return nil, errors.New("failed to hash")
}
@ -89,13 +88,7 @@ func (r *RLN) GenerateProof(input []byte, key *KeyPair, index uint) ([]byte, err
var output []byte
out := toBuffer(output)
keybuf := toBuffer(key.Key[:])
auth := &C.Auth{
secret_buffer: &keybuf,
index: C.ulong(index),
}
if !bool(C.generate_proof(r.ptr, &inputBuf, auth, &out)) {
if !bool(C.generate_proof(r.ptr, &inputBuf, &out)) {
return nil, errors.New("failed to generate proof")
}

View File

@ -1,3 +1,4 @@
//go:build !android && linux && amd64 && !musl
// +build !android,linux,amd64,!musl
package rln

View File

@ -46,6 +46,7 @@ func TestGenerateKey(t *testing.T) {
}
}
/*
func TestRLN_Hash(t *testing.T) {
// This test is based on tests from:
// https://github.com/status-im/nim-waku/blob/b7998de09d1ef04599a699938da69aecfa63cc6f/tests/v2/test_waku_rln_relay.nim#L527
@ -71,7 +72,7 @@ func TestRLN_Hash(t *testing.T) {
if expected != hex.EncodeToString(output) {
t.Fatalf("value %x did not match expected %s", output, expected)
}
}
}*/
func TestRLN_GetRoot(t *testing.T) {
// This test is based on tests from:

11
scripts/Cross.toml Normal file
View File

@ -0,0 +1,11 @@
[target.x86_64-pc-windows-gnu]
image = "ghcr.io/cross-rs/x86_64-pc-windows-gnu:local"
[target.aarch64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:local"
[target.x86_64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:local"
[target.arm-unknown-linux-gnueabi]
image = "ghcr.io/cross-rs/arm-unknown-linux-gnueabi:local"

76
scripts/build.sh Normal file → Executable file
View File

@ -1,3 +1,5 @@
#!/bin/bash
DIRECTORY=./libs
if [[ -d "$DIRECTORY" ]]
then
@ -5,46 +7,48 @@ then
exit 0
fi
export RUSTFLAGS="-Ccodegen-units=1"
export CROSS_CONFIG="$PWD/scripts/Cross.toml"
pushd lib/rln
export RUSTFLAGS="-Ccodegen-units=1"
rustup default 1.52.1
cargo install cargo-lipo -f
cargo install cargo-strip -f
rustup default stable
rustup target add x86_64-unknown-linux-gnu
rustup target add aarch64-unknown-linux-gnu
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
rustup target add x86_64-pc-windows-gnu
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
rustup target add x86_64-linux-android
rustup target add x86_64-unknown-linux-musl
rustup target add aarch64-apple-ios x86_64-apple-ios
cargo install cross --git https://github.com/cross-rs/cross --branch main
cargo install cargo-lipo
# cargo install cargo-strip
cross build --release --lib --target=aarch64-linux-android
cross build --release --lib --target=armv7-linux-androideabi
cross build --release --lib --target=i686-linux-android
cross build --release --lib --target=x86_64-linux-android
cross build --release --lib --target=x86_64-unknown-linux-musl
#cross build --release --lib --target=arm-unknown-linux-gnueabihf
#cross build --release --lib --target=i686-unknown-linux-gnu
#cross build --release --lib --target=mips-unknown-linux-gnu
#cross build --release --lib --target=mips64-unknown-linux-gnuabi64
#cross build --release --lib --target=mips64el-unknown-linux-gnuabi64
#cross build --release --lib --target=mipsel-unknown-linux-gnu
#cross build --release --lib --target=i686-pc-windows-gnu
# These depend on https://github.com/cross-rs/cross/pull/591 being merged
# In the meantime, we can follow the instructions from here
# https://github.com/cross-rs/cross/wiki/FAQ#newer-linux-versions
# to build the docker images locally. Once that PR is merged,
# remove the CROSS_CONFIG variable and Cross.toml file
cross build --release --lib --target=x86_64-pc-windows-gnu
cross build --release --lib --target=aarch64-unknown-linux-gnu
cross build --release --lib --target=x86_64-unknown-linux-gnu
cross build --release --lib --target=arm-unknown-linux-gnueabi
#rustup target add aarch64-apple-ios x86_64-apple-ios
#cross build --release --target=x86_64-apple-darwin --lib
#cross build --release --target=aarch64-apple-darwin --lib
#cargo lipo --release --targets=aarch64-apple-ios,x86_64-apple-ios
cargo build --release --target=aarch64-linux-android --lib
cargo strip --target aarch64-linux-android
cargo build --release --target=armv7-linux-androideabi --lib
cargo strip --target armv7-linux-androideabi
cargo build --release --target=i686-linux-android --lib
cargo strip --target i686-linux-android
cargo build --release --target=x86_64-linux-android --lib
cargo strip --target x86_64-linux-android
cargo build --target=x86_64-unknown-linux-gnu --release
cargo strip --target x86_64-unknown-linux-gnu
cargo build --target=aarch64-unknown-linux-gnu --release
cargo strip --target aarch64-unknown-linux-gnu
cargo build --target=x86_64-apple-darwin --release
cargo strip --target x86_64-apple-darwin
cargo build --target=aarch64-apple-darwin --release
cargo strip --target aarch64-apple-darwin
cargo build --target=x86_64-pc-windows-gnu --release
cargo strip --target x86_64-pc-windows-gnu
cargo build --target=x86_64-unknown-linux-musl --release
cargo strip --target x86_64-unknown-linux-musl
cargo lipo --release --targets=aarch64-apple-ios,x86_64-apple-ios
popd