ethereum / py-evm

A Python implementation of the Ethereum Virtual Machine
https://py-evm.readthedocs.io/en/latest/
MIT License
2.22k stars 637 forks source link

fix: msg.data mutability #2140

Closed charles-cooper closed 4 months ago

charles-cooper commented 4 months ago

this commit modifies msg.data so that it is an immutable bytes copy of the input. the issue is that right now it is a view of memory, which means the caller can trample the msg.data buffer after the call returns (and msg.data gets mutated). this is not necessarily a problem for the VM correctness, but it is an issue for integrators that inspect msg.data after a call, because msg.data will not retain its original value.

as a refactor, since Computation.memory_read() is completely dead (and more importantly, probably a footgun), this commit also removes memory_read() from the ComputationAPI interface as well as the Computation implementation.

What was wrong?

Related to Issue # Closes #

How was it fixed?

Todo:

Cute Animal Picture

charles-cooper commented 4 months ago

we could also get rid of Message.data_as_bytes() since it doesn't do anything additional now besides just return the Message.data bytes object, but it would be a hygiene thing.

$ python
Python 3.10.12 (main, Jul  7 2023, 18:23:44) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s = b"12345"
>>> t = bytes(s)
>>> id(t), id(s)
(139843084676256, 139843084676256)