Skip to content

use safe arithmetic wherever gas calculations can cause U256 to overflow#344

Merged
SamWilsn merged 1 commit intoethereum:masterfrom
voith:safe-gas-arithmetic
Sep 16, 2021
Merged

use safe arithmetic wherever gas calculations can cause U256 to overflow#344
SamWilsn merged 1 commit intoethereum:masterfrom
voith:safe-gas-arithmetic

Conversation

@voith
Copy link
Contributor

@voith voith commented Sep 16, 2021

What was wrong?

Related to Issue #342

#342 introduced safe arithmetic for handling gas calculations that could overflow U256. There are several more places where gas calculations can cause U256 to overflow.

How was it fixed?

Used safe arithmetic wherever gas calculations can cause U256 to overflow.

Note:

The Yellow paper says that the "data" size is unlimited:
Screenshot 2021-09-16 at 3 23 58 PM
There are some precompiles that calculate gas cost based on the input data size. This is the reason why u256_safe_add and u256_safe_multiply have been modified to accept Uint as input.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

Pic credits: pexels.com

@codecov-commenter
Copy link

Codecov Report

Merging #344 (7678500) into master (dace4e5) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #344      +/-   ##
==========================================
+ Coverage   95.04%   95.10%   +0.06%     
==========================================
  Files          46       46              
  Lines        2322     2351      +29     
==========================================
+ Hits         2207     2236      +29     
  Misses        115      115              
Flag Coverage Δ
unittests 95.10% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/ethereum/frontier/vm/instructions/environment.py 98.93% <100.00%> (+0.09%) ⬆️
src/ethereum/frontier/vm/instructions/keccak.py 100.00% <100.00%> (ø)
src/ethereum/frontier/vm/instructions/memory.py 100.00% <100.00%> (ø)
src/ethereum/frontier/vm/instructions/system.py 89.85% <100.00%> (+0.22%) ⬆️
...reum/frontier/vm/precompiled_contracts/identity.py 100.00% <100.00%> (ø)
...eum/frontier/vm/precompiled_contracts/ripemd160.py 100.00% <100.00%> (ø)
...hereum/frontier/vm/precompiled_contracts/sha256.py 100.00% <100.00%> (ø)
src/ethereum/utils/safe_arithmetic.py 73.68% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dace4e5...7678500. Read the comment docs.

@SamWilsn SamWilsn merged commit 68f20b8 into ethereum:master Sep 16, 2021
@voith voith deleted the safe-gas-arithmetic branch September 16, 2021 12:42
Carsons-Eels pushed a commit to Carsons-Eels/execution-specs that referenced this pull request Oct 16, 2025
danceratopz added a commit to danceratopz/execution-specs that referenced this pull request Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants