vyperlang / titanoboa

a vyper interpreter
https://titanoboa.readthedocs.io
Other
236 stars 36 forks source link

local var frame incorrect when revert with reason string is used #14

Open charles-cooper opened 1 year ago

charles-cooper commented 1 year ago

ex.

@external
def foo():
    x: uint256 = 5
    raise "reason"

in the traceback, 32 will be displayed as the value for x since the encoding of the reason string clobbers x.

there are two ways to fix this -- one is a short term fix, which is to optimize the handling of string literals so that the clobbering is not required here: https://github.com/vyperlang/vyper/blob/c71b0238bb8e804072a92f7ebc39cbafdb5da3e7/vyper/codegen/stmt.py#L195-L207

but the longer term issue is that local variables may be aliased in future - they may be deallocated after last use to reduce memory expansion. so we will need a plan to trace variables at the time that they are deallocated.

scherrey commented 1 month ago

This is killing us in terms of being able to diagnose issues inside boa. Any chance this can be remedied any time soon? We've just moved our dev environment to boa and love it compared to ape but this really misled us and continues to hinder our development.

charles-cooper commented 1 month ago

this particular instance should be fixed in vyper v0.4.0 because it now allocates a fresh memory buffer for revert reasons

https://github.com/vyperlang/vyper/pull/3877/files#diff-101e5cf85404fee89bfce1654513063c7e77e87ba130b54975046fa00142fe5aR132

but yea, there are cases where variables can overlap memory (if they have different live ranges), and going forward the optimizer should optimize this more and more aggressively. so we will need some way of approaching that in the future

charles-cooper commented 1 month ago

for <= v0.3.10, dev reasons should help here since they don't overwrite any evm memory