Skip to content

Commit 67d6154

Browse files
authored
Bump nim-eth (#3877)
* Bump nim-eth. * BAL updates for slot change from Bytes32 to UInt256.
1 parent 150ffaa commit 67d6154

File tree

5 files changed

+22
-34
lines changed

5 files changed

+22
-34
lines changed

execution_chain/block_access_list/block_access_list_builder.nim

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,8 @@ proc addCodeChange*(
113113
func balIndexCmp(x, y: StorageChange | BalanceChange | NonceChange | CodeChange): int =
114114
cmp(x.blockAccessIndex, y.blockAccessIndex)
115115

116-
func slotCmp(x, y: StorageKey | StorageValue): int =
117-
cmp(x.data.toHex(), y.data.toHex())
118-
119116
func slotChangesCmp(x, y: SlotChanges): int =
120-
cmp(x.slot.data.toHex(), y.slot.data.toHex())
117+
cmp(x.slot, y.slot)
121118

122119
func addressCmp(x, y: AccountChanges): int =
123120
cmp(x.address.data.toHex(), y.address.data.toHex())
@@ -132,18 +129,18 @@ func buildBlockAccessList*(builder: BlockAccessListBuilderRef): BlockAccessList
132129
var slotChanges: seq[StorageChange]
133130

134131
for balIndex, value in changes:
135-
slotChanges.add((BlockAccessIndex(balIndex), StorageValue(value.toBytesBE())))
132+
slotChanges.add((BlockAccessIndex(balIndex), StorageValue(value)))
136133
slotChanges.sort(balIndexCmp)
137134

138-
storageChanges.add((StorageKey(slot.toBytesBE()), slotChanges))
135+
storageChanges.add((StorageKey(slot), slotChanges))
139136
storageChanges.sort(slotChangesCmp)
140137

141138
# Collect and sort storageReads
142139
var storageReads: seq[StorageKey]
143140
for slot in accData.storageReads:
144141
if slot notin accData.storageChanges:
145-
storageReads.add(StorageKey(slot.toBytesBE()))
146-
storageReads.sort(slotCmp)
142+
storageReads.add(StorageKey(slot))
143+
storageReads.sort()
147144

148145
# Collect and sort balanceChanges
149146
var balanceChanges: seq[BalanceChange]

execution_chain/block_access_list/block_access_list_validation.nim

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import
1818

1919
export block_access_lists, hashes, results
2020

21-
func slotCmp(x, y: StorageKey | StorageValue): int =
22-
cmp(x.data.toHex(), y.data.toHex())
23-
2421
func validate*(bal: BlockAccessList, expectedHash: Hash32): Result[void, string] =
2522
## Validate that a block access list is structurally correct and matches the expected hash.
2623

@@ -44,7 +41,7 @@ func validate*(bal: BlockAccessList, expectedHash: Hash32): Result[void, string]
4441
for accountChanges in bal:
4542
# Validate storage changes slots are sorted lexicographically
4643
let storageChangesSlots = accountChanges.storageChanges.mapIt(it.slot)
47-
if storageChangesSlots != storageChangesSlots.sorted(slotCmp):
44+
if storageChangesSlots != storageChangesSlots.sorted():
4845
return err("Storage changes slots should be sorted lexicographically")
4946

5047
# Check storage changes are sorted by blockAccessIndex
@@ -55,7 +52,7 @@ func validate*(bal: BlockAccessList, expectedHash: Hash32): Result[void, string]
5552

5653
# Validate storage reads are sorted lexicographically
5754
let storageReadsSlots = accountChanges.storageReads
58-
if storageReadsSlots != storageReadsSlots.sorted(slotCmp):
55+
if storageReadsSlots != storageReadsSlots.sorted():
5956
return err("Storage reads should be sorted lexicographically")
6057

6158
# Check balance changes are sorted by blockAccessIndex

tests/test_block_access_list_builder.nim

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import
1414
unittest2,
1515
../execution_chain/block_access_list/block_access_list_builder
1616

17-
template toBytes32(slot: UInt256): Bytes32 =
18-
Bytes32(slot.toBytesBE())
19-
2017
suite "Block access list builder":
2118
const
2219
address1 = address"0x10007bc31cedb7bfb8a345f31e668033056b2728"
@@ -63,12 +60,12 @@ suite "Block access list builder":
6360
bal.len() == 2
6461
bal[0].address == address1
6562
bal[0].storageChanges.len() == 3
66-
bal[0].storageChanges[0] == (slot1.toBytes32(), @[(1.BlockAccessIndex, 1.u256.toBytes32())])
67-
bal[0].storageChanges[1] == (slot2.toBytes32(), @[(2.BlockAccessIndex, 2.u256.toBytes32())])
68-
bal[0].storageChanges[2] == (slot3.toBytes32(), @[(0.BlockAccessIndex, 3.u256.toBytes32()), (3.BlockAccessIndex, 5.u256.toBytes32())])
63+
bal[0].storageChanges[0] == (slot1, @[(1.BlockAccessIndex, 1.u256)])
64+
bal[0].storageChanges[1] == (slot2, @[(2.BlockAccessIndex, 2.u256)])
65+
bal[0].storageChanges[2] == (slot3, @[(0.BlockAccessIndex, 3.u256), (3.BlockAccessIndex, 5.u256)])
6966
bal[1].address == address2
7067
bal[1].storageChanges.len() == 1
71-
bal[1].storageChanges[0] == (slot1.toBytes32(), @[(1.BlockAccessIndex, 1.u256.toBytes32())])
68+
bal[1].storageChanges[0] == (slot1, @[(1.BlockAccessIndex, 1.u256)])
7269

7370
test "Add storage read":
7471
builder.addStorageRead(address2, slot3)
@@ -81,11 +78,11 @@ suite "Block access list builder":
8178
check:
8279
bal.len() == 3
8380
bal[0].address == address1
84-
bal[0].storageReads == @[slot1.toBytes32()]
81+
bal[0].storageReads == @[slot1]
8582
bal[1].address == address2
86-
bal[1].storageReads == @[slot2.toBytes32(), slot3.toBytes32()]
83+
bal[1].storageReads == @[slot2, slot3]
8784
bal[2].address == address3
88-
bal[2].storageReads == @[slot3.toBytes32()]
85+
bal[2].storageReads == @[slot3]
8986

9087
test "Add balance change":
9188
builder.addBalanceChange(address2, 1, 0.u256)
@@ -177,23 +174,23 @@ suite "Block access list builder":
177174

178175
bal[0].address == address1
179176
bal[0].storageChanges.len() == 3
180-
bal[0].storageChanges[0] == (slot1.toBytes32(), @[(1.BlockAccessIndex, 1.u256.toBytes32())])
181-
bal[0].storageChanges[1] == (slot2.toBytes32(), @[(2.BlockAccessIndex, 2.u256.toBytes32())])
182-
bal[0].storageChanges[2] == (slot3.toBytes32(), @[(0.BlockAccessIndex, 3.u256.toBytes32()), (3.BlockAccessIndex, 5.u256.toBytes32())])
177+
bal[0].storageChanges[0] == (slot1, @[(1.BlockAccessIndex, 1.u256)])
178+
bal[0].storageChanges[1] == (slot2, @[(2.BlockAccessIndex, 2.u256)])
179+
bal[0].storageChanges[2] == (slot3, @[(0.BlockAccessIndex, 3.u256), (3.BlockAccessIndex, 5.u256)])
183180
bal[0].storageReads.len() == 0 # read removed by storage change with the same slot
184181
bal[0].balanceChanges == @[(2.BlockAccessIndex, 10.u256)]
185182
bal[0].nonceChanges == @[(3.BlockAccessIndex, 3.AccountNonce)]
186183
bal[0].codeChanges == @[(3.BlockAccessIndex, @[0x4.byte])]
187184

188185
bal[1].address == address2
189186
bal[1].storageChanges.len() == 1
190-
bal[1].storageChanges[0] == (slot1.toBytes32(), @[(1.BlockAccessIndex, 1.u256.toBytes32())])
191-
bal[1].storageReads == @[slot2.toBytes32(), slot3.toBytes32()]
187+
bal[1].storageChanges[0] == (slot1, @[(1.BlockAccessIndex, 1.u256)])
188+
bal[1].storageReads == @[slot2, slot3]
192189
bal[1].balanceChanges == @[(0.BlockAccessIndex, 1.u256), (1.BlockAccessIndex, 0.u256)]
193190
bal[1].nonceChanges == @[(1.BlockAccessIndex, 1.AccountNonce), (2.BlockAccessIndex, 2.AccountNonce)]
194191
bal[1].codeChanges == @[(0.BlockAccessIndex, @[0x1.byte]), (1.BlockAccessIndex, @[0x2.byte])]
195192

196193
bal[2].address == address3
197-
bal[2].storageReads == @[slot3.toBytes32()]
194+
bal[2].storageReads == @[slot3]
198195
bal[2].balanceChanges == @[(3.BlockAccessIndex, 3.u256)]
199196
bal[2].nonceChanges == @[(1.BlockAccessIndex, 10.AccountNonce)]

tests/test_block_access_list_validation.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import
1515
eth/common/block_access_lists_rlp,
1616
../execution_chain/block_access_list/[block_access_list_builder, block_access_list_validation]
1717

18-
template toBytes32(slot: UInt256): Bytes32 =
19-
Bytes32(slot.toBytesBE())
20-
2118
suite "Block access list validation":
2219
const
2320
address1 = address"0x10007bc31cedb7bfb8a345f31e668033056b2728"
@@ -81,7 +78,7 @@ suite "Block access list validation":
8178
builder.addStorageWrite(address1, slot3, 3, 3.u256)
8279

8380
var bal = builder.buildBlockAccessList()
84-
bal[0].storageReads = @[slot1.toBytes32()]
81+
bal[0].storageReads = @[slot1]
8582
check bal.validate(bal.computeBlockAccessListHash()).isErr()
8683

8784
test "Account changes out of order should fail validation":

0 commit comments

Comments
 (0)