Truncate BALANCE opcode parameter for witness recording #397
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR was found by running our replay code in the latest changes.
The run had a panic at this line, since
20-len(addr)
was negative which is an illegal index access. For context, we changed this line some days ago in #366.That PR fix was fine since it fixes cases where
addr
length is less than 20. If we don't do20-len(addr)
, the alignment is wrong. But the situation here is the inverse, ifaddr
is longer than 20 bytes then we have this panic. From where this came from, it was theBALANCE
opcode.The value of
BALANCE
is a 32-byte value that must be truncated for a correct interpretation of the address (since no address can be 32 bytes anyway). This isn't always a problem since.Bytes()
(old code line) truncates the value, removing the left-zeroes. But if the value is, for whatever reason, longer than 20 bytes, it can cause this panic. As in, most of the time the contractBALANCE
parameter will be a 20-byte address (or smaller) since it's actually what it's expected semantically, but for weird cases where a potential arbitrary >20 byte value is provided is when this bug is triggered. (This is why this bug hasn't happened before)