fix precompiles selection, GST +5

This commit is contained in:
andri lim 2019-04-02 13:05:42 +07:00
parent 112d2219df
commit 26b40f41e3
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 23 additions and 27 deletions

View File

@ -2377,13 +2377,13 @@ OK: 24/24 Fail: 0/24 Skip: 0/24
ecpairing_two_point_match_5.json Skip ecpairing_two_point_match_5.json Skip
ecpairing_two_point_oog.json Skip ecpairing_two_point_oog.json Skip
ecpairing_two_points_with_one_g2_zero.json Skip ecpairing_two_points_with_one_g2_zero.json Skip
pairingTest.json Skip + pairingTest.json OK
pointAdd.json Skip + pointAdd.json OK
pointAddTrunc.json Skip + pointAddTrunc.json OK
pointMulAdd.json Skip + pointMulAdd.json OK
pointMulAdd2.json Skip + pointMulAdd2.json OK
``` ```
OK: 0/133 Fail: 0/133 Skip: 133/133 OK: 5/133 Fail: 0/133 Skip: 128/133
## stZeroKnowledge2 ## stZeroKnowledge2
```diff ```diff
ecadd_0-0_0-0_21000_0.json Skip 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 OK: 0/130 Fail: 0/130 Skip: 130/130
---TOTAL--- ---TOTAL---
OK: 1433/2334 Fail: 0/2334 Skip: 901/2334 OK: 1438/2334 Fail: 0/2334 Skip: 896/2334

View File

@ -182,15 +182,17 @@ proc applyMessage*(computation: var BaseComputation, opCode: static[Op]) =
if computation.gasMeter.gasRemaining < 0: if computation.gasMeter.gasRemaining < 0:
computation.commit() computation.commit()
return return
let fork = computation.getFork
try: try:
executeOpcodes(computation) if not computation.execPrecompiles(fork):
executeOpcodes(computation)
except: except:
let msg = getCurrentExceptionMsg() let msg = getCurrentExceptionMsg()
computation.setError(&"applyMessage Error msg={msg}, depth={computation.msg.depth}", true) computation.setError(&"applyMessage Error msg={msg}, depth={computation.msg.depth}", true)
if computation.isSuccess and computation.msg.isCreate: if computation.isSuccess and computation.msg.isCreate:
let fork = computation.getFork
let contractFailed = not computation.writeContract(fork) let contractFailed = not computation.writeContract(fork)
if contractFailed and fork == FkHomestead: if contractFailed and fork == FkHomestead:
computation.setError(&"writeContract failed, depth={computation.msg.depth}", true) computation.setError(&"writeContract failed, depth={computation.msg.depth}", true)

View File

@ -247,12 +247,10 @@ macro genHomesteadDispatch(computation: BaseComputation): untyped =
result = opTableToCaseStmt(HomesteadOpDispatch, computation) result = opTableToCaseStmt(HomesteadOpDispatch, computation)
proc frontierVM(computation: var BaseComputation) = proc frontierVM(computation: var BaseComputation) =
if not computation.execPrecompiles: genFrontierDispatch(computation)
genFrontierDispatch(computation)
proc homesteadVM(computation: var BaseComputation) = proc homesteadVM(computation: var BaseComputation) =
if not computation.execPrecompiles: genHomesteadDispatch(computation)
genHomesteadDispatch(computation)
proc executeOpcodes(computation: var BaseComputation) = proc executeOpcodes(computation: var BaseComputation) =
# TODO: Optimise getting fork and updating opCodeExec only when necessary # TODO: Optimise getting fork and updating opCodeExec only when necessary

View File

@ -1,15 +1,16 @@
import 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, ../errors, stint, eth/[keys, common], chronicles, tables, macros,
message, math, nimcrypto, bncurve/[fields, groups] message, math, nimcrypto, bncurve/[fields, groups]
type type
PrecompileAddresses* = enum PrecompileAddresses* = enum
# Frontier to Spurious Dragron
paEcRecover = 1, paEcRecover = 1,
paSha256, paSha256,
paRipeMd160, paRipeMd160,
paIdentity, paIdentity,
# # Byzantium onward
paModExp, paModExp,
paEcAdd, paEcAdd,
paEcMul, paEcMul,
@ -274,12 +275,13 @@ proc bn256ecPairing*(computation: var BaseComputation) =
# computation.gasMeter.consumeGas(gasFee, reason="ecPairing Precompile") # computation.gasMeter.consumeGas(gasFee, reason="ecPairing Precompile")
computation.rawOutput = @output computation.rawOutput = @output
proc execPrecompiles*(computation: var BaseComputation): bool {.inline.} = proc execPrecompiles*(computation: var BaseComputation, fork: Fork): bool {.inline.} =
for i in 0..18: for i in 0..18:
if computation.msg.codeAddress[i] != 0: return if computation.msg.codeAddress[i] != 0: return
let lb = computation.msg.codeAddress[19] 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 result = true
let precompile = PrecompileAddresses(lb) let precompile = PrecompileAddresses(lb)
trace "Call precompile", precompile = precompile, codeAddr = computation.msg.codeAddress trace "Call precompile", precompile = precompile, codeAddr = computation.msg.codeAddress

View File

@ -13,14 +13,8 @@
# being mostly used for short-term regression prevention. # being mostly used for short-term regression prevention.
func allowedFailingGeneralStateTest*(folder, name: string): bool = func allowedFailingGeneralStateTest*(folder, name: string): bool =
let allowedFailingGeneralStateTests = @[ let allowedFailingGeneralStateTests = @[
"randomStatetest14.json", "randomStatetest14.json", # SHA3 offset
"randomStatetest85.json", "randomStatetest85.json", # CALL* memoffset
# 2019-02-17:
"pairingTest.json",
"pointAdd.json",
"pointAddTrunc.json",
"pointMulAdd.json",
"pointMulAdd2.json",
# Homestead recursives # Homestead recursives
"ContractCreationSpam.json", "ContractCreationSpam.json",
"Call1024OOG.json", "Call1024OOG.json",