Skip to content

Commit 79202cc

Browse files
committed
add functions
1 parent d9128b4 commit 79202cc

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

packages/kit/src/oei/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ pub fn get_external_data(eid: i64, vid: i64) -> Result<String, i64> {
6666
}
6767
}
6868
}
69+
70+
/// Return the verification result of ecvrf given a pubkey, a vrf proof, and the
71+
/// corresponding result.
72+
pub fn ecvrf_verify(y: &[u8], pi: &[u8], alpha: &[u8]) -> bool {
73+
unsafe { raw::ecvrf_verify(y, pi, alpha) }
74+
}

packages/kit/src/oei/raw.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ extern "C" {
1010
pub fn ask_external_data(eid: i64, did: i64, offset: i64, len: i64);
1111
pub fn get_external_data_status(eid: i64, vid: i64) -> i64;
1212
pub fn read_external_data(eid: i64, vid: i64, offset: i64) -> i64;
13+
pub fn ecvrf_verify(y: &[u8], pi: &[u8], alpha: &[u8]) -> bool;
1314
}

packages/vm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ hex = "0.4"
1414
parity-wasm = "0.41"
1515
pwasm-utils = "0.12"
1616
wasmer = { version = "1.0.2", default-features = false, features = ["jit", "singlepass", "compiler"] }
17+
owasm-crypto = "0.1.13"
1718
tempfile = "3.1.0"
1819
clru = "0.2.0"
1920
cosmwasm-vm = "0.13.2"

packages/vm/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use pwasm_utils::{self, rules};
1414

1515
use wasmer::{imports, wasmparser, Function, Singlepass, Store, JIT};
1616

17+
use owasm_crypto::{ecvrf_verify}
18+
1719
// inspired by https://github.com/CosmWasm/cosmwasm/issues/81
1820
// 512 pages = 32mb
1921
static MEMORY_LIMIT: u32 = 512; // in pages
@@ -261,6 +263,13 @@ where
261263
Ok(data.len() as i64)
262264
})
263265
}),
266+
"ecvrf_verify" => Function::new_native_with_env(&store, owasm_env.clone(), |env: &Environment<E>, y: &[u8], pi: &[u8], alpha: &[u8]| {
267+
env.with_vm(|vm| {
268+
// consume gas relatively to the function running time (~12ms)
269+
vm.consume_gas(700000)?;
270+
ecvrf_verify(y, pi, alpha)
271+
})
272+
}),
264273
},
265274
};
266275

0 commit comments

Comments
 (0)