diff --git a/GeneralStateTests.md b/GeneralStateTests.md index f35754bd4..f9b4e6a26 100644 --- a/GeneralStateTests.md +++ b/GeneralStateTests.md @@ -2377,13 +2377,13 @@ OK: 24/24 Fail: 0/24 Skip: 0/24 ecpairing_two_point_match_5.json Skip ecpairing_two_point_oog.json Skip ecpairing_two_points_with_one_g2_zero.json Skip - pairingTest.json Skip - pointAdd.json Skip - pointAddTrunc.json Skip - pointMulAdd.json Skip - pointMulAdd2.json Skip ++ pairingTest.json OK ++ pointAdd.json OK ++ pointAddTrunc.json OK ++ pointMulAdd.json OK ++ pointMulAdd2.json OK ``` -OK: 0/133 Fail: 0/133 Skip: 133/133 +OK: 5/133 Fail: 0/133 Skip: 128/133 ## stZeroKnowledge2 ```diff ecadd_0-0_0-0_21000_0.json Skip @@ -2520,4 +2520,4 @@ OK: 0/133 Fail: 0/133 Skip: 133/133 OK: 0/130 Fail: 0/130 Skip: 130/130 ---TOTAL--- -OK: 1433/2334 Fail: 0/2334 Skip: 901/2334 +OK: 1438/2334 Fail: 0/2334 Skip: 896/2334 diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index a4ebc1717..56c9cf67f 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -182,15 +182,17 @@ proc applyMessage*(computation: var BaseComputation, opCode: static[Op]) = if computation.gasMeter.gasRemaining < 0: computation.commit() return - + + let fork = computation.getFork + try: - executeOpcodes(computation) + if not computation.execPrecompiles(fork): + executeOpcodes(computation) except: let msg = getCurrentExceptionMsg() computation.setError(&"applyMessage Error msg={msg}, depth={computation.msg.depth}", true) - if computation.isSuccess and computation.msg.isCreate: - let fork = computation.getFork + if computation.isSuccess and computation.msg.isCreate: let contractFailed = not computation.writeContract(fork) if contractFailed and fork == FkHomestead: computation.setError(&"writeContract failed, depth={computation.msg.depth}", true) diff --git a/nimbus/vm/interpreter_dispatch.nim b/nimbus/vm/interpreter_dispatch.nim index a4445cc7e..3aff39318 100644 --- a/nimbus/vm/interpreter_dispatch.nim +++ b/nimbus/vm/interpreter_dispatch.nim @@ -247,12 +247,10 @@ macro genHomesteadDispatch(computation: BaseComputation): untyped = result = opTableToCaseStmt(HomesteadOpDispatch, computation) proc frontierVM(computation: var BaseComputation) = - if not computation.execPrecompiles: - genFrontierDispatch(computation) + genFrontierDispatch(computation) proc homesteadVM(computation: var BaseComputation) = - if not computation.execPrecompiles: - genHomesteadDispatch(computation) + genHomesteadDispatch(computation) proc executeOpcodes(computation: var BaseComputation) = # TODO: Optimise getting fork and updating opCodeExec only when necessary diff --git a/nimbus/vm/precompiles.nim b/nimbus/vm/precompiles.nim index 60428e04b..873d00ced 100644 --- a/nimbus/vm/precompiles.nim +++ b/nimbus/vm/precompiles.nim @@ -1,15 +1,16 @@ import - ../vm_types, interpreter/[gas_meter, gas_costs, utils/utils_numeric], + ../vm_types, interpreter/[gas_meter, gas_costs, utils/utils_numeric, vm_forks], ../errors, stint, eth/[keys, common], chronicles, tables, macros, message, math, nimcrypto, bncurve/[fields, groups] type PrecompileAddresses* = enum + # Frontier to Spurious Dragron paEcRecover = 1, paSha256, paRipeMd160, paIdentity, - # + # Byzantium onward paModExp, paEcAdd, paEcMul, @@ -274,12 +275,13 @@ proc bn256ecPairing*(computation: var BaseComputation) = # computation.gasMeter.consumeGas(gasFee, reason="ecPairing Precompile") computation.rawOutput = @output -proc execPrecompiles*(computation: var BaseComputation): bool {.inline.} = +proc execPrecompiles*(computation: var BaseComputation, fork: Fork): bool {.inline.} = for i in 0..18: if computation.msg.codeAddress[i] != 0: return let lb = computation.msg.codeAddress[19] - if lb in PrecompileAddresses.low.byte .. PrecompileAddresses.high.byte: + let maxPrecompileAddr = if fork < FkByzantium: paIdentity else: PrecompileAddresses.high + if lb in PrecompileAddresses.low.byte .. maxPrecompileAddr.byte: result = true let precompile = PrecompileAddresses(lb) trace "Call precompile", precompile = precompile, codeAddr = computation.msg.codeAddress diff --git a/tests/test_generalstate_failing.nim b/tests/test_generalstate_failing.nim index 0b9bc3dc6..fcd00bc1e 100644 --- a/tests/test_generalstate_failing.nim +++ b/tests/test_generalstate_failing.nim @@ -13,14 +13,8 @@ # being mostly used for short-term regression prevention. func allowedFailingGeneralStateTest*(folder, name: string): bool = let allowedFailingGeneralStateTests = @[ - "randomStatetest14.json", - "randomStatetest85.json", - # 2019-02-17: - "pairingTest.json", - "pointAdd.json", - "pointAddTrunc.json", - "pointMulAdd.json", - "pointMulAdd2.json", + "randomStatetest14.json", # SHA3 offset + "randomStatetest85.json", # CALL* memoffset # Homestead recursives "ContractCreationSpam.json", "Call1024OOG.json",