Compare commits

...

13 Commits
v1.6.0 ... owi

Author SHA1 Message Date
zach
24622cd511 wip 2024-06-14 18:52:50 -07:00
zach
00f9155b9e feat: switch to owi conc, avoid needing wasm2wat 2024-06-14 18:46:27 -07:00
zach
7c770e2f1c feat(kernel): add proof for error handling 2024-06-14 18:46:27 -07:00
zach
33ad239c50 wip: reuse proof 2024-06-14 18:46:27 -07:00
zach
a62e37c21b cleanup: reduce the size of the allocation used in load_store example 2024-06-14 18:46:27 -07:00
zach
20ee6620c6 cleanup: improve verification 2024-06-14 18:46:27 -07:00
zach
db0b04696c cleanup: move proofs to examples directory 2024-06-14 18:46:27 -07:00
zach
6cc22bf2de cleanup: use new names from owi 2024-06-14 18:46:11 -07:00
zach
52d3c4ffd6 cleanup: add some comments to verification tests 2024-06-14 18:46:11 -07:00
zach
b96b28231f cleanup: ignore verification artifacts 2024-06-14 18:46:11 -07:00
zach
c1180d576c checkpoint: use owi crate from git 2024-06-14 18:46:11 -07:00
zach
48af68facc cleanup: improve owi verification 2024-06-14 18:46:11 -07:00
zach
38e6476797 wip 2024-06-14 18:46:09 -07:00
10 changed files with 144 additions and 3 deletions

3
kernel/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
owi-out
*.wat
proofs

View File

@@ -7,6 +7,7 @@ edition = "2021"
[dev-dependencies]
wasm-bindgen-test = "0.3.39"
owi = {git = "https://github.com/dylibso/owi-rs"}
[features]
default = ["bounds-checking"]
@@ -15,4 +16,4 @@ bounds-checking = []
[workspace]
members = [
"."
]
]

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env bash
set -e
export CARGO_FLAGS=""
while getopts d flag

View File

@@ -0,0 +1,21 @@
#![no_main]
#![no_std]
use extism_runtime_kernel::*;
use owi::*;
main!({
let n = alloc(1024);
let x = u64();
assume(x > 0);
let m = alloc(x);
// 1. Length should equal `x` while active
assert(length(m) == x);
// 2. Length should equal `0` after free
free(m); // Free the block
assert(length(m) == 0);
free(n);
});

24
kernel/examples/error.rs Normal file
View File

@@ -0,0 +1,24 @@
#![no_main]
#![no_std]
use extism_runtime_kernel::*;
use owi::*;
main!({
let x = u64();
let n = u64();
let m = u64();
assume(x > 0);
assume(n > 0);
assume(m > 0);
alloc(n);
alloc(m);
let n = alloc(x);
assert(error_get() == 0);
error_set(n);
assert(error_get() == n);
alloc(m);
error_set(0);
assert(error_get() == 0);
});

View File

@@ -0,0 +1,17 @@
#![no_main]
#![no_std]
use extism_runtime_kernel::*;
use owi::*;
main!({
let x = u64();
assume(x > 0);
let m = alloc(x);
assert(length(m) == x);
for i in 0..x {
store_u8(m + i, i as u8);
assert(load_u8(m + i) == i as u8);
}
free(m);
});

39
kernel/examples/reuse.rs Normal file
View File

@@ -0,0 +1,39 @@
#![no_main]
#![no_std]
use extism_runtime_kernel::*;
use owi::*;
main!({
let x = u64();
assume(x > 0);
let y = u64();
assume(y > 0);
let mut tmp = 0;
for _ in 0..y {
let m = alloc(x);
if tmp == 0 {
tmp = m;
} else {
// Check that the existing block is being re-used
assert(m == tmp);
}
assert(length(m) == x);
free(m); // Free the block
}
let y = u64();
assume(y == x + 1);
let n = alloc(y);
assert(n > tmp);
let z = u64();
assume(z <= x);
assume(x - z < 32);
assume(z > 0);
let p = alloc(z);
assert(p == tmp);
});

View File

@@ -1,5 +1,5 @@
#![no_main]
#![no_std]
#![no_main]
pub use extism_runtime_kernel::*;

View File

@@ -175,7 +175,7 @@ impl MemoryRoot {
core::ptr::write_bytes(
self.blocks.as_mut_ptr() as *mut u8,
MemoryStatus::Unused as u8,
self_position as usize,
self_position as usize - core::mem::size_of::<MemoryRoot>(),
);
// Clear extism runtime metadata
@@ -638,4 +638,15 @@ mod test {
assert_eq!(last, 0);
}
#[wasm_bindgen_test]
fn test_sym() {
unsafe {
reset();
let a = alloc(47);
let b = alloc(20);
assert_eq!(length(a), 47);
assert_eq!(length(b), 20);
}
}
}

23
kernel/verify.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e
OUT_DIR=./target/wasm32-unknown-unknown/release/examples/
get_proof() {
cp "$OUT_DIR/$1.wasm" "./proofs/$1.wasm"
}
cargo build --examples --release --target wasm32-unknown-unknown --no-default-features
mkdir -p proofs
get_proof alloc_length
get_proof load_store
get_proof reuse
get_proof error
for proof in $(ls proofs/*.wasm); do
echo "Checking $proof"
owi conc "$proof" $@
echo
echo "---"
done