Unverified Commit d8aaa3a2 authored by Martin Holst Swende's avatar Martin Holst Swende Committed by Péter Szilágyi

core/vm: benchmarking of metro precompiles

parent 6131dd55
This diff is collapsed.
package vm package vm
import ( import (
"fmt"
"math/big" "math/big"
"testing" "testing"
...@@ -64,126 +63,44 @@ func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contr ...@@ -64,126 +63,44 @@ func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contr
} }
} }
func precompiledBenchmark(addr, input, expected string, gas uint64, bench *testing.B) { func BenchmarkOpAdd64(b *testing.B) {
x := "ffffffff"
y := "fd37f3e2bba2c4f"
contract := NewContract(AccountRef(common.HexToAddress("1337")), opBenchmark(b, opAdd, x, y)
nil, new(big.Int), gas)
p := PrecompiledContractsMetropolis[common.HexToAddress(addr)]
in := common.Hex2Bytes(input)
var (
res []byte
err error
)
data := make([]byte, len(in))
bench.ResetTimer()
for i := 0; i < bench.N; i++ {
contract.Gas = gas
copy(data, in)
res, err = RunPrecompiledContract(p, data, contract)
}
bench.StopTimer()
//Check if it is correct
if err != nil {
bench.Error(err)
return
}
if common.Bytes2Hex(res) != expected {
bench.Error(fmt.Sprintf("Expected %v, got %v", expected, common.Bytes2Hex(res)))
return
}
}
func BenchmarkPrecompiledECDSA(bench *testing.B) {
var (
addr = "01"
inp = "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
exp = "000000000000000000000000ceaccac640adf55b2028469bd36ba501f28b699d"
gas = uint64(4000000)
)
precompiledBenchmark(addr, inp, exp, gas, bench)
}
func BenchmarkPrecompiledSha256(bench *testing.B) {
var (
addr = "02"
inp = "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
exp = "811c7003375852fabd0d362e40e68607a12bdabae61a7d068fe5fdd1dbbf2a5d"
gas = uint64(4000000)
)
precompiledBenchmark(addr, inp, exp, gas, bench)
} }
func BenchmarkPrecompiledRipeMD(bench *testing.B) { func BenchmarkOpAdd128(b *testing.B) {
var ( x := "ffffffffffffffff"
addr = "03" y := "f5470b43c6549b016288e9a65629687"
inp = "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
exp = "0000000000000000000000009215b8d9882ff46f0dfde6684d78e831467f65e6"
gas = uint64(4000000)
)
precompiledBenchmark(addr, inp, exp, gas, bench)
}
func BenchmarkPrecompiledIdentity(bench *testing.B) { opBenchmark(b, opAdd, x, y)
var (
addr = "04"
inp = "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
exp = "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
gas = uint64(4000000)
)
precompiledBenchmark(addr, inp, exp, gas, bench)
} }
func BenchmarkPrecompiledModExp(bench *testing.B) { func BenchmarkOpAdd256(b *testing.B) {
var ( x := "0802431afcbce1fc194c9eaa417b2fb67dc75a95db0bc7ec6b1c8af11df6a1da9"
addr = "05" y := "a1f5aac137876480252e5dcac62c354ec0d42b76b0642b6181ed099849ea1d57"
inp = "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"
exp = "0000000000000000000000000000000000000000000000000000000000000001"
gas = uint64(4000000)
)
precompiledBenchmark(addr, inp, exp, gas, bench)
}
func BenchmarkPrecompiledBn256Add(bench *testing.B) { opBenchmark(b, opAdd, x, y)
var (
addr = "06"
inp = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
exp = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
gas = uint64(4000000)
)
precompiledBenchmark(addr, inp, exp, gas, bench)
} }
func BenchmarkPrecompiledBn256ScalarMul(bench *testing.B) { func BenchmarkOpSub64(b *testing.B) {
var ( x := "51022b6317003a9d"
addr = "07" y := "a20456c62e00753a"
inp = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
exp = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
gas = uint64(4000000)
)
precompiledBenchmark(addr, inp, exp, gas, bench)
}
func BenchmarkPrecompiledBn256Pairing(bench *testing.B) { opBenchmark(b, opSub, x, y)
var (
addr = "08"
inp = "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa"
exp = "0000000000000000000000000000000000000000000000000000000000000001"
gas = uint64(4000000)
)
precompiledBenchmark(addr, inp, exp, gas, bench)
} }
func BenchmarkOpAdd(b *testing.B) { func BenchmarkOpSub128(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := "4dde30faaacdc14d00327aac314e915d"
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := "9bbc61f5559b829a0064f558629d22ba"
opBenchmark(b, opAdd, x, y) opBenchmark(b, opSub, x, y)
} }
func BenchmarkOpSub(b *testing.B) { func BenchmarkOpSub256(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := "4bfcd8bb2ac462735b48a17580690283980aa2d679f091c64364594df113ea37"
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := "97f9b1765588c4e6b69142eb00d20507301545acf3e1238c86c8b29be227d46e"
opBenchmark(b, opSub, x, y) opBenchmark(b, opSub, x, y)
} }
...@@ -195,16 +112,27 @@ func BenchmarkOpMul(b *testing.B) { ...@@ -195,16 +112,27 @@ func BenchmarkOpMul(b *testing.B) {
opBenchmark(b, opMul, x, y) opBenchmark(b, opMul, x, y)
} }
func BenchmarkOpDiv(b *testing.B) { func BenchmarkOpDiv256(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := "ff3f9014f20db29ae04af2c2d265de17"
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
opBenchmark(b, opDiv, x, y)
}
func BenchmarkOpDiv128(b *testing.B) {
x := "fdedc7f10142ff97"
y := "fbdfda0e2ce356173d1993d5f70a2b11"
opBenchmark(b, opDiv, x, y)
}
func BenchmarkOpDiv64(b *testing.B) {
x := "fcb34eb3"
y := "f97180878e839129"
opBenchmark(b, opDiv, x, y) opBenchmark(b, opDiv, x, y)
} }
func BenchmarkOpSdiv(b *testing.B) { func BenchmarkOpSdiv(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := "ff3f9014f20db29ae04af2c2d265de17"
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611"
opBenchmark(b, opSdiv, x, y) opBenchmark(b, opSdiv, x, y)
} }
...@@ -315,12 +243,3 @@ func BenchmarkOpMulmod(b *testing.B) { ...@@ -315,12 +243,3 @@ func BenchmarkOpMulmod(b *testing.B) {
opBenchmark(b, opMulmod, x, y, z) opBenchmark(b, opMulmod, x, y, z)
} }
//func BenchmarkOpSha3(b *testing.B) {
// x := "0"
// y := "32"
//
// opBenchmark(b,opSha3, x, y)
//
//
//}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment