mirror of https://github.com/vacp2p/zerokit.git
fix: u64 to usize conversion
usize::from_le_bytes will take an array of length 2, 4 or 8 bytes depending on the target pointer size. Since wasm uses 32b, there was a failure while reading serialized values due to the number of bytes read being incorrect. I also update version rln-wasm to 0.0.9 (npm package needs to be updated to include this fix)
This commit is contained in:
parent
654c77dcf6
commit
33d3732922
|
@ -2405,7 +2405,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rln-wasm"
|
name = "rln-wasm"
|
||||||
version = "0.0.7"
|
version = "0.0.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rln-wasm"
|
name = "rln-wasm"
|
||||||
version = "0.0.8"
|
version = "0.0.9"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT or Apache2"
|
license = "MIT or Apache2"
|
||||||
|
|
||||||
|
|
|
@ -155,13 +155,17 @@ pub fn proof_inputs_to_rln_witness(
|
||||||
let (identity_secret, read) = bytes_le_to_fr(&serialized[all_read..]);
|
let (identity_secret, read) = bytes_le_to_fr(&serialized[all_read..]);
|
||||||
all_read += read;
|
all_read += read;
|
||||||
|
|
||||||
let id_index = usize::from_le_bytes(serialized[all_read..all_read + 8].try_into()?);
|
let id_index = usize::try_from(u64::from_le_bytes(
|
||||||
|
serialized[all_read..all_read + 8].try_into()?,
|
||||||
|
))?;
|
||||||
all_read += 8;
|
all_read += 8;
|
||||||
|
|
||||||
let (epoch, read) = bytes_le_to_fr(&serialized[all_read..]);
|
let (epoch, read) = bytes_le_to_fr(&serialized[all_read..]);
|
||||||
all_read += read;
|
all_read += read;
|
||||||
|
|
||||||
let signal_len = usize::from_le_bytes(serialized[all_read..all_read + 8].try_into()?);
|
let signal_len = usize::try_from(u64::from_le_bytes(
|
||||||
|
serialized[all_read..all_read + 8].try_into()?,
|
||||||
|
))?;
|
||||||
all_read += 8;
|
all_read += 8;
|
||||||
|
|
||||||
let signal: Vec<u8> = serialized[all_read..all_read + signal_len].to_vec();
|
let signal: Vec<u8> = serialized[all_read..all_read + signal_len].to_vec();
|
||||||
|
|
|
@ -607,7 +607,9 @@ impl RLN<'_> {
|
||||||
let (proof_values, read) = deserialize_proof_values(&serialized[all_read..]);
|
let (proof_values, read) = deserialize_proof_values(&serialized[all_read..]);
|
||||||
all_read += read;
|
all_read += read;
|
||||||
|
|
||||||
let signal_len = usize::from_le_bytes(serialized[all_read..all_read + 8].try_into()?);
|
let signal_len = usize::try_from(u64::from_le_bytes(
|
||||||
|
serialized[all_read..all_read + 8].try_into()?,
|
||||||
|
))?;
|
||||||
all_read += 8;
|
all_read += 8;
|
||||||
|
|
||||||
let signal: Vec<u8> = serialized[all_read..all_read + signal_len].to_vec();
|
let signal: Vec<u8> = serialized[all_read..all_read + signal_len].to_vec();
|
||||||
|
@ -683,7 +685,9 @@ impl RLN<'_> {
|
||||||
let (proof_values, read) = deserialize_proof_values(&serialized[all_read..]);
|
let (proof_values, read) = deserialize_proof_values(&serialized[all_read..]);
|
||||||
all_read += read;
|
all_read += read;
|
||||||
|
|
||||||
let signal_len = usize::from_le_bytes(serialized[all_read..all_read + 8].try_into()?);
|
let signal_len = usize::try_from(u64::from_le_bytes(
|
||||||
|
serialized[all_read..all_read + 8].try_into()?,
|
||||||
|
))?;
|
||||||
all_read += 8;
|
all_read += 8;
|
||||||
|
|
||||||
let signal: Vec<u8> = serialized[all_read..all_read + signal_len].to_vec();
|
let signal: Vec<u8> = serialized[all_read..all_read + signal_len].to_vec();
|
||||||
|
|
|
@ -117,7 +117,7 @@ pub fn vec_u8_to_bytes_be(input: Vec<u8>) -> Result<Vec<u8>> {
|
||||||
pub fn bytes_le_to_vec_u8(input: &[u8]) -> Result<(Vec<u8>, usize)> {
|
pub fn bytes_le_to_vec_u8(input: &[u8]) -> Result<(Vec<u8>, usize)> {
|
||||||
let mut read: usize = 0;
|
let mut read: usize = 0;
|
||||||
|
|
||||||
let len = usize::from_le_bytes(input[0..8].try_into()?);
|
let len = usize::try_from(u64::from_le_bytes(input[0..8].try_into()?))?;
|
||||||
read += 8;
|
read += 8;
|
||||||
|
|
||||||
let res = input[8..8 + len].to_vec();
|
let res = input[8..8 + len].to_vec();
|
||||||
|
@ -129,7 +129,7 @@ pub fn bytes_le_to_vec_u8(input: &[u8]) -> Result<(Vec<u8>, usize)> {
|
||||||
pub fn bytes_be_to_vec_u8(input: &[u8]) -> Result<(Vec<u8>, usize)> {
|
pub fn bytes_be_to_vec_u8(input: &[u8]) -> Result<(Vec<u8>, usize)> {
|
||||||
let mut read: usize = 0;
|
let mut read: usize = 0;
|
||||||
|
|
||||||
let len = usize::from_be_bytes(input[0..8].try_into()?);
|
let len = usize::try_from(u64::from_be_bytes(input[0..8].try_into()?))?;
|
||||||
read += 8;
|
read += 8;
|
||||||
|
|
||||||
let res = input[8..8 + len].to_vec();
|
let res = input[8..8 + len].to_vec();
|
||||||
|
@ -143,7 +143,7 @@ pub fn bytes_le_to_vec_fr(input: &[u8]) -> Result<(Vec<Fr>, usize)> {
|
||||||
let mut read: usize = 0;
|
let mut read: usize = 0;
|
||||||
let mut res: Vec<Fr> = Vec::new();
|
let mut res: Vec<Fr> = Vec::new();
|
||||||
|
|
||||||
let len = usize::from_le_bytes(input[0..8].try_into()?);
|
let len = usize::try_from(u64::from_le_bytes(input[0..8].try_into()?))?;
|
||||||
read += 8;
|
read += 8;
|
||||||
|
|
||||||
let el_size = fr_byte_size();
|
let el_size = fr_byte_size();
|
||||||
|
@ -160,7 +160,7 @@ pub fn bytes_be_to_vec_fr(input: &[u8]) -> Result<(Vec<Fr>, usize)> {
|
||||||
let mut read: usize = 0;
|
let mut read: usize = 0;
|
||||||
let mut res: Vec<Fr> = Vec::new();
|
let mut res: Vec<Fr> = Vec::new();
|
||||||
|
|
||||||
let len = usize::from_be_bytes(input[0..8].try_into()?);
|
let len = usize::try_from(u64::from_le_bytes(input[0..8].try_into()?))?;
|
||||||
read += 8;
|
read += 8;
|
||||||
|
|
||||||
let el_size = fr_byte_size();
|
let el_size = fr_byte_size();
|
||||||
|
|
Loading…
Reference in New Issue