mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-24 19:19:21 +00:00
modexp cleanup
This commit is contained in:
parent
b7a1431c33
commit
077fbe6b73
@ -394,7 +394,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
||||
+ call_then_create2_successful_then_returndatasize.json OK
|
||||
+ create2InitCodes.json OK
|
||||
+ create2SmartInitCode.json OK
|
||||
create2callPrecompiles.json Skip
|
||||
+ create2callPrecompiles.json OK
|
||||
+ create2checkFieldsInInitcode.json OK
|
||||
+ create2collisionBalance.json OK
|
||||
+ create2collisionCode.json OK
|
||||
@ -413,7 +413,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
||||
+ returndatacopy_following_successful_create.json OK
|
||||
+ returndatasize_following_successful_create.json OK
|
||||
```
|
||||
OK: 41/44 Fail: 0/44 Skip: 3/44
|
||||
OK: 42/44 Fail: 0/44 Skip: 2/44
|
||||
## stCreateTest
|
||||
```diff
|
||||
+ CREATE_AcreateB_BSuicide_BStore.json OK
|
||||
@ -2645,4 +2645,4 @@ OK: 133/133 Fail: 0/133 Skip: 0/133
|
||||
OK: 130/130 Fail: 0/130 Skip: 0/130
|
||||
|
||||
---TOTAL---
|
||||
OK: 2342/2447 Fail: 0/2447 Skip: 105/2447
|
||||
OK: 2343/2447 Fail: 0/2447 Skip: 104/2447
|
||||
|
@ -133,10 +133,6 @@ proc identity*(computation: BaseComputation) =
|
||||
proc modExpInternal(computation: BaseComputation, base_len, exp_len, mod_len: int, T: type StUint) =
|
||||
template rawMsg: untyped {.dirty.} =
|
||||
computation.msg.data
|
||||
let
|
||||
base = rawMsg.rangeToPadded[:T](96, 95 + base_len, base_len)
|
||||
exp = rawMsg.rangeToPadded[:T](96 + base_len, 95 + base_len + exp_len, exp_len)
|
||||
modulo = rawMsg.rangeToPadded[:T](96 + base_len + exp_len, 95 + base_len + exp_len + mod_len, mod_len)
|
||||
|
||||
block: # Gas cost
|
||||
func gasModExp_f(x: Natural): int =
|
||||
@ -170,6 +166,11 @@ proc modExpInternal(computation: BaseComputation, base_len, exp_len, mod_len: in
|
||||
computation.gasMeter.consumeGas(gasFee, reason="ModExp Precompile")
|
||||
|
||||
block: # Processing
|
||||
let
|
||||
base = rawMsg.rangeToPadded[:T](96, 95 + base_len, base_len)
|
||||
exp = rawMsg.rangeToPadded[:T](96 + base_len, 95 + base_len + exp_len, exp_len)
|
||||
modulo = rawMsg.rangeToPadded[:T](96 + base_len + exp_len, 95 + base_len + exp_len + mod_len, mod_len)
|
||||
|
||||
# TODO: specs mentions that we should return in "M" format
|
||||
# i.e. if Base and exp are uint512 and Modulo an uint256
|
||||
# we should return a 256-bit big-endian byte array
|
||||
@ -187,11 +188,11 @@ proc modExpInternal(computation: BaseComputation, base_len, exp_len, mod_len: in
|
||||
# If m == 0: EVM returns 0.
|
||||
# If m == 1: we can shortcut that to 0 as well
|
||||
zero()
|
||||
elif exp.isZero():
|
||||
elif exp.isZero():
|
||||
# If 0^0: EVM returns 1
|
||||
# For all x != 0, x^0 == 1 as well
|
||||
one()
|
||||
else:
|
||||
else:
|
||||
powmod(base, exp, modulo).toByteArrayBE
|
||||
|
||||
# maximum output len is the same as mod_len
|
||||
@ -209,6 +210,7 @@ proc modExp*(computation: BaseComputation) =
|
||||
# Parsing the data
|
||||
template rawMsg: untyped {.dirty.} =
|
||||
computation.msg.data
|
||||
|
||||
let # lengths Base, Exponent, Modulus
|
||||
base_len = rawMsg.rangeToPadded[:Uint256](0, 31).safeInt
|
||||
exp_len = rawMsg.rangeToPadded[:Uint256](32, 63).safeInt
|
||||
|
@ -14,7 +14,6 @@
|
||||
func allowedFailingGeneralStateTest*(folder, name: string): bool =
|
||||
let allowedFailingGeneralStateTests = @[
|
||||
"modexp.json",
|
||||
"create2callPrecompiles.json",
|
||||
"create2noCash.json",
|
||||
]
|
||||
result = name in allowedFailingGeneralStateTests
|
||||
|
Loading…
x
Reference in New Issue
Block a user