titanoboa icon indicating copy to clipboard operation
titanoboa copied to clipboard

local var frame incorrect when revert with reason string is used

Open charles-cooper opened this issue 3 years ago • 3 comments
trafficstars

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.

charles-cooper avatar Aug 10 '22 17:08 charles-cooper

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.

scherrey avatar May 31 '24 12:05 scherrey

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 avatar May 31 '24 12:05 charles-cooper

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

charles-cooper avatar May 31 '24 12:05 charles-cooper