Skip to content

Commit 61c577c

Browse files
authored
Bump nim-eth (#3841)
1 parent 8f31196 commit 61c577c

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

execution_chain/block_access_list/block_access_list_builder.nim

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ type
4343
accounts*: Table[Address, AccountData]
4444
## Maps address -> account data
4545

46-
proc init*(T: type AccountData): T =
46+
template init*(T: type AccountData): T =
4747
AccountData()
4848

4949
# Disallow copying of AccountData
5050
proc `=copy`(dest: var AccountData; src: AccountData) {.error: "Copying AccountData is forbidden".} =
5151
discard
5252

53-
proc init*(T: type BlockAccessListBuilderRef): T =
53+
template init*(T: type BlockAccessListBuilderRef): T =
5454
BlockAccessListBuilderRef()
5555

56-
proc ensureAccount(builder: BlockAccessListBuilderRef, address: Address) =
56+
func ensureAccount(builder: BlockAccessListBuilderRef, address: Address) =
5757
if address notin builder.accounts:
5858
builder.accounts[address] = AccountData.init()
5959

@@ -110,16 +110,19 @@ proc addCodeChange*(
110110
builder.accounts.withValue(address, accData):
111111
accData[].codeChanges[blockAccessIndex] = newCode
112112

113-
proc balIndexCmp(x, y: StorageChange | BalanceChange | NonceChange | CodeChange): int =
113+
func balIndexCmp(x, y: StorageChange | BalanceChange | NonceChange | CodeChange): int =
114114
cmp(x.blockAccessIndex, y.blockAccessIndex)
115115

116-
proc slotCmp(x, y: SlotChanges): int =
117-
cmp(x.slot, y.slot)
116+
func slotCmp(x, y: StorageKey | StorageValue): int =
117+
cmp(x.data.toHex(), y.data.toHex())
118118

119-
proc addressCmp(x, y: AccountChanges): int =
119+
func slotChangesCmp(x, y: SlotChanges): int =
120+
cmp(x.slot.data.toHex(), y.slot.data.toHex())
121+
122+
func addressCmp(x, y: AccountChanges): int =
120123
cmp(x.address.data.toHex(), y.address.data.toHex())
121124

122-
proc buildBlockAccessList*(builder: BlockAccessListBuilderRef): BlockAccessList =
125+
func buildBlockAccessList*(builder: BlockAccessListBuilderRef): BlockAccessList =
123126
var blockAccessList: BlockAccessList
124127

125128
for address, accData in builder.accounts.mpairs():
@@ -129,18 +132,18 @@ proc buildBlockAccessList*(builder: BlockAccessListBuilderRef): BlockAccessList
129132
var slotChanges: seq[StorageChange]
130133

131134
for balIndex, value in changes:
132-
slotChanges.add((BlockAccessIndex(balIndex), StorageValue(value)))
135+
slotChanges.add((BlockAccessIndex(balIndex), StorageValue(value.toBytesBE())))
133136
slotChanges.sort(balIndexCmp)
134137

135-
storageChanges.add((StorageKey(slot), slotChanges))
136-
storageChanges.sort(slotCmp)
138+
storageChanges.add((StorageKey(slot.toBytesBE()), slotChanges))
139+
storageChanges.sort(slotChangesCmp)
137140

138141
# Collect and sort storageReads
139142
var storageReads: seq[StorageKey]
140143
for slot in accData.storageReads:
141144
if slot notin accData.storageChanges:
142-
storageReads.add(slot)
143-
storageReads.sort()
145+
storageReads.add(StorageKey(slot.toBytesBE()))
146+
storageReads.sort(slotCmp)
144147

145148
# Collect and sort balanceChanges
146149
var balanceChanges: seq[BalanceChange]

execution_chain/block_access_list/block_access_list_validation.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ 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())
2123

2224
func validate*(bal: BlockAccessList, expectedHash: Hash32): Result[void, string] =
2325
## Validate that a block access list is structurally correct and matches the expected hash.
@@ -42,7 +44,7 @@ func validate*(bal: BlockAccessList, expectedHash: Hash32): Result[void, string]
4244
for accountChanges in bal:
4345
# Validate storage changes slots are sorted lexicographically
4446
let storageChangesSlots = accountChanges.storageChanges.mapIt(it.slot)
45-
if storageChangesSlots != storageChangesSlots.sorted():
47+
if storageChangesSlots != storageChangesSlots.sorted(slotCmp):
4648
return err("Storage changes slots should be sorted lexicographically")
4749

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

5456
# Validate storage reads are sorted lexicographically
5557
let storageReadsSlots = accountChanges.storageReads
56-
if storageReadsSlots != storageReadsSlots.sorted():
58+
if storageReadsSlots != storageReadsSlots.sorted(slotCmp):
5759
return err("Storage reads should be sorted lexicographically")
5860

5961
# Check balance changes are sorted by blockAccessIndex

tests/test_block_access_list_builder.nim

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

17+
template toBytes32(slot: UInt256): Bytes32 =
18+
Bytes32(slot.toBytesBE())
1719

1820
suite "Block access list builder":
1921
const
@@ -61,12 +63,12 @@ suite "Block access list builder":
6163
bal.len() == 2
6264
bal[0].address == address1
6365
bal[0].storageChanges.len() == 3
64-
bal[0].storageChanges[0] == (slot1, @[(1.BlockAccessIndex, 1.u256)])
65-
bal[0].storageChanges[1] == (slot2, @[(2.BlockAccessIndex, 2.u256)])
66-
bal[0].storageChanges[2] == (slot3, @[(0.BlockAccessIndex, 3.u256), (3.BlockAccessIndex, 5.u256)])
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())])
6769
bal[1].address == address2
6870
bal[1].storageChanges.len() == 1
69-
bal[1].storageChanges[0] == (slot1, @[(1.BlockAccessIndex, 1.u256)])
71+
bal[1].storageChanges[0] == (slot1.toBytes32(), @[(1.BlockAccessIndex, 1.u256.toBytes32())])
7072

