core/vm, params: rename precompiled to p256verify

pull/27540/head
Ulaş Erdoğan 2 years ago
parent c0554c0764
commit 6c7028a904
  1. 20
      core/vm/contracts.go
  2. 10
      core/vm/contracts_test.go
  3. 2
      core/vm/testdata/precompiles/p256Verify.json
  4. 2
      params/protocol_params.go

@ -105,10 +105,10 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{18}): &bls12381MapG2{}, common.BytesToAddress([]byte{18}): &bls12381MapG2{},
} }
// PrecompiledContractsEcverify contains the precompiled Ethereum // PrecompiledContractsP256Verify contains the precompiled Ethereum
// contract specified in EIP-N. This is exported for testing purposes. // contract specified in EIP-N. This is exported for testing purposes.
var PrecompiledContractsEcverify = map[common.Address]PrecompiledContract{ var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{19}): &ecverify{}, common.BytesToAddress([]byte{19}): &p256Verify{},
} }
var ( var (
@ -1056,22 +1056,22 @@ func (c *bls12381MapG2) Run(input []byte) ([]byte, error) {
return g.EncodePoint(r), nil return g.EncodePoint(r), nil
} }
// ECVERIFY (secp256r1 signature verification) // P256VERIFY (secp256r1 signature verification)
// implemented as a native contract // implemented as a native contract
type ecverify struct{} type p256Verify struct{}
// RequiredGas returns the gas required to execute the precompiled contract // RequiredGas returns the gas required to execute the precompiled contract
func (c *ecverify) RequiredGas(input []byte) uint64 { func (c *p256Verify) RequiredGas(input []byte) uint64 {
return params.EcverifyGas return params.P256VerifyGas
} }
// Run executes the precompiled contract, returning the output and the used gas // Run executes the precompiled contract, returning the output and the used gas
func (c *ecverify) Run(input []byte) ([]byte, error) { func (c *p256Verify) Run(input []byte) ([]byte, error) {
// Required input length is 160 bytes // Required input length is 160 bytes
const ecverifyInputLength = 160 const p256VerifyInputLength = 160
// "input" is (hash, r, s, x, y), each 32 bytes // "input" is (hash, r, s, x, y), each 32 bytes
input = common.RightPadBytes(input, ecverifyInputLength) input = common.RightPadBytes(input, p256VerifyInputLength)
// Extract the hash, r, s, x, y from the input // Extract the hash, r, s, x, y from the input
hash := input[0:32] hash := input[0:32]

@ -65,7 +65,7 @@ var allPrecompiles = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{16}): &bls12381Pairing{}, common.BytesToAddress([]byte{16}): &bls12381Pairing{},
common.BytesToAddress([]byte{17}): &bls12381MapG1{}, common.BytesToAddress([]byte{17}): &bls12381MapG1{},
common.BytesToAddress([]byte{18}): &bls12381MapG2{}, common.BytesToAddress([]byte{18}): &bls12381MapG2{},
common.BytesToAddress([]byte{19}): &ecverify{}, common.BytesToAddress([]byte{19}): &p256Verify{},
} }
// EIP-152 test vectors // EIP-152 test vectors
@ -393,14 +393,14 @@ func BenchmarkPrecompiledBLS12381G2MultiExpWorstCase(b *testing.B) {
benchmarkPrecompiled("0f", testcase, b) benchmarkPrecompiled("0f", testcase, b)
} }
// Benchmarks the sample inputs from the ECVERIFY precompile. // Benchmarks the sample inputs from the P256VERIFY precompile.
func BenchmarkPrecompiledEcverify(bench *testing.B) { func BenchmarkPrecompiledP256Verify(bench *testing.B) {
t := precompiledTest{ t := precompiledTest{
Input: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03", Input: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03",
Expected: "0000000000000000000000000000000000000000000000000000000000000001", Expected: "0000000000000000000000000000000000000000000000000000000000000001",
Name: "ecverify", Name: "p256Verify",
} }
benchmarkPrecompiled("13", t, bench) benchmarkPrecompiled("13", t, bench)
} }
func TestPrecompiledEcverify(t *testing.T) { testJson("ecverify", "13", t) } func TestPrecompiledP256Verify(t *testing.T) { testJson("p256Verify", "13", t) }

@ -3,7 +3,7 @@
"Input": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03", "Input": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03",
"Expected": "0000000000000000000000000000000000000000000000000000000000000001", "Expected": "0000000000000000000000000000000000000000000000000000000000000001",
"Gas": 3450, "Gas": 3450,
"Name": "CallEcverify", "Name": "CallP256Verify",
"NoBenchmark": false "NoBenchmark": false
} }
] ]

@ -155,7 +155,7 @@ const (
Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation
Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation
EcverifyGas uint64 = 3450 // secp256r1 elliptic curve signature verifier gas price P256VerifyGas uint64 = 3450 // secp256r1 elliptic curve signature verifier gas price
// The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529, // The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529,
// up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529 // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529

Loading…
Cancel
Save