Fix EIP-2537: Precompile for BLS12-381 curve operations (#2603)
* Fix EIP-2537: Precompile for BLS12-381 curve operations * Update test vectors
This commit is contained in:
parent
838c9854e7
commit
5464f8e5f1
|
@ -8,10 +8,10 @@ PrecompileTests
|
|||
+ blsG1MultiExp.json OK
|
||||
+ blsG2Add.json OK
|
||||
+ blsG2Mul.json OK
|
||||
blsG2MultiExp.json Skip
|
||||
blsMapG1.json Skip
|
||||
blsMapG2.json Skip
|
||||
blsPairing.json Skip
|
||||
+ blsG2MultiExp.json OK
|
||||
+ blsMapG1.json OK
|
||||
+ blsMapG2.json OK
|
||||
+ blsPairing.json OK
|
||||
+ bn256Add.json OK
|
||||
+ bn256Add_istanbul.json OK
|
||||
+ bn256mul.json OK
|
||||
|
@ -25,7 +25,7 @@ PrecompileTests
|
|||
+ ripemd160.json OK
|
||||
+ sha256.json OK
|
||||
```
|
||||
OK: 18/22 Fail: 0/22 Skip: 4/22
|
||||
OK: 22/22 Fail: 0/22 Skip: 0/22
|
||||
|
||||
---TOTAL---
|
||||
OK: 18/22 Fail: 0/22 Skip: 4/22
|
||||
OK: 22/22 Fail: 0/22 Skip: 0/22
|
||||
|
|
|
@ -46,11 +46,10 @@ type
|
|||
paBlsG1MultiExp = 0x0d,
|
||||
paBlsG2Add = 0x0e,
|
||||
paBlsG2Mul = 0x0f,
|
||||
# EIP-2537: disabled; reason: gas price discrepancies, TODO
|
||||
# paBlsG2MultiExp
|
||||
# paBlsPairing
|
||||
# paBlsMapG1
|
||||
# paBlsMapG2
|
||||
paBlsG2MultiExp = 0x10,
|
||||
paBlsPairing = 0x11,
|
||||
paBlsMapG1 = 0x12,
|
||||
paBlsMapG2 = 0x13
|
||||
|
||||
SigRes = object
|
||||
msgHash: array[32, byte]
|
||||
|
@ -389,7 +388,7 @@ func blake2bf(c: Computation): EvmResultVoid =
|
|||
assign(c.output, output)
|
||||
ok()
|
||||
|
||||
func blsG1Add*(c: Computation): EvmResultVoid =
|
||||
func blsG1Add(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -412,7 +411,7 @@ func blsG1Add*(c: Computation): EvmResultVoid =
|
|||
return err(prcErr(PrcInvalidPoint))
|
||||
ok()
|
||||
|
||||
func blsG1Mul*(c: Computation): EvmResultVoid =
|
||||
func blsG1Mul(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -467,7 +466,7 @@ func calcBlsMultiExpGas(K: GasInt, gasCost: GasInt): GasInt =
|
|||
# Calculate gas and return the result
|
||||
result = (K * gasCost * discount) div 1000
|
||||
|
||||
func blsG1MultiExp*(c: Computation): EvmResultVoid =
|
||||
func blsG1MultiExp(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -509,7 +508,7 @@ func blsG1MultiExp*(c: Computation): EvmResultVoid =
|
|||
return err(prcErr(PrcInvalidPoint))
|
||||
ok()
|
||||
|
||||
func blsG2Add*(c: Computation): EvmResultVoid =
|
||||
func blsG2Add(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -532,7 +531,7 @@ func blsG2Add*(c: Computation): EvmResultVoid =
|
|||
return err(prcErr(PrcInvalidPoint))
|
||||
ok()
|
||||
|
||||
func blsG2Mul*(c: Computation): EvmResultVoid =
|
||||
func blsG2Mul(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -556,7 +555,7 @@ func blsG2Mul*(c: Computation): EvmResultVoid =
|
|||
return err(prcErr(PrcInvalidPoint))
|
||||
ok()
|
||||
|
||||
func blsG2MultiExp*(c: Computation): EvmResultVoid =
|
||||
func blsG2MultiExp(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -598,7 +597,7 @@ func blsG2MultiExp*(c: Computation): EvmResultVoid =
|
|||
return err(prcErr(PrcInvalidPoint))
|
||||
ok()
|
||||
|
||||
func blsPairing*(c: Computation): EvmResultVoid =
|
||||
func blsPairing(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -648,7 +647,7 @@ func blsPairing*(c: Computation): EvmResultVoid =
|
|||
c.output[^1] = 1.byte
|
||||
ok()
|
||||
|
||||
func blsMapG1*(c: Computation): EvmResultVoid =
|
||||
func blsMapG1(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -668,7 +667,7 @@ func blsMapG1*(c: Computation): EvmResultVoid =
|
|||
return err(prcErr(PrcInvalidPoint))
|
||||
ok()
|
||||
|
||||
func blsMapG2*(c: Computation): EvmResultVoid =
|
||||
func blsMapG2(c: Computation): EvmResultVoid =
|
||||
template input: untyped =
|
||||
c.msg.data
|
||||
|
||||
|
@ -748,11 +747,10 @@ proc execPrecompiles*(c: Computation, fork: EVMFork): bool =
|
|||
of paBlsG1MultiExp: blsG1MultiExp(c)
|
||||
of paBlsG2Add: blsG2Add(c)
|
||||
of paBlsG2Mul: blsG2Mul(c)
|
||||
# EIP 2537: disabled; gas price changes/discrepancies in test vectors
|
||||
# of paBlsG2MultiExp: blsG2MultiExp(c)
|
||||
# of paBlsPairing: blsPairing(c)
|
||||
# of paBlsMapG1: blsMapG1(c)
|
||||
# of paBlsMapG2: blsMapG2(c)
|
||||
of paBlsG2MultiExp: blsG2MultiExp(c)
|
||||
of paBlsPairing: blsPairing(c)
|
||||
of paBlsMapG1: blsMapG1(c)
|
||||
of paBlsMapG2: blsMapG2(c)
|
||||
|
||||
if res.isErr:
|
||||
if res.error.code == EvmErrorCode.OutOfGas:
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"func": "blsMapG1",
|
||||
"fork": "berlin",
|
||||
"fork": "prague",
|
||||
"data":
|
||||
[
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"func": "blsMapG2",
|
||||
"fork": "berlin",
|
||||
"fork": "prague",
|
||||
"data":
|
||||
[
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"func": "blsPairing",
|
||||
"fork": "berlin",
|
||||
"fork": "prague",
|
||||
"data":
|
||||
[
|
||||
{
|
||||
|
|
|
@ -61,8 +61,8 @@ template doTest(fixture: JsonNode; vmState: BaseVMState; address: PrecompileAddr
|
|||
check fixtureResult.gasUsed == gasExpected.get
|
||||
|
||||
proc parseFork(x: string): string =
|
||||
result = x.capitalizeAscii
|
||||
|
||||
result = x.capitalizeAscii
|
||||
|
||||
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
let
|
||||
label = fixtures["func"].getStr
|
||||
|
@ -91,11 +91,10 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
|||
of "blsg1multiexp" : data.doTest(vmState, paBlsG1MultiExp)
|
||||
of "blsg2add" : data.doTest(vmState, paBlsG2Add)
|
||||
of "blsg2mul" : data.doTest(vmState, paBlsG2Mul)
|
||||
# EIP 2537: disabled due to gas price changes/discprepancies
|
||||
#of "blsg2multiexp": data.doTest(vmState, paBlsG2MultiExp)
|
||||
#of "blspairing": data.doTest(vmState, paBlsPairing)
|
||||
#of "blsmapg1": data.doTest(vmState, paBlsMapG1)
|
||||
#of "blsmapg2": data.doTest(vmState, paBlsMapG2)
|
||||
of "blsg2multiexp": data.doTest(vmState, paBlsG2MultiExp)
|
||||
of "blspairing": data.doTest(vmState, paBlsPairing)
|
||||
of "blsmapg1": data.doTest(vmState, paBlsMapG1)
|
||||
of "blsmapg2": data.doTest(vmState, paBlsMapG2)
|
||||
else:
|
||||
echo "Unknown test vector '" & $label & "'"
|
||||
testStatusIMPL = SKIPPED
|
||||
|
|
Loading…
Reference in New Issue