From 433ccba15f88993d81f044d23773e5db0f939bf5 Mon Sep 17 00:00:00 2001 From: andri lim Date: Sat, 16 Mar 2019 21:42:06 +0700 Subject: [PATCH] fix writePaddedResult, GST +4 --- GeneralStateTests.md | 14 +++++++------- nimbus/vm/interpreter/opcodes_impl.nim | 21 +++++++++------------ tests/test_generalstate_failing.nim | 4 ---- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/GeneralStateTests.md b/GeneralStateTests.md index 7c4a0f887..8faed3f9d 100644 --- a/GeneralStateTests.md +++ b/GeneralStateTests.md @@ -639,10 +639,10 @@ OK: 7/8 Fail: 0/8 Skip: 1/8 OK: 5/38 Fail: 0/38 Skip: 33/38 ## stMemoryTest ```diff - callDataCopyOffset.json Skip ++ callDataCopyOffset.json OK + calldatacopy_dejavu.json OK + calldatacopy_dejavu2.json OK - codeCopyOffset.json Skip ++ codeCopyOffset.json OK + codecopy_dejavu.json OK + codecopy_dejavu2.json OK + extcodecopy_dejavu.json OK @@ -707,7 +707,7 @@ OK: 5/38 Fail: 0/38 Skip: 33/38 + stackLimitPush32_1024.json OK + stackLimitPush32_1025.json OK ``` -OK: 65/67 Fail: 0/67 Skip: 2/67 +OK: 67/67 Fail: 0/67 Skip: 0/67 ## stNonZeroCallsTest ```diff + NonZeroValue_CALL.json OK @@ -974,7 +974,7 @@ OK: 0/16 Fail: 0/16 Skip: 16/16 + randomStatetest112.json OK + randomStatetest114.json OK + randomStatetest115.json OK - randomStatetest116.json Skip ++ randomStatetest116.json OK + randomStatetest117.json OK + randomStatetest118.json OK + randomStatetest119.json OK @@ -1089,7 +1089,7 @@ OK: 0/16 Fail: 0/16 Skip: 16/16 + randomStatetest232.json OK + randomStatetest233.json OK + randomStatetest236.json OK - randomStatetest237.json Skip ++ randomStatetest237.json OK + randomStatetest238.json OK + randomStatetest24.json OK + randomStatetest241.json OK @@ -1284,7 +1284,7 @@ OK: 0/16 Fail: 0/16 Skip: 16/16 + randomStatetest97.json OK + randomStatetest98.json OK ``` -OK: 315/327 Fail: 0/327 Skip: 12/327 +OK: 317/327 Fail: 0/327 Skip: 10/327 ## stRandom2 ```diff + 201503110226PYTHON_DUP6.json OK @@ -2520,4 +2520,4 @@ OK: 0/133 Fail: 0/133 Skip: 133/133 OK: 0/130 Fail: 0/130 Skip: 130/130 ---TOTAL--- -OK: 1230/2334 Fail: 0/2334 Skip: 1104/2334 +OK: 1234/2334 Fail: 0/2334 Skip: 1100/2334 diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index 2caa3a436..4a9eb0ce5 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -220,18 +220,16 @@ proc writePaddedResult(mem: var Memory, data: openarray[byte], memPos, dataPos, len: Natural, paddingValue = 0.byte) = - let prevLen = mem.len + mem.extend(memPos, len) let dataEndPosition = dataPos.int64 + len - 1 let sourceBytes = data[min(dataPos, data.len) .. min(data.len - 1, dataEndPosition)] mem.write(memPos, sourceBytes) - - # geth doesn't do padding, it causes block validation error - when false: - # Don't duplicate zero-padding of mem.extend - let paddingOffset = memPos + sourceBytes.len - # TODO: avoid unnecessary memory allocation - mem.write(paddingOffset, repeat(paddingValue, max(prevLen - paddingOffset, 0))) + + # Don't duplicate zero-padding of mem.extend + let paddingOffset = memPos + sourceBytes.len + # TODO: avoid unnecessary memory allocation + mem.write(paddingOffset, repeat(paddingValue, min(mem.len - paddingOffset, len))) op address, inline = true: ## 0x30, Get address of currently executing account. @@ -257,7 +255,6 @@ op callValue, inline = true: op callDataLoad, inline = false, startPos: ## 0x35, Get input data of current environment - # TODO simplification: https://github.com/status-im/nimbus/issues/67 let dataPos = startPos.cleanMemRef if dataPos >= computation.msg.data.len: push: 0 @@ -295,11 +292,11 @@ op callDataCopy, inline = false, memStartPos, copyStartPos, size: computation.memory.writePaddedResult(computation.msg.data, memPos, copyPos, len) -op codesize, inline = true: +op codeSize, inline = true: ## 0x38, Get size of code running in current environment. push: computation.code.len -op codecopy, inline = false, memStartPos, copyStartPos, size: +op codeCopy, inline = false, memStartPos, copyStartPos, size: ## 0x39, Copy code running in current environment to memory. # TODO tests: https://github.com/status-im/nimbus/issues/67 @@ -344,7 +341,7 @@ op returnDataCopy, inline = false, memStartPos, copyStartPos, size: computation.gasMeter.consumeGas( computation.gasCosts[CodeCopy].m_handler(memPos, copyPos, len), - reason="ExtCodeCopy fee") + reason="returnDataCopy fee") if copyPos + len > computation.returnData.len: # TODO Geth additionally checks copyPos + len < 64 diff --git a/tests/test_generalstate_failing.nim b/tests/test_generalstate_failing.nim index 1964ff9ee..dc17bae68 100644 --- a/tests/test_generalstate_failing.nim +++ b/tests/test_generalstate_failing.nim @@ -48,8 +48,6 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool = "delegatecodeDynamicCode2SelfCall.json", "OutOfGasContractCreation.json", "OutOfGasPrefundedContractCreation.json", - "callDataCopyOffset.json", - "codeCopyOffset.json", "CALLCODEEcrecoverV_prefixedf0.json", "randomStatetest14.json", "randomStatetest184.json", @@ -77,8 +75,6 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool = # 2019-02-07: # 2019-02-15: "randomStatetest101.json", - "randomStatetest116.json", - "randomStatetest237.json", "randomStatetest7.json", # 2019-02-17: "NewGasPriceForCodes.json",