@@ -2,8 +2,8 @@ extern crate ethereum_bn128;
2
2
extern crate parity_bytes as bytes;
3
3
extern crate rustc_hex;
4
4
5
- use std:: os:: raw:: c_char;
6
5
use std:: ffi:: CStr ;
6
+ use std:: os:: raw:: c_char;
7
7
8
8
use rustc_hex:: FromHex ;
9
9
use rustc_hex:: ToHex ;
@@ -12,67 +12,61 @@ use bytes::BytesRef;
12
12
13
13
#[ no_mangle]
14
14
pub fn ec_mul ( input_hex_ptr : * const c_char ) -> * const c_char {
15
- let input_hex = unsafe { CStr :: from_ptr ( input_hex_ptr) } ;
16
- let input_str: & str = input_hex. to_str ( ) . unwrap ( ) ;
17
- let input_parsed = FromHex :: from_hex ( input_str) . unwrap ( ) ;
15
+ let input_hex = unsafe { CStr :: from_ptr ( input_hex_ptr) } ;
16
+ let input_str: & str = input_hex. to_str ( ) . unwrap ( ) ;
17
+ let input_parsed = FromHex :: from_hex ( input_str) . unwrap ( ) ;
18
18
19
- let mut output = vec ! [ 0u8 ; 64 ] ;
20
- match ethereum_bn128:: bn128_mul ( & input_parsed[ ..] , & mut BytesRef :: Fixed ( & mut output[ ..] ) ) {
21
- Ok ( _) => {
22
- let mut output_hex = output. to_hex ( ) ;
23
- output_hex. push_str ( "\0 " ) ;
24
- return output_hex. as_ptr ( ) as * const c_char
25
- }
26
- Err ( _) => {
27
- return "\0 " . as_ptr ( ) as * const c_char
28
- }
29
- }
19
+ let mut output = vec ! [ 0u8 ; 64 ] ;
20
+ match ethereum_bn128:: bn128_mul ( & input_parsed[ ..] , & mut BytesRef :: Fixed ( & mut output[ ..] ) ) {
21
+ Ok ( _) => {
22
+ let mut output_hex = output. to_hex ( ) ;
23
+ output_hex. push_str ( "\0 " ) ;
24
+ return output_hex. as_ptr ( ) as * const c_char ;
25
+ }
26
+ Err ( _) => return "\0 " . as_ptr ( ) as * const c_char ,
27
+ }
30
28
}
31
29
32
30
#[ no_mangle]
33
31
pub fn ec_add ( input_hex_ptr : * const c_char ) -> * const c_char {
34
- let input_hex = unsafe { CStr :: from_ptr ( input_hex_ptr) } ;
35
- let input_str: & str = input_hex. to_str ( ) . unwrap ( ) ;
36
- let input_parsed = FromHex :: from_hex ( input_str) . unwrap ( ) ;
32
+ let input_hex = unsafe { CStr :: from_ptr ( input_hex_ptr) } ;
33
+ let input_str: & str = input_hex. to_str ( ) . unwrap ( ) ;
34
+ let input_parsed = FromHex :: from_hex ( input_str) . unwrap ( ) ;
37
35
38
- let mut output = vec ! [ 0u8 ; 64 ] ;
39
- match ethereum_bn128:: bn128_add ( & input_parsed[ ..] , & mut BytesRef :: Fixed ( & mut output[ ..] ) ) {
40
- Ok ( _) => {
41
- let mut output_hex = output. to_hex ( ) ;
42
- output_hex. push_str ( "\0 " ) ;
43
- return output_hex. as_ptr ( ) as * const c_char
44
- }
45
- Err ( _) => {
46
- return "\0 " . as_ptr ( ) as * const c_char
47
- }
48
- }
36
+ let mut output = vec ! [ 0u8 ; 64 ] ;
37
+ match ethereum_bn128:: bn128_add ( & input_parsed[ ..] , & mut BytesRef :: Fixed ( & mut output[ ..] ) ) {
38
+ Ok ( _) => {
39
+ let mut output_hex = output. to_hex ( ) ;
40
+ output_hex. push_str ( "\0 " ) ;
41
+ return output_hex. as_ptr ( ) as * const c_char ;
42
+ }
43
+ Err ( _) => return "\0 " . as_ptr ( ) as * const c_char ,
44
+ }
49
45
}
50
46
51
47
#[ no_mangle]
52
48
pub fn ec_pairing ( input_hex_ptr : * const c_char ) -> * const c_char {
53
- let input_hex = unsafe { CStr :: from_ptr ( input_hex_ptr) } ;
54
- let input_str: & str = input_hex. to_str ( ) . unwrap ( ) ;
55
- let input_parsed = FromHex :: from_hex ( input_str) . unwrap ( ) ;
49
+ let input_hex = unsafe { CStr :: from_ptr ( input_hex_ptr) } ;
50
+ let input_str: & str = input_hex. to_str ( ) . unwrap ( ) ;
51
+ let input_parsed = FromHex :: from_hex ( input_str) . unwrap ( ) ;
56
52
57
- let mut output = vec ! [ 0u8 ; 32 ] ;
58
- match ethereum_bn128:: bn128_pairing ( & input_parsed[ ..] , & mut BytesRef :: Fixed ( & mut output[ ..] ) ) {
59
- Ok ( _) => {
60
- let mut output_hex = output. to_hex ( ) ;
61
- output_hex. push_str ( "\0 " ) ;
62
- return output_hex. as_ptr ( ) as * const c_char
63
- }
64
- Err ( _) => {
65
- return "\0 " . as_ptr ( ) as * const c_char
66
- }
67
- }
53
+ let mut output = vec ! [ 0u8 ; 32 ] ;
54
+ match ethereum_bn128:: bn128_pairing ( & input_parsed[ ..] , & mut BytesRef :: Fixed ( & mut output[ ..] ) ) {
55
+ Ok ( _) => {
56
+ let mut output_hex = output. to_hex ( ) ;
57
+ output_hex. push_str ( "\0 " ) ;
58
+ return output_hex. as_ptr ( ) as * const c_char ;
59
+ }
60
+ Err ( _) => return "\0 " . as_ptr ( ) as * const c_char ,
61
+ }
68
62
}
69
63
70
- extern {
71
- fn emscripten_exit_with_live_runtime ( ) ;
64
+ extern "C" {
65
+ fn emscripten_exit_with_live_runtime ( ) ;
72
66
}
73
67
74
68
fn main ( ) {
75
- unsafe {
76
- emscripten_exit_with_live_runtime ( ) ;
77
- }
69
+ unsafe {
70
+ emscripten_exit_with_live_runtime ( ) ;
71
+ }
78
72
}
0 commit comments