accessing memory can't cost less than nothing
This commit is contained in:
parent
9f01223dd2
commit
85e1c39a83
10
VMTests.md
10
VMTests.md
|
@ -406,8 +406,8 @@ OK: 33/52 Fail: 4/52 Skip: 15/52
|
|||
+ deadCode_1.json OK
|
||||
+ dupAt51becameMload.json OK
|
||||
- extcodecopyMemExp.json Fail
|
||||
- for_loop1.json Fail
|
||||
- for_loop2.json Fail
|
||||
+ for_loop1.json OK
|
||||
+ for_loop2.json OK
|
||||
+ gas0.json OK
|
||||
+ gas1.json OK
|
||||
+ gasOverFlow.json OK
|
||||
|
@ -451,7 +451,7 @@ OK: 33/52 Fail: 4/52 Skip: 15/52
|
|||
+ loop_stacklimit_1021.json OK
|
||||
+ memory1.json OK
|
||||
+ mloadError0.json OK
|
||||
- mloadError1.json Fail
|
||||
+ mloadError1.json OK
|
||||
+ mloadMemExp.json OK
|
||||
+ mloadOutOfGasError2.json OK
|
||||
+ msize0.json OK
|
||||
|
@ -472,7 +472,7 @@ OK: 33/52 Fail: 4/52 Skip: 15/52
|
|||
+ pop0.json OK
|
||||
+ pop1.json OK
|
||||
+ return1.json OK
|
||||
- return2.json Fail
|
||||
+ return2.json OK
|
||||
+ sha3MemExp.json OK
|
||||
+ sstore_load_0.json OK
|
||||
+ sstore_load_1.json OK
|
||||
|
@ -483,7 +483,7 @@ OK: 33/52 Fail: 4/52 Skip: 15/52
|
|||
+ swapAt52becameMstore.json OK
|
||||
+ when.json OK
|
||||
```
|
||||
OK: 134/145 Fail: 10/145 Skip: 1/145
|
||||
OK: 138/145 Fail: 6/145 Skip: 1/145
|
||||
## vmLogTest
|
||||
```diff
|
||||
+ log0_emptyMem.json OK
|
||||
|
|
|
@ -124,24 +124,29 @@ template gasCosts(FeeSchedule: GasFeeSchedule, prefix, ResultGasCostsName: untyp
|
|||
# Except when memLength = 0, where per eq (297),
|
||||
# M(currentMemSize, f, l) = currentMemSize
|
||||
|
||||
if memLength == 0:
|
||||
let
|
||||
prev_words = currentMemSize.wordCount
|
||||
new_words = (memOffset + memLength).wordCount
|
||||
|
||||
if memLength == 0 or new_words <= prev_words:
|
||||
# Special subcase of memory-expansion cost
|
||||
# currentMemSize - currentMemSize = 0
|
||||
# "Referencing a zero length range ... does not require memory to be extended
|
||||
# to the beginning of the range."
|
||||
#
|
||||
# Also, don't credit EVM code for allocating memory
|
||||
# then accessing lots of low memory. memoryGasCost,
|
||||
# via go-ethereum, checks for this as special case.
|
||||
return 0
|
||||
|
||||
let
|
||||
prev_words = currentMemSize.wordCount
|
||||
prev_cost = prev_words * static(FeeSchedule[GasMemory]) +
|
||||
(prev_words ^ 2) shr 9 # div 512
|
||||
|
||||
new_words = (memOffset + memLength).wordCount
|
||||
new_cost = new_words * static(FeeSchedule[GasMemory]) +
|
||||
(new_words ^ 2) shr 9 # div 512
|
||||
|
||||
# TODO: add logging
|
||||
result = new_cost - prev_cost
|
||||
result = max(new_cost - prev_cost, 0)
|
||||
|
||||
func `prefix all_but_one_64th`(gas: GasInt): GasInt {.inline.} =
|
||||
## Computes all but 1/64th
|
||||
|
|
Loading…
Reference in New Issue