7173
test "Add storage read":
7274
builder.addStorageRead(address2, slot3)
@@ -79,11 +81,11 @@ suite "Block access list builder":
7981
check:
8082
bal.len() == 3
8183
bal[0].address == address1
82-
bal[0].storageReads == @[slot1]
84+
bal[0].storageReads == @[slot1.toBytes32()]
8385
bal[1].address == address2
84-
bal[1].storageReads == @[slot2, slot3]
86+
bal[1].storageReads == @[slot2.toBytes32(), slot3.toBytes32()]
8587
bal[2].address == address3
86-
bal[2].storageReads == @[slot3]
88+
bal[2].storageReads == @[slot3.toBytes32()]
8789

8890
test "Add balance change":
8991
builder.addBalanceChange(address2, 1, 0.u256)
@@ -175,23 +177,23 @@ suite "Block access list builder":
175177

176178
bal[0].address == address1
177179
bal[0].storageChanges.len() == 3
178-
bal[0].storageChanges[0] == (slot1, @[(1.BlockAccessIndex, 1.u256)])
179-
bal[0].storageChanges[1] == (slot2, @[(2.BlockAccessIndex, 2.u256)])
180-
bal[0].storageChanges[2] == (slot3, @[(0.BlockAccessIndex, 3.u256), (3.BlockAccessIndex, 5.u256)])
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())])
181183
bal[0].storageReads.len() == 0 # read removed by storage change with the same slot
182184
bal[0].balanceChanges == @[(2.BlockAccessIndex, 10.u256)]
183185
bal[0].nonceChanges == @[(3.BlockAccessIndex, 3.AccountNonce)]
184186
bal[0].codeChanges == @[(3.BlockAccessIndex, @[0x4.byte])]
185187

186188
bal[1].address == address2
187189
bal[1].storageChanges.len() == 1
188-
bal[1].storageChanges[0] == (slot1, @[(1.BlockAccessIndex, 1.u256)])
189-
bal[1].storageReads == @[slot2, slot3]
190+
bal[1].storageChanges[0] == (slot1.toBytes32(), @[(1.BlockAccessIndex, 1.u256.toBytes32())])
191+
bal[1].storageReads == @[slot2.toBytes32(), slot3.toBytes32()]
190192
bal[1].balanceChanges == @[(0.BlockAccessIndex, 1.u256), (1.BlockAccessIndex, 0.u256)]
191193
bal[1].nonceChanges == @[(1.BlockAccessIndex, 1.AccountNonce), (2.BlockAccessIndex, 2.AccountNonce)]
192194
bal[1].codeChanges == @[(0.BlockAccessIndex, @[0x1.byte]), (1.BlockAccessIndex, @[0x2.byte])]
193195

194196
bal[2].address == address3
195-
bal[2].storageReads == @[slot3]
197+
bal[2].storageReads == @[slot3.toBytes32()]
196198
bal[2].balanceChanges == @[(3.BlockAccessIndex, 3.u256)]
197199
bal[2].nonceChanges == @[(1.BlockAccessIndex, 10.AccountNonce)]

tests/test_block_access_list_validation.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ 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())
1820

1921
suite "Block access list validation":
2022
const
@@ -79,7 +81,7 @@ suite "Block access list validation":
7981
builder.addStorageWrite(address1, slot3, 3, 3.u256)
8082

8183
var bal = builder.buildBlockAccessList()
82-
bal[0].storageReads = @[slot1]
84+
bal[0].storageReads = @[slot1.toBytes32()]
8385
check bal.validate(bal.computeBlockAccessListHash()).isErr()
8486

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

vendor/nim-eth

0 commit comments

Comments
 (0)