Merge pull request #912 from Zokrates/fix-serialization
Fixed deserialization logic in the zokrates.js that caused issues on cli-compiled binaries
This commit is contained in:
commit
31cec6661f
6 changed files with 43 additions and 41 deletions
|
@ -129,10 +129,19 @@ jobs:
|
|||
zokrates_js_test:
|
||||
docker:
|
||||
- image: zokrates/env:latest
|
||||
working_directory: ~/project/zokrates_js
|
||||
steps:
|
||||
- checkout
|
||||
- checkout:
|
||||
path: ~/project
|
||||
- run:
|
||||
command: cd zokrates_js && npm run test
|
||||
name: Check format
|
||||
command: cargo fmt --all -- --check
|
||||
- run:
|
||||
name: Run clippy
|
||||
command: cargo clippy -- -D warnings
|
||||
- run:
|
||||
name: Run tests
|
||||
command: npm run test
|
||||
cross_build:
|
||||
parameters:
|
||||
os:
|
||||
|
|
1
changelogs/unreleased/912-dark64
Normal file
1
changelogs/unreleased/912-dark64
Normal file
|
@ -0,0 +1 @@
|
|||
Fixed deserialization logic in the zokrates.js that caused issues on cli-compiled binaries
|
29
zokrates_js/Cargo.lock
generated
29
zokrates_js/Cargo.lock
generated
|
@ -82,16 +82,6 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.6.2"
|
||||
|
@ -1159,7 +1149,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|||
|
||||
[[package]]
|
||||
name = "zokrates_abi"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_derive",
|
||||
|
@ -1174,10 +1164,10 @@ version = "0.1.0"
|
|||
|
||||
[[package]]
|
||||
name = "zokrates_core"
|
||||
version = "0.5.3"
|
||||
version = "0.6.3"
|
||||
dependencies = [
|
||||
"bellman_ce",
|
||||
"bincode 0.8.0",
|
||||
"bincode",
|
||||
"cfg-if 0.1.10",
|
||||
"csv",
|
||||
"ff_ce 0.9.0",
|
||||
|
@ -1202,7 +1192,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zokrates_embed"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"bellman_ce",
|
||||
"sapling-crypto_ce",
|
||||
|
@ -1210,10 +1200,10 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zokrates_field"
|
||||
version = "0.3.7"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"bellman_ce",
|
||||
"bincode 0.8.0",
|
||||
"bincode",
|
||||
"lazy_static",
|
||||
"num-bigint",
|
||||
"num-integer",
|
||||
|
@ -1226,9 +1216,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zokrates_js"
|
||||
version = "1.0.27"
|
||||
version = "1.0.32"
|
||||
dependencies = [
|
||||
"bincode 1.3.1",
|
||||
"console_error_panic_hook",
|
||||
"js-sys",
|
||||
"serde",
|
||||
|
@ -1242,7 +1231,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zokrates_parser"
|
||||
version = "0.1.6"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_derive",
|
||||
|
@ -1250,7 +1239,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zokrates_pest_ast"
|
||||
version = "0.1.5"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"from-pest",
|
||||
"lazy_static",
|
||||
|
|
|
@ -8,7 +8,6 @@ edition = "2018"
|
|||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.1.4"
|
||||
js-sys = "0.3.33"
|
||||
serde = { version = "^1.0.59", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
@ -17,4 +16,4 @@ zokrates_core = { path = "../zokrates_core", features = ["wasm", "bellman"], def
|
|||
zokrates_common = { path = "../zokrates_common" }
|
||||
zokrates_field = { path = "../zokrates_field", default-features = false, features = ["bellman"] }
|
||||
zokrates_abi = { path = "../zokrates_abi" }
|
||||
console_error_panic_hook = "0.1.5"
|
||||
console_error_panic_hook = "0.1.6"
|
2
zokrates_js/package-lock.json
generated
2
zokrates_js/package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "zokrates-js",
|
||||
"version": "1.0.28",
|
||||
"version": "1.0.32",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bincode::{deserialize, serialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::to_string_pretty;
|
||||
use std::io::Cursor;
|
||||
use std::path::PathBuf;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use zokrates_abi::{parse_strict, Decode, Encode, Inputs};
|
||||
|
@ -37,14 +37,18 @@ pub struct ComputationResult {
|
|||
|
||||
#[inline]
|
||||
fn deserialize_program(value: &[u8]) -> Result<ir::Prog<Bn128Field>, JsValue> {
|
||||
deserialize(value)
|
||||
.map_err(|err| JsValue::from_str(&format!("Could not deserialize program: {}", err)))
|
||||
let prog = ir::ProgEnum::deserialize(value).map_err(|err| JsValue::from_str(&err))?;
|
||||
match prog {
|
||||
ir::ProgEnum::Bn128Program(p) => Ok(p),
|
||||
_ => Err(JsValue::from_str("Unsupported binary")),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn serialize_program(program: &ir::Prog<Bn128Field>) -> Result<Vec<u8>, JsValue> {
|
||||
serialize(program)
|
||||
.map_err(|err| JsValue::from_str(&format!("Could not serialize program: {}", err)))
|
||||
fn serialize_program(program: &ir::Prog<Bn128Field>) -> Vec<u8> {
|
||||
let mut buffer = Cursor::new(vec![]);
|
||||
program.serialize(&mut buffer);
|
||||
buffer.into_inner()
|
||||
}
|
||||
|
||||
pub struct JsResolver<'a> {
|
||||
|
@ -97,7 +101,7 @@ pub fn compile(
|
|||
config: JsValue,
|
||||
) -> Result<JsValue, JsValue> {
|
||||
let resolver = JsResolver::new(resolve_callback);
|
||||
let config: CompileConfig = config.into_serde().unwrap_or(CompileConfig::default());
|
||||
let config: CompileConfig = config.into_serde().unwrap_or_default();
|
||||
|
||||
let fmt_error = |e: &CompileError| format!("{}:{}", e.file().display(), e.value());
|
||||
let artifacts: CompilationArtifacts<Bn128Field> = core_compile(
|
||||
|
@ -107,17 +111,17 @@ pub fn compile(
|
|||
&config,
|
||||
)
|
||||
.map_err(|ce| {
|
||||
JsValue::from_str(&format!(
|
||||
"{}",
|
||||
ce.0.iter()
|
||||
JsValue::from_str(
|
||||
&ce.0
|
||||
.iter()
|
||||
.map(|e| fmt_error(e))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
))
|
||||
.join("\n"),
|
||||
)
|
||||
})?;
|
||||
|
||||
let result = CompilationResult {
|
||||
program: serialize_program(artifacts.prog())?,
|
||||
program: serialize_program(artifacts.prog()),
|
||||
abi: to_string_pretty(artifacts.abi()).unwrap(),
|
||||
};
|
||||
|
||||
|
@ -134,8 +138,8 @@ pub fn compute_witness(program: &[u8], abi: JsValue, args: JsValue) -> Result<Js
|
|||
let input = args.as_string().unwrap();
|
||||
|
||||
let inputs = parse_strict(&input, signature.inputs)
|
||||
.map(|parsed| Inputs::Abi(parsed))
|
||||
.map_err(|why| JsValue::from_str(&format!("{}", why.to_string())))?;
|
||||
.map(Inputs::Abi)
|
||||
.map_err(|why| JsValue::from_str(&why.to_string()))?;
|
||||
|
||||
let interpreter = ir::Interpreter::default();
|
||||
|
||||
|
@ -203,6 +207,6 @@ pub fn verify(vk: JsValue, proof: JsValue) -> Result<JsValue, JsValue> {
|
|||
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn main_js() -> Result<(), JsValue> {
|
||||
console_error_panic_hook::set_once();
|
||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue