Skip to content

core: implement eip-7981: Increase Access List Cost - #34755

Merged
MariusVanDerWijden merged 3 commits into
ethereum:masterfrom
MariusVanDerWijden:eip-7981
May 6, 2026
Merged

core: implement eip-7981: Increase Access List Cost#34755
MariusVanDerWijden merged 3 commits into
ethereum:masterfrom
MariusVanDerWijden:eip-7981

Conversation

@MariusVanDerWijden

Copy link
Copy Markdown
Member

Comment thread core/state_transition.go
if accessList != nil {
gas += uint64(len(accessList)) * params.TxAccessListAddressGas
gas += uint64(accessList.StorageKeys()) * params.TxAccessListStorageKeyGas
// EIP-7981: access list data is charged in addition to the base charge.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how we can get rid of the overflow checking, but apparently the validation is missing here.

diff --git a/core/state_transition.go b/core/state_transition.go
index 3f7ec50f5b..e7b06a96ed 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -107,12 +107,31 @@ func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Set
 		}
 	}
 	if accessList != nil {
-		gas += uint64(len(accessList)) * params.TxAccessListAddressGas
-		gas += uint64(accessList.StorageKeys()) * params.TxAccessListStorageKeyGas
+		addresses := uint64(len(accessList))
+		storageKeys := uint64(accessList.StorageKeys())
+		if (math.MaxUint64-gas)/params.TxAccessListAddressGas < addresses {
+			return 0, ErrGasUintOverflow
+		}
+		gas += addresses * params.TxAccessListAddressGas
+		if (math.MaxUint64-gas)/params.TxAccessListStorageKeyGas < storageKeys {
+			return 0, ErrGasUintOverflow
+		}
+		gas += storageKeys * params.TxAccessListStorageKeyGas
+
 		// EIP-7981: access list data is charged in addition to the base charge.
 		if isAmsterdam {
-			gas += uint64(len(accessList)) * common.AddressLength * params.TxCostFloorPerToken7976 * params.TxTokenPerNonZeroByte
-			gas += uint64(accessList.StorageKeys()) * common.HashLength * params.TxCostFloorPerToken7976 * params.TxTokenPerNonZeroByte
+			const (
+				addressCost    = common.AddressLength * params.TxCostFloorPerToken7976 * params.TxTokenPerNonZeroByte
+				storageKeyCost = common.HashLength * params.TxCostFloorPerToken7976 * params.TxTokenPerNonZeroByte
+			)
+			if (math.MaxUint64-gas)/addressCost < addresses {
+				return 0, ErrGasUintOverflow
+			}
+			gas += addresses * addressCost
+			if (math.MaxUint64-gas)/storageKeyCost < storageKeys {
+				return 0, ErrGasUintOverflow
+			}
+			gas += storageKeys * storageKeyCost
 		}
 	}
 	if authList != nil {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense

@rjl493456442

Copy link
Copy Markdown
Member

Please rebase and address the comments i left.

@fjl fjl self-assigned this Apr 21, 2026
Comment thread core/state_transition.go

// Check for overflow
if (math.MaxUint64-params.TxGas)/params.TxCostFloorPerToken < tokens {
if (math.MaxUint64-params.TxGas)/tokenCost < tokens {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overflow check here seems a bit over-protective. The overflow could only happen if len(data) is very large. But if we were worried about that happening, we would have to check for overflow also in the code above where we calculate based on len(data). Checking for overflow only here is just weird.

@rjl493456442 rjl493456442 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MariusVanDerWijden
MariusVanDerWijden merged commit aaa2b66 into ethereum:master May 6, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants