Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blake2b F precompile #4

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bc39c31
Added dependency to github.com/keep-network/blake2-f
pdyraga Jun 17, 2019
6e2b26a
Introduced map of precompiled Istanbul contracts
pdyraga Jun 4, 2019
4d5287c
keep-network/blake2 dependency updated to the newest version
pdyraga Jun 19, 2019
110a5ab
Added Blake2b F function precompile contract
pdyraga Jun 19, 2019
214f72f
Reverted mistakenly modified rootPath in vendor.json
pdyraga Jun 19, 2019
e7fafe2
Accept abi.encodePacked parameters to F precompile
pdyraga Jun 25, 2019
fc1426f
Allow only 213-bytes input in F precompile
pdyraga Jun 25, 2019
5e9c041
Set Blake2b F precompile price to 1gas/round
pdyraga Jun 25, 2019
c2bdb96
Reordered imports
pdyraga Jun 25, 2019
0124f1f
Use blake2FInputLength constant to check the input length
pdyraga Jun 25, 2019
cbd54af
Made blake2FInputLength a constant
pdyraga Jul 1, 2019
b4e46b1
Updaded keep-network/blake2b reference to the newest version
pdyraga Jul 1, 2019
b667e1c
Switched to the new interface of compression.F, updated test vectors
pdyraga Jul 1, 2019
97b4056
Accept rounds parameter as the first one to F precompile
pdyraga Jul 1, 2019
f4b25c5
nonzero f bytes are considered as 'true'
pdyraga Jul 1, 2019
d5ff1ab
Simplified condition assigning a value to `f` parameter
pdyraga Jul 1, 2019
d907056
Gas calculation function reads number of rounds from the first 4 bytes
pdyraga Jul 1, 2019
a8a06f1
Updated blake2b compression lib reference to point to v1.0 release
pdyraga Jul 2, 2019
251a800
Accept h,m,t bytes for BLAKE2b precompile as little-endian
pdyraga Aug 9, 2019
f245982
Replaced generated test vectors with one from BLAKE2b RFC
pdyraga Aug 9, 2019
4877166
Strict validation of the final block indicator flag
pdyraga Aug 13, 2019
0e51e86
Decode test vector with Hex2Bytes before modifying it
pdyraga Aug 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package vm

import (
"crypto/sha256"
"encoding/binary"
"errors"
"math/big"

Expand All @@ -26,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/bn256"
"github.com/ethereum/go-ethereum/params"
"github.com/keep-network/blake2"
"golang.org/x/crypto/ripemd160"
)

Expand Down Expand Up @@ -59,6 +61,20 @@ var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{8}): &bn256Pairing{},
}

// PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum
// contracts used in the Istanbul release.
var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hash{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{},
common.BytesToAddress([]byte{6}): &bn256Add{},
common.BytesToAddress([]byte{7}): &bn256ScalarMul{},
common.BytesToAddress([]byte{8}): &bn256Pairing{},
common.BytesToAddress([]byte{9}): &blake2F{},
}

// RunPrecompiledContract runs and evaluates the output of a precompiled contract.
func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *Contract) (ret []byte, err error) {
gas := p.RequiredGas(input)
Expand Down Expand Up @@ -358,3 +374,68 @@ func (c *bn256Pairing) Run(input []byte) ([]byte, error) {
}
return false32Byte, nil
}

type blake2F struct{}

func (c *blake2F) RequiredGas(input []byte) uint64 {
if len(input) != 213 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If input larger than 213 is used, this will throw. If that's the intended behaviour, then the EIP must also be updated to explicitly state that only exactly 213 bytes is accepted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my intention was to update the EIP to state it explicitly that exactly 213 bytes is accepted. I am not sure if there is any use case for passing more bytes and ignoring some of them. I personally think it's less error-prone to expect the exact length and fail when the length does not match.

pdyraga marked this conversation as resolved.
Show resolved Hide resolved
// Input is malformed, we can't read the number of rounds.
// Precompile can't be executed so we set its price to 0.
return 0
}

rounds := binary.BigEndian.Uint32(input[209:213])
return uint64(rounds)
}

var (
blake2FInputLength = 213
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a const, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it could be:

const blake2FInputLength = 213

var errBlake2FIncorrectInputLength = errors.New(
	"input length for Blake2 F precompile should be exactly 213 bytes",
)

but thought it's better to initialize them in one block, similarly how it's done above the bn256Pairing struct definition. I wasn't sure about the conventions used in the project.

Please let me know what's the preference here and I'll alter it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think const is preferrable, rather than calling it a var just for the sake of indentation...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updated.


errBlake2FIncorrectInputLength = errors.New(
"input length for Blake2 F precompile should be exactly 213 bytes",
)
)

func (c *blake2F) Run(input []byte) ([]byte, error) {
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
if len(input) != 213 {
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
return nil, errBlake2FIncorrectInputLength
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's only used in this place, might as well define the error inline

Suggested change
return nil, errBlake2FIncorrectInputLength
return nil, errors.New("invalid input length for Blake2 F precompile")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also used in tests, see TestPrecompileBlake2FMalformedInput.

}

var h [8]uint64
h[0] = binary.BigEndian.Uint64(input[0:8])
h[1] = binary.BigEndian.Uint64(input[8:16])
h[2] = binary.BigEndian.Uint64(input[16:24])
h[3] = binary.BigEndian.Uint64(input[24:32])
h[4] = binary.BigEndian.Uint64(input[32:40])
h[5] = binary.BigEndian.Uint64(input[40:48])
h[6] = binary.BigEndian.Uint64(input[48:56])
h[7] = binary.BigEndian.Uint64(input[56:64])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EIP needs to specify how to handle cases where the input data is too short. Other precompiles typially return an error in that case. It's very important that such decisions are not left "as implementation details", since it's consensus-critical behaviour.

In this case, the client woud panic if given an input shorter than 64 bytes, afaict

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it to the EIP spec, waiting for the draft and competing PRs to be resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now expect the input to be exactly 213 bytes long.

The PR was opened as an initial implementation before we figure out some details. I should probably open it in a Draft mode.


var m [blake2.BlockSize]byte
copy(m[:], input[64:192])

var t [2]uint64
t[0] = binary.BigEndian.Uint64(input[192:200])
t[1] = binary.BigEndian.Uint64(input[200:208])

var f bool
if input[208] == 0x00000001 {
Copy link

@iikirilov iikirilov Jun 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if input[208] == 0x00000001 {
if input[208] != 0x00000000 {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be checked in a different way, just != 0

f = true
}

rounds := binary.BigEndian.Uint32(input[209:213])

blake2.F(&h, m, t, f, int(rounds))
Copy link

@holiman holiman Jun 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really safe to cast a uint32 to int -- what about 32-bit systems? Will it become negative on 0xffff ffff?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer cast to int - the number of rounds is uint32 everywhere now.


var output [64]byte
binary.BigEndian.PutUint64(output[0:8], h[0])
binary.BigEndian.PutUint64(output[8:16], h[1])
binary.BigEndian.PutUint64(output[16:24], h[2])
binary.BigEndian.PutUint64(output[24:32], h[3])
binary.BigEndian.PutUint64(output[32:40], h[4])
binary.BigEndian.PutUint64(output[40:48], h[5])
binary.BigEndian.PutUint64(output[48:56], h[6])
binary.BigEndian.PutUint64(output[56:64], h[7])

return output[:], nil
}
123 changes: 121 additions & 2 deletions core/vm/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package vm

import (
"crypto/rand"
"encoding/hex"
"fmt"
"math/big"
"reflect"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -32,6 +35,14 @@ type precompiledTest struct {
noBenchmark bool // Benchmark primarily the worst-cases
}

// precompiledFailureTest defines the input/error pairs for precompiled
// contract failure tests.
type precompiledFailureTest struct {
input string
expectedError error
name string
}

// modexpTests are the test and benchmark data for the modexp precompiled contract.
var modexpTests = []precompiledTest{
{
Expand Down Expand Up @@ -336,8 +347,61 @@ var bn256PairingTests = []precompiledTest{
},
}

var blake2FTests = []precompiledTest{
{
input: "6a09e667f2bd8948bb67ae8484caa73b3c6ef372fe94f82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c",
expected: "63b3654623b9ca0757a1474a529433186257ba9deee206e9572365bbce31cea6d3e6d6901c014e1be3c5854bdbbef6de8ccfe917f2bb6643c72c02911aecadad",
name: "testVectors2bX_0",
},
{
input: "6a09e627f3bcc909bb67ae8484caa73b3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179278400340e6b05c5752592c52c4f121292eafc51cc01a997b4aed13409298fad0d99ccc8f76453d9b3661e5c4d325d7751147db17489046d1682d50eefa4a1da00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c",
expected: "d618d21e4ccdda64b147dcca5687459fbf24145ea9091c33416e45229d0972282ea8b80ff6ca078d180efb0a36b08042c068f0ae9ce69f4a7098c8215ee61773",
name: "testVectors2bX_3",
},
{
input: "2b536b65aae1d6731671813c2841a6146b8927a455d1f805ed650cdc3d38b03decbeb55e397687eb59650053fa515f5c817b4cedb190759a7f24f6ba1fc97300808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00000000000001000000000000000000010000000c",
expected: "913105d263890354d07b7868b36d287c2391f54f2d43099882adae97a0345a253672600754921d844010f12d6e9455d383bb247343b1372dbb58369fbc9b2bdf",
name: "testVectors2bX_70",
},
{
input: "6a09e667f2bd8948bb67aea184caa73b3c6ef372fe94f82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c",
expected: "138f26ca8e8b5088415879a35a2c2d7dd95e0929ba0bfe9c8b0ce25db7bce94cdbf1e30c89a2c099ea0da3e8e9ff135368f769a0eaae54da630d9b2ce7272703",
name: "testVectors2bX_140",
},
{
input: "456d45a3841d8a19f16ed318dc09cb4a225593e559ecd4e1c57032c0316e2f08239531a59702945cb52b3fba2f3aa61e55e133554d2f4fd4fc252af7327e80e3808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00000000000001000000000000000000010000000c",
expected: "164a65d708f5ee940fffc9ac7d1ca30083dbe67dfc6623e36b7d5ffd9aa8edca89e32143550f1d81b3297a7dba3ed6097d246f9e82ba2a93d5b908dbaef1384c",
name: "testVectors2bX_230",
},
{
input: "6a09e627f3bcc901bb67aecc84caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179d817fa064689494877e43d757ab1285b4b2a1899cde490442a90071c439a224e7070d3be04b6370df09c77018cf9d989afe1e208a9a35ce951330f210d56364a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c",
expected: "089c3ff02e0c9e934a01d4631722ffbbb1f5d4cc508cdb5510ebbbab022e58b50e585dcd7dbfb1c7a9a01d51a9523d54ec60d2a1a96c1f6690b407054e4d00e3",
name: "testVectors2bX_300",
},
{
input: "6a09e627f3bcc91fbb67aed284caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179a11a4843ebc5ebc5e402d0f0ecf997957a5a01b2bfa6715e67130c95562c6f4d84c64d4bd0fb03698fbb0103aa31c4c1daeb4d727b46074d23756f961141685a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c",
expected: "d38f3c045427b0ff87160b670ad983c7611cfe54558be69c7a8890fd94186323e43ce133de436abdea320274298acd2eef70be64c3277a60a902da3fd06af78e",
name: "testVectors2bX_370",
},
{
input: "6a09e627f3bcc92dbb67aee084caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e217928cdecc6e7e3f0e93591c75513aa862e44adae0a40ce7b8e6c72ea4b47b7c88b832a34cca4d8dbc6f112373f1e82e1d26a58498cfa1ed290e872149667cb2b9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c",
expected: "f1639feeaad03b7ea99e85889b6f7407a26a4095687dbc027d3256ad0c481f1661564b3628ba5b0a8117ea73be040036921ce3b64849a70db05bbaec2ba82c15",
name: "testVectors2bX_440",
},
{
input: "6a09e627f3bcc93bbb67aef684caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e21795f88c38e13dd036e0b6907218d2236f47bfc9ad7ad4478e69c11a4dd69109a5045de7154839b33f604c0f5907ab5e9a916abd7bedaba1dd6635f2850f42038b500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c",
expected: "4c0fa0b3fa95a5ef7eb0ee4c662f9aef6b96582d211917c640cba8d7a7009fcaccfbb7ba7664cf24b2e2f5c3e7d45fee8b459c6581a25a97af1d6e71fd67a709",
name: "testVectors2bX_510",
},
{
input: "6a09e627f3bcc948bb67ae0484caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e21790bc009514bdad0c0331a29252f923da6137d6fd4ba14cb0e9c7cbb0bb1a666d5597d4d8c44612f5a2b12e8e39fa134d96b1d53fa08e48a1ad915bc44040c22ed00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c",
expected: "272539bb30107dea7bf9ef9e3ed75db2c8a0ddb9f37c39ea06c012ed70c8a917e00040c6684905cc1b627d7d9b4e87daa03e2412698679068fe944138ab3c796",
name: "testVectors2bX_580",
},
}

func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
p := PrecompiledContractsByzantium[common.HexToAddress(addr)]
p := PrecompiledContractsIstanbul[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.input)
contract := NewContract(AccountRef(common.HexToAddress("1337")),
nil, new(big.Int), p.RequiredGas(in))
Expand All @@ -350,11 +414,25 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
})
}

func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing.T) {
p := PrecompiledContractsIstanbul[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.input)
contract := NewContract(AccountRef(common.HexToAddress("31337")),
nil, new(big.Int), p.RequiredGas(in))

t.Run(fmt.Sprintf("%s", test.name), func(t *testing.T) {
_, err := RunPrecompiledContract(p, in, contract)
if !reflect.DeepEqual(err, test.expectedError) {
t.Errorf("Expected error [%v], got [%v]", test.expectedError, err)
}
})
}

