mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
add slot uniqueness check and test for EIP-7928
This commit is contained in:
parent
344ce84a43
commit
c840b954d3
2 changed files with 36 additions and 0 deletions
|
|
@ -159,6 +159,19 @@ func (e *AccountAccess) validate() error {
|
|||
return errors.New("storage read slots not in lexicographic order")
|
||||
}
|
||||
|
||||
// EIP-7928: a slot must not appear in both storage_changes and storage_reads.
|
||||
if len(e.StorageWrites) > 0 && len(e.StorageReads) > 0 {
|
||||
changeSlots := make(map[common.Hash]struct{}, len(e.StorageWrites))
|
||||
for _, sc := range e.StorageWrites {
|
||||
changeSlots[sc.Slot] = struct{}{}
|
||||
}
|
||||
for _, key := range e.StorageReads {
|
||||
if _, exists := changeSlots[key]; exists {
|
||||
return fmt.Errorf("storage key %s in both changes and reads", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check the balance changes are sorted in order
|
||||
if !slices.IsSortedFunc(e.BalanceChanges, func(a, b encodingBalanceChange) int {
|
||||
return cmp.Compare[uint16](a.TxIdx, b.TxIdx)
|
||||
|
|
|
|||
|
|
@ -252,3 +252,26 @@ func TestBlockAccessListValidation(t *testing.T) {
|
|||
t.Fatalf("Unexpected validation error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockAccessListSlotUniqueness(t *testing.T) {
|
||||
var addr common.Address
|
||||
addr[19] = 0x01
|
||||
slot := common.HexToHash("0x01")
|
||||
|
||||
ac := AccountAccess{
|
||||
Address: addr,
|
||||
StorageWrites: []encodingSlotWrites{
|
||||
{
|
||||
Slot: slot,
|
||||
Accesses: []encodingStorageWrite{
|
||||
{TxIdx: 0, ValueAfter: [32]byte{1}},
|
||||
},
|
||||
},
|
||||
},
|
||||
StorageReads: [][32]byte{slot},
|
||||
}
|
||||
bal := BlockAccessList{[]AccountAccess{ac}}
|
||||
if err := bal.Validate(); err == nil {
|
||||
t.Fatal("expected error for slot in both changes and reads")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue