@ -0,0 +1,25 @@ |
|||||
|
# poseidon-lengths test |
||||
|
|
||||
|
Test to check the output of the Poseidon Hash implementations in Go and Rust for the cases when the BigInt outputed is of 31 bytes. |
||||
|
|
||||
|
- Go |
||||
|
``` |
||||
|
> go test |
||||
|
|
||||
|
bigint 166341157454475665850184286625226909090143669024322546717713937140175961129 |
||||
|
length 31 |
||||
|
bytes [94 37 80 113 132 94 199 232 119 124 206 119 0 59 128 138 249 85 43 37 236 41 18 110 |
||||
|
214 23 182 6 121 124 41] |
||||
|
hex 5e255071845ec7e8777cce77003b808af9552b25ec29126ed617b606797c29 |
||||
|
``` |
||||
|
|
||||
|
- Rust |
||||
|
``` |
||||
|
> cargo test -- --nocapture |
||||
|
|
||||
|
bigint "166341157454475665850184286625226909090143669024322546717713937140175961129" |
||||
|
length 31 |
||||
|
bytes [94, 37, 80, 113, 132, 94, 199, 232, 119, 124, 206, 119, 0, 59, 128, 138, 249, 85, 43 |
||||
|
, 37, 236, 41, 18, 110, 214, 23, 182, 6, 121, 124, 41] |
||||
|
hex "5e255071845ec7e8777cce77003b808af9552b25ec29126ed617b606797c29" |
||||
|
``` |
@ -0,0 +1,5 @@ |
|||||
|
module poseidon-lengths |
||||
|
|
||||
|
go 1.14 |
||||
|
|
||||
|
require github.com/iden3/go-iden3-crypto v0.0.4 |
@ -0,0 +1,16 @@ |
|||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
||||
|
github.com/dchest/blake512 v1.0.0/go.mod h1:FV1x7xPPLWukZlpDpWQ88rF/SFwZ5qbskrzhLMB92JI= |
||||
|
github.com/ethereum/go-ethereum v1.8.27/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= |
||||
|
github.com/iden3/go-iden3-crypto v0.0.4 h1:rGQEFBvX6d4fDxqkQTizVq5UefB+xdZAg8j5FQ6uv6g= |
||||
|
github.com/iden3/go-iden3-crypto v0.0.4/go.mod h1:LLcgB7DLWAUs+8eBSKne+ZHy5z7xtAmlYlEz0M9M8gE= |
||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= |
||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= |
||||
|
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A= |
||||
|
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= |
||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= |
||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= |
||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
@ -0,0 +1,25 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"encoding/hex" |
||||
|
"fmt" |
||||
|
"testing" |
||||
|
|
||||
|
"github.com/iden3/go-iden3-crypto/poseidon" |
||||
|
) |
||||
|
|
||||
|
func TestLen(t *testing.T) { |
||||
|
m := []byte("45") |
||||
|
h, err := poseidon.HashBytes(m) |
||||
|
if err != nil { |
||||
|
t.Fatal(err) |
||||
|
} |
||||
|
fmt.Println("bigint", h.String()) |
||||
|
fmt.Println("length", len(h.Bytes())) |
||||
|
fmt.Println("bytes", h.Bytes()) |
||||
|
fmt.Println("hex", hex.EncodeToString(h.Bytes())) |
||||
|
if len(h.Bytes()) != 31 { |
||||
|
t.Fatal("expected 31 bytes") |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
/target |
||||
|
Cargo.lock |
@ -0,0 +1,11 @@ |
|||||
|
[package] |
||||
|
name = "rs" |
||||
|
version = "0.0.1" |
||||
|
authors = ["arnaucube <root@arnaucube.com>"] |
||||
|
edition = "2018" |
||||
|
|
||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
|
||||
|
[dependencies] |
||||
|
poseidon-rs = "0.0.2" |
||||
|
rustc-hex = "1.0.0" |
@ -0,0 +1,17 @@ |
|||||
|
#[cfg(test)]
|
||||
|
mod tests {
|
||||
|
use poseidon_rs::Poseidon;
|
||||
|
use rustc_hex::ToHex;
|
||||
|
|
||||
|
#[test]
|
||||
|
fn test_output_size() {
|
||||
|
let poseidon = Poseidon::new();
|
||||
|
let msg = "45";
|
||||
|
let h = poseidon.hash_bytes(msg.as_bytes().to_vec()).unwrap();
|
||||
|
println!("bigint {:?}", h.to_string());
|
||||
|
println!("length {:?}", h.to_bytes_be().1.len());
|
||||
|
println!("bytes {:?}", h.to_bytes_be().1);
|
||||
|
assert_eq!(h.to_bytes_be().1.len(), 31);
|
||||
|
println!("hex {:?}", h.to_bytes_be().1.to_hex());
|
||||
|
}
|
||||
|
}
|