Skip to content

Commit 7cc22ab

Browse files
authored
Merge pull request #38 from ethereumjs/bn128-update
Update upstream ethereum-bn128
2 parents 8ac7be0 + 8bdd3bf commit 7cc22ab

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

.cargo/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
rustflags = [
44
"-Clink-args=-s NO_DYNAMIC_EXECUTION=1",
55
"-Clink-args=-s NODEJS_CATCH_EXIT=0",
6+
"-Clink-args=-s EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap']",
67
]

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ authors = ["holgerd77 <[email protected]>",
77
publish = false
88

99
[dependencies]
10-
ethereum-bn128 = { git = "https://github.com/ewasm/ethereum-bn128.rs" }
11-
parity-bytes = { git = "https://github.com/paritytech/parity-common" }
10+
ethereum-bn128 = { git = "https://github.com/ewasm/ethereum-bn128.rs", version = "0.1.0" }
1211
rustc-hex = "1.0"

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ all:
44
cargo build --target=asmjs-unknown-emscripten --release
55
mkdir -p lib
66
find target/asmjs-unknown-emscripten/release -type f -name "rustbn-js.js" | xargs -I {} cp {} lib/index.asm.js
7-
@res=$$(sed -n '/run()$$/p' lib/index.asm.js | wc -l); \
7+
@res=$$(sed -n '/run();$$/p' lib/index.asm.js | wc -l); \
88
if [ $$res == "0" ]; then \
99
echo "ERROR: could not find run() function in generated code"; \
1010
exit 1; \
1111
fi\
1212

13-
sed -ibak 's/run()$$/Module\["arguments"\]=\[\];run();module\.exports=Module;/' lib/index.asm.js
13+
sed -ibak 's/run();$$/Module\["arguments"\]=\[\];run();module\.exports=Module;/' lib/index.asm.js
1414

1515
wasm:
1616
cargo build --target=wasm32-unknown-emscripten --release

lib/index.asm.js

Lines changed: 25 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
extern crate ethereum_bn128;
2-
extern crate parity_bytes as bytes;
32
extern crate rustc_hex;
43

54
use std::ffi::CStr;
@@ -8,16 +7,14 @@ use std::os::raw::c_char;
87
use rustc_hex::FromHex;
98
use rustc_hex::ToHex;
109

11-
use bytes::BytesRef;
12-
1310
#[no_mangle]
1411
pub fn ec_mul(input_hex_ptr: *const c_char) -> *const c_char {
1512
let input_hex = unsafe { CStr::from_ptr(input_hex_ptr) };
1613
let input_str: &str = input_hex.to_str().unwrap();
1714
let input_parsed = FromHex::from_hex(input_str).unwrap();
1815

19-
let mut output = vec![0u8; 64];
20-
match ethereum_bn128::bn128_mul(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
16+
let mut output = [0u8; 64];
17+
match ethereum_bn128::bn128_mul(&input_parsed[..], &mut output) {
2118
Ok(_) => {
2219
let mut output_hex = output.to_hex();
2320
output_hex.push_str("\0");
@@ -33,8 +30,8 @@ pub fn ec_add(input_hex_ptr: *const c_char) -> *const c_char {
3330
let input_str: &str = input_hex.to_str().unwrap();
3431
let input_parsed = FromHex::from_hex(input_str).unwrap();
3532

36-
let mut output = vec![0u8; 64];
37-
match ethereum_bn128::bn128_add(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
33+
let mut output = [0u8; 64];
34+
match ethereum_bn128::bn128_add(&input_parsed[..], &mut output) {
3835
Ok(_) => {
3936
let mut output_hex = output.to_hex();
4037
output_hex.push_str("\0");
@@ -50,8 +47,8 @@ pub fn ec_pairing(input_hex_ptr: *const c_char) -> *const c_char {
5047
let input_str: &str = input_hex.to_str().unwrap();
5148
let input_parsed = FromHex::from_hex(input_str).unwrap();
5249

53-
let mut output = vec![0u8; 32];
54-
match ethereum_bn128::bn128_pairing(&input_parsed[..], &mut BytesRef::Fixed(&mut output[..])) {
50+
let mut output = [0u8; 32];
51+
match ethereum_bn128::bn128_pairing(&input_parsed[..], &mut output) {
5552
Ok(_) => {
5653
let mut output_hex = output.to_hex();
5754
output_hex.push_str("\0");

0 commit comments

Comments
 (0)