Skip to content

Commit

Permalink
Add asc abort polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
aseaday committed Oct 25, 2022
1 parent f52ff45 commit 9c232e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
23 changes: 3 additions & 20 deletions asctest/array.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
export function test_array(): Array<i32> {
return [42];
}

function test_new_array(): Array<i32> {
var str_arr = new Array<string>(10);
var int_arr = new Array<i32>(10);
return str_arr;
}

function test_length_array(): i32 {
var arr = [1,2,3]
return arr.length;
}

function test_set_array(): void {
var str_arr = new Array<string>(10);
for (let i = 0; i < str_arr.length; ++i) {
str_arr[i] = ""
}
export function test_array(): i32 {
let a = [42]
return a[0];
}
1 change: 1 addition & 0 deletions specs/src/host_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ pub struct HostFunctionDesc {
pub enum HostPlugin {
HostInput = 0,
Sha256,
AssemblyScriptPolyfill,
}
16 changes: 14 additions & 2 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use halo2_proofs::pairing::bn256::Fr as Fp;
use std::fs;
use std::io::Write;
use std::process::exit;
use std::{fmt, fs::File, io::Read, path::PathBuf};
use wasmi::{ExternVal, ImportsBuilder};
use specs::{host_function::HostPlugin, types::ValueType};

use crate::circuits::ZkWasmCircuitBuilder;
use crate::foreign::wasm_input_helper::runtime::register_wasm_input_foreign;
use crate::runtime::host::HostEnv;
use crate::runtime::host::{ForeignContext, HostEnv};
use crate::runtime::{WasmInterpreter, WasmRuntime};

struct Context {}
impl ForeignContext for Context {}
#[derive(Debug, Clone)]
pub struct ArgumentError;

Expand Down Expand Up @@ -63,6 +66,15 @@ pub fn exec(
let private_inputs = parse_args(private_args);

let mut env = HostEnv::new();
env.register_function("abort",
0, Box::new(Context {}),
specs::host_function::Signature {
params: vec![ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32],
return_type: None,
},
Box::new(|_, args| {
exit(-1);
}), HostPlugin::AssemblyScriptPolyfill);
register_wasm_input_foreign(&mut env, public_inputs.clone(), private_inputs.clone());
let imports = ImportsBuilder::new().with_resolver("env", &env);

Expand Down

0 comments on commit 9c232e4

Please sign in to comment.