func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
if test.noBenchmark {
return
}
p := PrecompiledContractsByzantium[common.HexToAddress(addr)]
p := PrecompiledContractsIstanbul[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.input)
reqGas := p.RequiredGas(in)
contract := NewContract(AccountRef(common.HexToAddress("1337")),
Expand Down Expand Up @@ -481,3 +559,44 @@ func BenchmarkPrecompiledBn256Pairing(bench *testing.B) {
benchmarkPrecompiled("08", test, bench)
}
}
func TestPrecompiledBlake2F(t *testing.T) {
for _, test := range blake2FTests {
testPrecompiled("09", test, t)
}
}

func BenchmarkPrecompiledBlake2F(bench *testing.B) {
for _, test := range blake2FTests {
benchmarkPrecompiled("09", test, bench)
}
}

func TestPrecompileBlake2FMalformedInput(t *testing.T) {
bytes212 := make([]byte, 212)
bytes214 := make([]byte, 214)

rand.Read(bytes212)
rand.Read(bytes214)

var tests = []precompiledFailureTest{
{
input: "",
expectedError: errBlake2FIncorrectInputLength,
name: "empty input",
},
{
input: hex.EncodeToString(bytes212),
expectedError: errBlake2FIncorrectInputLength,
name: "less than 213 bytes input",
},
{
input: hex.EncodeToString(bytes214),
expectedError: errBlake2FIncorrectInputLength,
name: "more than 213 bytes input",
},
}

for _, test := range tests {
testPrecompiledFailure("09", test, t)
}
}
6 changes: 6 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
precompiles = PrecompiledContractsByzantium
}
if evm.ChainConfig().IsIstanbul(evm.BlockNumber) {
precompiles = PrecompiledContractsIstanbul
}
if p := precompiles[*contract.CodeAddr]; p != nil {
return RunPrecompiledContract(p, input, contract)
}
Expand Down Expand Up @@ -201,6 +204,9 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
precompiles = PrecompiledContractsByzantium
}
if evm.ChainConfig().IsIstanbul(evm.BlockNumber) {
precompiles = PrecompiledContractsIstanbul
}
if precompiles[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.Sign() == 0 {
// Calling a non existing account, don't do anything, but ping the tracer
if evm.vmConfig.Debug && evm.depth == 0 {
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func New(code string) (*Tracer, error) {
return 1
})
tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int {
_, ok := vm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))]
_, ok := vm.PrecompiledContractsIstanbul[common.BytesToAddress(popSlice(ctx))]
ctx.PushBoolean(ok)
return 1
})
Expand Down
12 changes: 9 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ var (
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil}
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil}

// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Clique consensus.
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}

TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil}
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil}
TestRules = TestChainConfig.Rules(new(big.Int))
)

Expand Down Expand Up @@ -199,6 +199,7 @@ type ChainConfig struct {
ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = already on byzantium)
ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated)
PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople)
IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already activated)
EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated)

// Various consensus engines
Expand Down Expand Up @@ -293,6 +294,11 @@ func (c *ChainConfig) IsPetersburg(num *big.Int) bool {
return isForked(c.PetersburgBlock, num) || c.PetersburgBlock == nil && isForked(c.ConstantinopleBlock, num)
}

// IsIstanbul returns whether num is either equal to the Istanbul fork block or greater.
func (c *ChainConfig) IsIstanbul(num *big.Int) bool {
return isForked(c.IstanbulBlock, num)
}

// IsEWASM returns whether num represents a block number after the EWASM fork
func (c *ChainConfig) IsEWASM(num *big.Int) bool {
return isForked(c.EWASMBlock, num)
Expand Down
27 changes: 27 additions & 0 deletions vendor/github.com/keep-network/blake2/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading