From 624780fe7586fef882a86ad58dede762f96ebd02 Mon Sep 17 00:00:00 2001 From: web3Softcloud Date: Thu, 11 Jan 2024 10:34:49 +0800 Subject: [PATCH] MOD: deserialize program. --- Cargo.lock | 1 + zk-vm/Cargo.toml | 11 ++++++----- zk-vm/src/lib.rs | 8 ++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32e6fd6d..1ecb8f44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3388,6 +3388,7 @@ dependencies = [ name = "zk-vm" version = "0.1.0" dependencies = [ + "bincode", "core", "env_logger 0.6.2", "executor", diff --git a/zk-vm/Cargo.toml b/zk-vm/Cargo.toml index f2b8feaf..2f1fcf23 100644 --- a/zk-vm/Cargo.toml +++ b/zk-vm/Cargo.toml @@ -6,14 +6,15 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ola-core = { package = "core", path = "../core", version = "0.1.0"} +ola-core = { package = "core", path = "../core", version = "0.1.0" } executor = { package = "executor", path = "../executor", version = "0.1.0", default-features = false } serde_json = "1" -serde = {version = "1" } -serde_derive = {version = "1"} +serde = { version = "1" } +serde_derive = { version = "1" } env_logger = "0.6" log = "0.4" thiserror = "1.0" -tokio = { version = "1", features = ["full","test-util"] } +tokio = { version = "1", features = ["full", "test-util"] } tempfile = "3" -rand = "0.8.5" \ No newline at end of file +rand = "0.8.5" +bincode = "1.3.3" diff --git a/zk-vm/src/lib.rs b/zk-vm/src/lib.rs index b8a85262..f8b80c12 100644 --- a/zk-vm/src/lib.rs +++ b/zk-vm/src/lib.rs @@ -159,8 +159,12 @@ impl OlaVM { if get_code { let contract = self.get_program(&code_hash)?; - let bin_program: BinaryProgram = - serde_json::from_str(std::str::from_utf8(&contract.to_vec()).unwrap()).unwrap(); + let bin_program: BinaryProgram = match bincode::deserialize(&contract) { + Ok(data) => data, + Err(e) => { + return Err(StateError::GetProgramError(format!("{:?}", e))); + } + }; let instructions = bin_program.bytecode.split("\n"); let code: Vec<_> = instructions