sway icon indicating copy to clipboard operation
sway copied to clipboard

Have a check on how the `__addr_of` intrinsic's result is used

Open vaivaswatha opened this issue 2 years ago • 0 comments

It's possible that we have a contract that has a function taking in an address (u64 value).

contract;
 abi Foo {
    fn bar(addr: u64);
} 

Then we have a script that calls this function bar as below:

script;
use Foo::bar;

fn something() {
    let x : b256 = 0x1111....;
    let x_addr = __addr_of(x);
    bar(x_addr);
}

This (using the address of a local variable in another program) should be statically analysed and disallowed as it violates memory safety (and causes a runtime failure).

vaivaswatha avatar Aug 11 '22 13:08 vaivaswatha