cssl-unist / trust-sec23

7 stars 1 forks source link

Adding an example program #2

Closed kiyoakii closed 10 months ago

kiyoakii commented 10 months ago

Hi!

I'm wondering if you can provide an example showing how one can compile a simple rust project using trust runtime, and compare the compiled program with the original one without trust's protection.

For example, for the code mentioned in the Figure 5 of the paper, I wrote the following example

// main.rs
fn read_vec(idx: usize, vec: &mut Vec<i32>) {
    unsafe { vec.set_len(idx + 1); }
    vec[idx] = 256;
    println!("The container has been hacked: {}", vec[idx]);
}

fn main() {
    let mut v = Vec::with_capacity(10);
    read_vec(12, &mut v);
}

When I cargo run it with rustup toolchain set up as trust, I get The container has been hacked: 256