ethereum / evmone

Fast Ethereum Virtual Machine implementation
Apache License 2.0
865 stars 287 forks source link

precompiles: Improve output buffer handling #951

Closed chfast closed 4 months ago

chfast commented 4 months ago

Replace the fixed-size on-stack temporary buffer for precompiles with a heap-allocated buffer big enough to handle properly any precompile invocation.

This actually keeps the number of allocations the same. Previously the contents of the on-stack buffer were copied to heap by the Result constructor. Now we are creating the heap buffer in the first place and pass the ownership of it to the Result.

This fixes out-of-bounds memory accesses often being found by fuzzers.

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.29%. Comparing base (70ca837) to head (e186095).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #951 +/- ## ======================================= Coverage 94.29% 94.29% ======================================= Files 143 143 Lines 16119 16120 +1 ======================================= + Hits 15199 15200 +1 Misses 920 920 ``` | [Flag](https://app.codecov.io/gh/ethereum/evmone/pull/951/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | Coverage Δ | | |---|---|---| | [eof_execution_spec_tests](https://app.codecov.io/gh/ethereum/evmone/pull/951/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `16.65% <0.00%> (-0.01%)` | :arrow_down: | | [ethereum_tests](https://app.codecov.io/gh/ethereum/evmone/pull/951/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `26.99% <100.00%> (+<0.01%)` | :arrow_up: | | [ethereum_tests_silkpre](https://app.codecov.io/gh/ethereum/evmone/pull/951/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `18.71% <100.00%> (+<0.01%)` | :arrow_up: | | [execution_spec_tests](https://app.codecov.io/gh/ethereum/evmone/pull/951/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `17.98% <100.00%> (+<0.01%)` | :arrow_up: | | [unittests](https://app.codecov.io/gh/ethereum/evmone/pull/951/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `89.66% <0.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/ethereum/evmone/pull/951?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | Coverage Δ | | |---|---|---| | [test/state/precompiles.cpp](https://app.codecov.io/gh/ethereum/evmone/pull/951?src=pr&el=tree&filepath=test%2Fstate%2Fprecompiles.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum#diff-dGVzdC9zdGF0ZS9wcmVjb21waWxlcy5jcHA=) | `100.00% <100.00%> (ø)` | |