From 9956fdfc99643cd19a36b1775a74614401177a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Mon, 8 May 2023 04:11:54 +0300 Subject: [PATCH 01/49] crypto/secp2561r1: add secp256r1 curve verifiers (cherry picked from commit fb89b61cdc2ccf6bda9f77f72315e01fa4ffb7d7) --- crypto/secp256r1/publickey.go | 21 +++++++++++++++++++ crypto/secp256r1/verifier.go | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 crypto/secp256r1/publickey.go create mode 100644 crypto/secp256r1/verifier.go diff --git a/crypto/secp256r1/publickey.go b/crypto/secp256r1/publickey.go new file mode 100644 index 0000000000..c92afaa1e0 --- /dev/null +++ b/crypto/secp256r1/publickey.go @@ -0,0 +1,21 @@ +package secp256r1 + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "math/big" +) + +// Generates approptiate public key format from given coordinates +func newPublicKey(x, y *big.Int) *ecdsa.PublicKey { + // Check if the given coordinates are valid + if x == nil || y == nil || !elliptic.P256().IsOnCurve(x, y) { + return nil + } + + return &ecdsa.PublicKey{ + Curve: elliptic.P256(), + X: x, + Y: y, + } +} diff --git a/crypto/secp256r1/verifier.go b/crypto/secp256r1/verifier.go new file mode 100644 index 0000000000..67a0dd787d --- /dev/null +++ b/crypto/secp256r1/verifier.go @@ -0,0 +1,39 @@ +package secp256r1 + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "errors" + "math/big" + + "github.com/ethereum/go-ethereum/common" +) + +var ( + secp256k1halfN = new(big.Int).Div(elliptic.P256().Params().N, big.NewInt(2)) +) + +// Verifies the given signature (r, s) for the given hash and public key (x, y). +func Verify(hash []byte, r, s, x, y *big.Int) ([]byte, error) { + // Create the public key format + publicKey := newPublicKey(x, y) + if publicKey == nil { + return nil, errors.New("invalid public key coordinates") + } + + if checkMalleability(s) { + return nil, errors.New("malleability issue") + } + + // Verify the signature with the public key and return 1 if it's valid, 0 otherwise + if ok := ecdsa.Verify(publicKey, hash, r, s); ok { + return common.LeftPadBytes(common.Big1.Bytes(), 32), nil + } + + return common.LeftPadBytes(common.Big0.Bytes(), 32), nil +} + +// Check the malleability issue +func checkMalleability(s *big.Int) bool { + return s.Cmp(secp256k1halfN) <= 0 +} From cdb96096d890880aac45eaaf7ad96e72f284cbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Mon, 8 May 2023 04:12:57 +0300 Subject: [PATCH 02/49] core/vm: implement secp256r1 verifier precompiled (cherry picked from commit a8c0a2e05c7b6cafa16d296f91da8cb651bf9d46) --- core/vm/contracts.go | 55 ++++++++++++++++++---- core/vm/contracts_test.go | 13 +++++ core/vm/testdata/precompiles/ecverify.json | 9 ++++ 3 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 core/vm/testdata/precompiles/ecverify.json diff --git a/core/vm/contracts.go b/core/vm/contracts.go index ba7539737c..d5375be753 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/crypto/blake2b" "github.com/ethereum/go-ethereum/crypto/bls12381" "github.com/ethereum/go-ethereum/crypto/bn256" + "github.com/ethereum/go-ethereum/crypto/secp256r1" "github.com/ethereum/go-ethereum/params" "golang.org/x/crypto/ripemd160" ) @@ -79,15 +80,15 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ // PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum // contracts used in the Berlin release. var PrecompiledContractsBerlin = 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{eip2565: true}, - common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, + 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{eip2565: true}, + common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, } // PrecompiledContractsBLS contains the set of pre-compiled Ethereum @@ -104,6 +105,12 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{18}): &bls12381MapG2{}, } +// PrecompiledContractsEcverify contains the precompiled Ethereum +// contract specified in EIP-N. This is exported for testing purposes. +var PrecompiledContractsEcverify = map[common.Address]PrecompiledContract{ + common.BytesToAddress([]byte{19}): &ecverify{}, +} + var ( PrecompiledAddressesBerlin []common.Address PrecompiledAddressesIstanbul []common.Address @@ -1107,3 +1114,33 @@ func (c *bls12381MapG2) Run(input []byte) ([]byte, error) { // Encode the G2 point to 256 bytes return g.EncodePoint(r), nil } + +// ECVERIFY (secp256r1 signature verification) +// implemented as a native contract +type ecverify struct{} + +// RequiredGas returns the gas required to execute the precompiled contract +func (c *ecverify) RequiredGas(input []byte) uint64 { + return params.EcverifyGas +} + +// Run executes the precompiled contract, returning the output and the used gas +func (c *ecverify) Run(input []byte) ([]byte, error) { + // Required input length is 160 bytes + const ecverifyInputLength = 160 + + // "input" is (hash, r, s, x, y), each 32 bytes + input = common.RightPadBytes(input, ecverifyInputLength) + + // Extract the hash, r, s, x, y from the input + hash := input[0:32] + r, s := new(big.Int).SetBytes(input[32:64]), new(big.Int).SetBytes(input[64:96]) + x, y := new(big.Int).SetBytes(input[96:128]), new(big.Int).SetBytes(input[128:160]) + + // Verify the secp256r1 signature + if result, err := secp256r1.Verify(hash, r, s, x, y); err != nil { + return nil, err + } else { + return result, nil + } +} diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 53f8de5945..3e8f5c71eb 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -65,6 +65,7 @@ var allPrecompiles = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{16}): &bls12381Pairing{}, common.BytesToAddress([]byte{17}): &bls12381MapG1{}, common.BytesToAddress([]byte{18}): &bls12381MapG2{}, + common.BytesToAddress([]byte{19}): &ecverify{}, } // EIP-152 test vectors @@ -411,3 +412,15 @@ func BenchmarkPrecompiledBLS12381G2MultiExpWorstCase(b *testing.B) { } benchmarkPrecompiled("0f", testcase, b) } + +// Benchmarks the sample inputs from the ECVERIFY precompile. +func BenchmarkPrecompiledEcverify(bench *testing.B) { + t := precompiledTest{ + Input: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03", + Expected: "0000000000000000000000000000000000000000000000000000000000000001", + Name: "ecverify", + } + benchmarkPrecompiled("13", t, bench) +} + +func TestPrecompiledEcverify(t *testing.T) { testJson("ecverify", "13", t) } diff --git a/core/vm/testdata/precompiles/ecverify.json b/core/vm/testdata/precompiles/ecverify.json new file mode 100644 index 0000000000..15ad1fbb34 --- /dev/null +++ b/core/vm/testdata/precompiles/ecverify.json @@ -0,0 +1,9 @@ +[ + { + "Input": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03", + "Expected": "0000000000000000000000000000000000000000000000000000000000000001", + "Gas": 3450, + "Name": "CallEcverify", + "NoBenchmark": false + } + ] \ No newline at end of file From 56f193346e1b004f848d85aa728cbd5eac9b0114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Mon, 8 May 2023 04:13:19 +0300 Subject: [PATCH 03/49] params: add new precompiled gas price (cherry picked from commit c0554c0764a2c021689e8d73b36987b67c954f0c) --- params/protocol_params.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/params/protocol_params.go b/params/protocol_params.go index 1de8e88bd7..685bce776f 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -160,6 +160,8 @@ const ( 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 + EcverifyGas 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, // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529 RefundQuotient uint64 = 2 From ae2d3da5c1da25a207741233980e7d38517a10a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Tue, 16 May 2023 18:05:43 +0300 Subject: [PATCH 04/49] core/vm, params: rename precompiled to p256verify (cherry picked from commit 6c7028a9043f65f0a3596be4a429be4e03d0eb89) --- core/vm/contracts.go | 38 +++++++++---------- core/vm/contracts_test.go | 10 ++--- .../{ecverify.json => p256Verify.json} | 2 +- params/protocol_params.go | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) rename core/vm/testdata/precompiles/{ecverify.json => p256Verify.json} (93%) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index d5375be753..f07969c435 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -80,15 +80,15 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ // PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum // contracts used in the Berlin release. var PrecompiledContractsBerlin = 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{eip2565: true}, - common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, + 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{eip2565: true}, + common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, } // PrecompiledContractsBLS contains the set of pre-compiled Ethereum @@ -105,10 +105,10 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ 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. -var PrecompiledContractsEcverify = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{19}): &ecverify{}, +var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{ + common.BytesToAddress([]byte{19}): &p256Verify{}, } var ( @@ -1115,22 +1115,22 @@ func (c *bls12381MapG2) Run(input []byte) ([]byte, error) { return g.EncodePoint(r), nil } -// ECVERIFY (secp256r1 signature verification) +// P256VERIFY (secp256r1 signature verification) // implemented as a native contract -type ecverify struct{} +type p256Verify struct{} // RequiredGas returns the gas required to execute the precompiled contract -func (c *ecverify) RequiredGas(input []byte) uint64 { - return params.EcverifyGas +func (c *p256Verify) RequiredGas(input []byte) uint64 { + return params.P256VerifyGas } // 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 - const ecverifyInputLength = 160 + const p256VerifyInputLength = 160 // "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 hash := input[0:32] diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 3e8f5c71eb..b025742238 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -65,7 +65,7 @@ var allPrecompiles = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{16}): &bls12381Pairing{}, common.BytesToAddress([]byte{17}): &bls12381MapG1{}, common.BytesToAddress([]byte{18}): &bls12381MapG2{}, - common.BytesToAddress([]byte{19}): &ecverify{}, + common.BytesToAddress([]byte{19}): &p256Verify{}, } // EIP-152 test vectors @@ -413,14 +413,14 @@ func BenchmarkPrecompiledBLS12381G2MultiExpWorstCase(b *testing.B) { benchmarkPrecompiled("0f", testcase, b) } -// Benchmarks the sample inputs from the ECVERIFY precompile. -func BenchmarkPrecompiledEcverify(bench *testing.B) { +// Benchmarks the sample inputs from the P256VERIFY precompile. +func BenchmarkPrecompiledP256Verify(bench *testing.B) { t := precompiledTest{ Input: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03", Expected: "0000000000000000000000000000000000000000000000000000000000000001", - Name: "ecverify", + Name: "p256Verify", } benchmarkPrecompiled("13", t, bench) } -func TestPrecompiledEcverify(t *testing.T) { testJson("ecverify", "13", t) } +func TestPrecompiledP256Verify(t *testing.T) { testJson("p256Verify", "13", t) } diff --git a/core/vm/testdata/precompiles/ecverify.json b/core/vm/testdata/precompiles/p256Verify.json similarity index 93% rename from core/vm/testdata/precompiles/ecverify.json rename to core/vm/testdata/precompiles/p256Verify.json index 15ad1fbb34..c98054d4c2 100644 --- a/core/vm/testdata/precompiles/ecverify.json +++ b/core/vm/testdata/precompiles/p256Verify.json @@ -3,7 +3,7 @@ "Input": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03", "Expected": "0000000000000000000000000000000000000000000000000000000000000001", "Gas": 3450, - "Name": "CallEcverify", + "Name": "CallP256Verify", "NoBenchmark": false } ] \ No newline at end of file diff --git a/params/protocol_params.go b/params/protocol_params.go index 685bce776f..10f7aaf81a 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -160,7 +160,7 @@ const ( 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 - 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, // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529 From 83a20d36eca3432dee1420b67db834454ad0ca45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Mon, 22 May 2023 17:57:24 +0200 Subject: [PATCH 05/49] core/vm: simplify the return values format (cherry picked from commit d245194e7724c2a7d153945cc86c9aa8d0b522b3) --- core/vm/contracts.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index f07969c435..4245a54528 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -1138,9 +1138,5 @@ func (c *p256Verify) Run(input []byte) ([]byte, error) { x, y := new(big.Int).SetBytes(input[96:128]), new(big.Int).SetBytes(input[128:160]) // Verify the secp256r1 signature - if result, err := secp256r1.Verify(hash, r, s, x, y); err != nil { - return nil, err - } else { - return result, nil - } + return secp256r1.Verify(hash, r, s, x, y) } From fc057aaabb9b1e9faed73ced441caecc28ee6cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Mon, 22 May 2023 22:38:41 +0200 Subject: [PATCH 06/49] crypto/secp25r1: fix reverse malleability issue (cherry picked from commit 066a31f6345c8a04a4ebf84efd8c80d87107e6d5) --- crypto/secp256r1/verifier.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/secp256r1/verifier.go b/crypto/secp256r1/verifier.go index 67a0dd787d..9db2d5b930 100644 --- a/crypto/secp256r1/verifier.go +++ b/crypto/secp256r1/verifier.go @@ -35,5 +35,5 @@ func Verify(hash []byte, r, s, x, y *big.Int) ([]byte, error) { // Check the malleability issue func checkMalleability(s *big.Int) bool { - return s.Cmp(secp256k1halfN) <= 0 + return s.Cmp(secp256k1halfN) > 0 } From 40e6de0bf2f5fc3e0c055b3d19f94e933399a7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Mon, 22 May 2023 22:39:55 +0200 Subject: [PATCH 07/49] core/vm: fix testdata non-malleable for p256Verify (cherry picked from commit ec17e788ade3f43ded67c014f019770634f32a7c) --- core/vm/contracts_test.go | 2 +- core/vm/testdata/precompiles/p256Verify.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index b025742238..24ddae0715 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -416,7 +416,7 @@ func BenchmarkPrecompiledBLS12381G2MultiExpWorstCase(b *testing.B) { // Benchmarks the sample inputs from the P256VERIFY precompile. func BenchmarkPrecompiledP256Verify(bench *testing.B) { t := precompiledTest{ - Input: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03", + Input: "4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e", Expected: "0000000000000000000000000000000000000000000000000000000000000001", Name: "p256Verify", } diff --git a/core/vm/testdata/precompiles/p256Verify.json b/core/vm/testdata/precompiles/p256Verify.json index c98054d4c2..fbcac41e9f 100644 --- a/core/vm/testdata/precompiles/p256Verify.json +++ b/core/vm/testdata/precompiles/p256Verify.json @@ -1,6 +1,6 @@ [ { - "Input": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98243744ca2b25ce52b927841120de9d5e5a454acabea2ebacaa1f76850934cb0c7c818200fa5e4b4607eeea9593071a6097b132d77c10661c441b5a66eb36856e1251c078c2c1367932e25bf657f6b2e378a26a27e238196295e1c59e2225d372fe603c229d85ea9eb0b090274c59a0600becd11d0df3f91fe44677977119c4ff03", + "Input": "4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e", "Expected": "0000000000000000000000000000000000000000000000000000000000000001", "Gas": 3450, "Name": "CallP256Verify", From b5559e30186326ed614adcb843532793d4a74450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Thu, 22 Jun 2023 15:40:47 +0300 Subject: [PATCH 08/49] core/vm: update the eip number (cherry picked from commit f5b6d7e9954cae87348e21525210affda09297c1) --- core/vm/contracts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 4245a54528..d9e427d5e3 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -106,7 +106,7 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ } // PrecompiledContractsP256Verify contains the precompiled Ethereum -// contract specified in EIP-N. This is exported for testing purposes. +// contract specified in EIP-7212. This is exported for testing purposes. var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{19}): &p256Verify{}, } From 0d115db16865edb6903d7bf11126ab64256f366c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Fri, 23 Jun 2023 01:13:27 +0300 Subject: [PATCH 09/49] core, crypto/secp256r1: fix error reverts tx error (cherry picked from commit 2820903f591365b17a4c3bdb36bd49ee2d84054c) --- core/vm/contracts.go | 8 +++++++- crypto/secp256r1/verifier.go | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index d9e427d5e3..db73bcebbc 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -1138,5 +1138,11 @@ func (c *p256Verify) Run(input []byte) ([]byte, error) { x, y := new(big.Int).SetBytes(input[96:128]), new(big.Int).SetBytes(input[128:160]) // Verify the secp256r1 signature - return secp256r1.Verify(hash, r, s, x, y) + if secp256r1.Verify(hash, r, s, x, y) { + // Signature is valid + return common.LeftPadBytes(common.Big1.Bytes(), 32), nil + } else { + // Signature is invalid + return nil, nil + } } diff --git a/crypto/secp256r1/verifier.go b/crypto/secp256r1/verifier.go index 9db2d5b930..e45d49e352 100644 --- a/crypto/secp256r1/verifier.go +++ b/crypto/secp256r1/verifier.go @@ -3,34 +3,36 @@ package secp256r1 import ( "crypto/ecdsa" "crypto/elliptic" - "errors" "math/big" - - "github.com/ethereum/go-ethereum/common" ) var ( + // Half of the order of the subgroup in the elliptic curve secp256k1halfN = new(big.Int).Div(elliptic.P256().Params().N, big.NewInt(2)) ) // Verifies the given signature (r, s) for the given hash and public key (x, y). -func Verify(hash []byte, r, s, x, y *big.Int) ([]byte, error) { +func Verify(hash []byte, r, s, x, y *big.Int) bool { // Create the public key format publicKey := newPublicKey(x, y) + + // Check if they are invalid public key coordinates if publicKey == nil { - return nil, errors.New("invalid public key coordinates") + return false } + // Check the malleability issue if checkMalleability(s) { - return nil, errors.New("malleability issue") + return false } - // Verify the signature with the public key and return 1 if it's valid, 0 otherwise + // Verify the signature with the public key, + // then return true if it's valid, false otherwise if ok := ecdsa.Verify(publicKey, hash, r, s); ok { - return common.LeftPadBytes(common.Big1.Bytes(), 32), nil + return true } - return common.LeftPadBytes(common.Big0.Bytes(), 32), nil + return false } // Check the malleability issue From d64d8e73c11b6ccfa8175e0fae6407d6587fd1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Fri, 11 Aug 2023 00:36:35 +0300 Subject: [PATCH 10/49] crypto/secp256r1: refactor by simplfying return (cherry picked from commit 1be1875156e2a5a417801deb59546b167e5456c6) --- crypto/secp256r1/verifier.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crypto/secp256r1/verifier.go b/crypto/secp256r1/verifier.go index e45d49e352..a9e833cd65 100644 --- a/crypto/secp256r1/verifier.go +++ b/crypto/secp256r1/verifier.go @@ -28,11 +28,7 @@ func Verify(hash []byte, r, s, x, y *big.Int) bool { // Verify the signature with the public key, // then return true if it's valid, false otherwise - if ok := ecdsa.Verify(publicKey, hash, r, s); ok { - return true - } - - return false + return ecdsa.Verify(publicKey, hash, r, s) } // Check the malleability issue From 2bbf30ff90ff1b94db6986aaf957c80c1e1ed9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Sun, 24 Sep 2023 04:42:41 +0300 Subject: [PATCH 11/49] core/vm: force the input length of p256verify (cherry picked from commit 21f4932c9bbb8664cf7b3e3c3602b6a48c747893) --- core/vm/contracts.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index db73bcebbc..4d1047d948 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -1124,13 +1124,15 @@ func (c *p256Verify) RequiredGas(input []byte) uint64 { return params.P256VerifyGas } -// Run executes the precompiled contract, returning the output and the used gas +// Run executes the precompiled contract with given 160 bytes of param, returning the output and the used gas func (c *p256Verify) Run(input []byte) ([]byte, error) { // Required input length is 160 bytes const p256VerifyInputLength = 160 - - // "input" is (hash, r, s, x, y), each 32 bytes - input = common.RightPadBytes(input, p256VerifyInputLength) + // Check the input length + if len(input) != p256VerifyInputLength { + // Input length is invalid + return nil, nil + } // Extract the hash, r, s, x, y from the input hash := input[0:32] From ab2f20e8ddd540ebccce2fa2473447f54d62183d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Sun, 24 Sep 2023 04:54:00 +0300 Subject: [PATCH 12/49] crypto/secp256r1: reject the reference pubKey coordinates (cherry picked from commit 98f10b0d5e358075d03b76834cd30c97f4fbdfe1) --- crypto/secp256r1/publickey.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crypto/secp256r1/publickey.go b/crypto/secp256r1/publickey.go index c92afaa1e0..9b84044efa 100644 --- a/crypto/secp256r1/publickey.go +++ b/crypto/secp256r1/publickey.go @@ -13,6 +13,11 @@ func newPublicKey(x, y *big.Int) *ecdsa.PublicKey { return nil } + // Check if the given coordinates are the reference point (infinity) + if x.Sign() == 0 && y.Sign() == 0 { + return nil + } + return &ecdsa.PublicKey{ Curve: elliptic.P256(), X: x, From 738107b6c85b50619e37aa058e6be93cee4ad62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Sat, 7 Oct 2023 16:08:05 +0300 Subject: [PATCH 13/49] crypto/secp256r1: remove malleability check due to spec (cherry picked from commit cec0b058115282168c5afc5197de3f6b5479dc4a) --- crypto/secp256r1/verifier.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/crypto/secp256r1/verifier.go b/crypto/secp256r1/verifier.go index a9e833cd65..ccc0786610 100644 --- a/crypto/secp256r1/verifier.go +++ b/crypto/secp256r1/verifier.go @@ -2,15 +2,9 @@ package secp256r1 import ( "crypto/ecdsa" - "crypto/elliptic" "math/big" ) -var ( - // Half of the order of the subgroup in the elliptic curve - secp256k1halfN = new(big.Int).Div(elliptic.P256().Params().N, big.NewInt(2)) -) - // Verifies the given signature (r, s) for the given hash and public key (x, y). func Verify(hash []byte, r, s, x, y *big.Int) bool { // Create the public key format @@ -21,17 +15,7 @@ func Verify(hash []byte, r, s, x, y *big.Int) bool { return false } - // Check the malleability issue - if checkMalleability(s) { - return false - } - // Verify the signature with the public key, // then return true if it's valid, false otherwise return ecdsa.Verify(publicKey, hash, r, s) } - -// Check the malleability issue -func checkMalleability(s *big.Int) bool { - return s.Cmp(secp256k1halfN) > 0 -} From 53c7d9b2286a4ec36c5e1574aa285efb86cf7c76 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Fri, 24 Nov 2023 11:35:13 +0530 Subject: [PATCH 14/49] remove unnecessary lines --- core/blockchain.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 36d5635065..e62ab09189 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -408,7 +408,8 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis // The first thing the node will do is reconstruct the verification data for // the head block (ethash cache or clique voting snapshot). Might as well do // it in advance. - bc.engine.VerifyHeader(bc, bc.CurrentHeader()) + // BOR - commented out intentionally + // bc.engine.VerifyHeader(bc, bc.CurrentHeader()) // Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain for hash := range BadHashes { @@ -2139,15 +2140,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) parent = bc.GetHeader(block.ParentHash(), block.NumberU64()-1) } - statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps) - if err != nil { - return it.index, err - } - - // Enable prefetching to pull in trie node paths while processing transactions - statedb.StartPrefetcher("chain") - activeState = statedb - // If we have a followup block, run that against the current state to pre-cache // transactions and probabilistically some of the account/storage trie nodes. var followupInterrupt atomic.Bool From 83722b9615d56276455ee23be345774c25bd4a94 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Fri, 24 Nov 2023 11:48:10 +0530 Subject: [PATCH 15/49] version change --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index e4f0463fc2..687576c52b 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.0-beta +Version: 1.2.0-beta2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 04a59510f7..9fb61257fa 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.0-beta +Version: 1.2.0-beta2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index f83b21148d..7f5fe47543 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0-beta +Version: 1.2.0-beta2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index e39ecda6d1..ac18df1eee 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0-beta +Version: 1.2.0-beta2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index f201053311..70daa188d1 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0-beta +Version: 1.2.0-beta2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index fa5360da07..db84ee3116 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0-beta +Version: 1.2.0-beta2 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index d942ddf483..1ee0e1e429 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 0 // Patch version component of the current release - VersionMeta = "beta" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 0 // Patch version component of the current release + VersionMeta = "beta2" // Version metadata to append to the version string ) var GitCommit string From e3192cae8bff9ab1ee58c2db3564d5688862a0b4 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Fri, 24 Nov 2023 12:50:04 +0530 Subject: [PATCH 16/49] hot fix: block stm ParallelSpeculativeProcesses flag --- core/blockchain.go | 18 ++++++++++-------- core/parallel_state_processor.go | 4 ++-- core/vm/interpreter.go | 4 ---- eth/backend.go | 2 +- miner/worker_test.go | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index e62ab09189..b63ab6378c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -236,13 +236,14 @@ type BlockChain struct { stopping atomic.Bool // false if chain is running, true when stopped procInterrupt atomic.Bool // interrupt signaler for block processing - engine consensus.Engine - validator Validator // Block and state validator interface - prefetcher Prefetcher - processor Processor // Block transaction processor interface - parallelProcessor Processor // Parallel block transaction processor interface - forker *ForkChoice - vmConfig vm.Config + engine consensus.Engine + validator Validator // Block and state validator interface + prefetcher Prefetcher + processor Processor // Block transaction processor interface + parallelProcessor Processor // Parallel block transaction processor interface + parallelSpeculativeProcesses int // Number of parallel speculative processes + forker *ForkChoice + vmConfig vm.Config // Bor related changes borReceiptsCache *lru.Cache[common.Hash, *types.Receipt] // Cache for the most recent bor receipt receipts per block @@ -482,7 +483,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis } // NewParallelBlockChain , similar to NewBlockChain, creates a new blockchain object, but with a parallel state processor -func NewParallelBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64, checker ethereum.ChainValidator) (*BlockChain, error) { +func NewParallelBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64, checker ethereum.ChainValidator, numprocs int) (*BlockChain, error) { bc, err := NewBlockChain(db, cacheConfig, genesis, overrides, engine, vmConfig, shouldPreserve, txLookupLimit, checker) if err != nil { @@ -501,6 +502,7 @@ func NewParallelBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis } bc.parallelProcessor = NewParallelStateProcessor(chainConfig, bc, engine) + bc.parallelSpeculativeProcesses = numprocs return bc, nil } diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index c4077de4d8..2dfff35349 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -364,7 +364,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat backupStateDB := statedb.Copy() profile := false - result, err := blockstm.ExecuteParallel(tasks, profile, metadata, cfg.ParallelSpeculativeProcesses, interruptCtx) + result, err := blockstm.ExecuteParallel(tasks, profile, metadata, p.bc.parallelSpeculativeProcesses, interruptCtx) if err == nil && profile && result.Deps != nil { _, weight := result.Deps.LongestPath(*result.Stats) @@ -398,7 +398,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat t.totalUsedGas = usedGas } - _, err = blockstm.ExecuteParallel(tasks, false, metadata, cfg.ParallelSpeculativeProcesses, interruptCtx) + _, err = blockstm.ExecuteParallel(tasks, false, metadata, p.bc.parallelSpeculativeProcesses, interruptCtx) break } diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index c8907bc9b3..e91d80b811 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -52,10 +52,6 @@ type Config struct { NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls) EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages ExtraEips []int // Additional EIPS that are to be enabled - - // parallel EVM configs - ParallelEnable bool - ParallelSpeculativeProcesses int } // ScopeContext contains the things that are per-call, such as stack and memory, diff --git a/eth/backend.go b/eth/backend.go index e21e760d60..e8d9fabbff 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -237,7 +237,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { // check if Parallel EVM is enabled // if enabled, use parallel state processor if config.ParallelEVM.Enable { - eth.blockchain, err = core.NewParallelBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit, checker) + eth.blockchain, err = core.NewParallelBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit, checker, config.ParallelEVM.SpeculativeProcesses) } else { eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit, checker) } diff --git a/miner/worker_test.go b/miner/worker_test.go index 58a5ff2948..88f7924b00 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -949,7 +949,7 @@ func BenchmarkBorMiningBlockSTMMetadata(b *testing.B) { db2 := rawdb.NewMemoryDatabase() back.genesis.MustCommit(db2) - chain, _ := core.NewParallelBlockChain(db2, nil, back.genesis, nil, engine, vm.Config{ParallelEnable: true, ParallelSpeculativeProcesses: 8}, nil, nil, nil) + chain, _ := core.NewParallelBlockChain(db2, nil, back.genesis, nil, engine, vm.Config{}, nil, nil, nil, 8) defer chain.Stop() // Ignore empty commit here for less noise. From 2fdacadf1ad7bf255f08c13b2d303c497e61d0b5 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 29 Nov 2023 20:52:07 +0530 Subject: [PATCH 17/49] update version --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 687576c52b..eb90e92d82 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.0-beta2 +Version: 1.2.0 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 9fb61257fa..f07ee18113 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.0-beta2 +Version: 1.2.0 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 7f5fe47543..f58ef6ffad 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0-beta2 +Version: 1.2.0 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index ac18df1eee..8465229b95 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0-beta2 +Version: 1.2.0 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 70daa188d1..085dd4e11d 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0-beta2 +Version: 1.2.0 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index db84ee3116..d0a6ac7e80 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0-beta2 +Version: 1.2.0 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index 1ee0e1e429..ee3d820c50 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 0 // Patch version component of the current release - VersionMeta = "beta2" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 0 // Patch version component of the current release + VersionMeta = "" // Version metadata to append to the version string ) var GitCommit string From 05a19f2a360055c489af4eb22e46d6b641d52f8e Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Thu, 30 Nov 2023 12:56:21 +0530 Subject: [PATCH 18/49] fix test, add napoli block --- core/vm/contracts.go | 11 +++++++++-- core/vm/contracts_test.go | 6 +++++- core/vm/testdata/precompiles/p256Verify.json | 2 +- params/config.go | 14 +++++++++++--- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 4d1047d948..5d1728d1fd 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -105,13 +105,14 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{18}): &bls12381MapG2{}, } -// PrecompiledContractsP256Verify contains the precompiled Ethereum +// PrecompiledContractsNapoli contains the precompiled Ethereum // contract specified in EIP-7212. This is exported for testing purposes. -var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{ +var PrecompiledContractsNapoli = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{19}): &p256Verify{}, } var ( + PrecompiledAddressesNapoli []common.Address PrecompiledAddressesBerlin []common.Address PrecompiledAddressesIstanbul []common.Address PrecompiledAddressesByzantium []common.Address @@ -134,11 +135,17 @@ func init() { for k := range PrecompiledContractsBerlin { PrecompiledAddressesBerlin = append(PrecompiledAddressesBerlin, k) } + + for k := range PrecompiledContractsNapoli { + PrecompiledAddressesNapoli = append(PrecompiledAddressesNapoli, k) + } } // ActivePrecompiles returns the precompiles enabled with the current configuration. func ActivePrecompiles(rules params.Rules) []common.Address { switch { + case rules.IsNapoli: + return PrecompiledAddressesNapoli case rules.IsBerlin: return PrecompiledAddressesBerlin case rules.IsIstanbul: diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 24ddae0715..c55f58eb51 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -423,4 +423,8 @@ func BenchmarkPrecompiledP256Verify(bench *testing.B) { benchmarkPrecompiled("13", t, bench) } -func TestPrecompiledP256Verify(t *testing.T) { testJson("p256Verify", "13", t) } +func TestPrecompiledP256Verify(t *testing.T) { + t.Parallel() + + testJson("p256Verify", "13", t) +} diff --git a/core/vm/testdata/precompiles/p256Verify.json b/core/vm/testdata/precompiles/p256Verify.json index fbcac41e9f..c01387dda7 100644 --- a/core/vm/testdata/precompiles/p256Verify.json +++ b/core/vm/testdata/precompiles/p256Verify.json @@ -6,4 +6,4 @@ "Name": "CallP256Verify", "NoBenchmark": false } - ] \ No newline at end of file +] \ No newline at end of file diff --git a/params/config.go b/params/config.go index e3740068c6..278374356b 100644 --- a/params/config.go +++ b/params/config.go @@ -649,6 +649,7 @@ type ChainConfig struct { ShanghaiBlock *big.Int `json:"shanghaiBlock,omitempty"` // Shanghai switch Block (nil = no fork, 0 = already on shanghai) CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch Block (nil = no fork, 0 = already on cancun) PragueBlock *big.Int `json:"pragueBlock,omitempty"` // Prague switch Block (nil = no fork, 0 = already on prague) + NapoliBlock *big.Int `json:"napoliBlock,omitempty"` // Napoli switch Block (nil = no fork, 0 = already on Napoli) // TerminalTotalDifficulty is the amount of total difficulty reached by // the network that triggers the consensus upgrade. @@ -971,21 +972,26 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0 } -// IsShanghai returns whether time is either equal to the Shanghai fork time or greater. +// IsShanghai returns whether num is either equal to the Shanghai fork block or greater. func (c *ChainConfig) IsShanghai(num *big.Int) bool { return isBlockForked(c.ShanghaiBlock, num) } -// IsCancun returns whether num is either equal to the Cancun fork time or greater. +// IsCancun returns whether num is either equal to the Cancun fork block or greater. func (c *ChainConfig) IsCancun(num *big.Int) bool { return isBlockForked(c.CancunBlock, num) } -// IsPrague returns whether num is either equal to the Prague fork time or greater. +// IsPrague returns whether num is either equal to the Prague fork block or greater. func (c *ChainConfig) IsPrague(num *big.Int) bool { return isBlockForked(c.PragueBlock, num) } +// IsNapoli returns whether num is either equal to the Napoli fork block or greater. +func (c *ChainConfig) IsNapoli(num *big.Int) bool { + return isBlockForked(c.NapoliBlock, num) +} + // CheckCompatible checks whether scheduled fork transitions have been imported // with a mismatching chain configuration. func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time uint64) *ConfigCompatError { @@ -1327,6 +1333,7 @@ type Rules struct { IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool IsBerlin, IsLondon bool IsMerge, IsShanghai, IsCancun, IsPrague bool + IsNapoli bool } // Rules ensures c's ChainID is not nil. @@ -1352,5 +1359,6 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsShanghai: c.IsShanghai(num), IsCancun: c.IsCancun(num), IsPrague: c.IsPrague(num), + IsNapoli: c.IsNapoli(num), } } From 532ebd41e9837cbc92b20a7b896330b215ee1870 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Mon, 18 Dec 2023 14:56:45 +0530 Subject: [PATCH 19/49] debug testing --- core/state/pruner/pruner.go | 44 +++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go index 157d2e181d..ea021c3be2 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -57,6 +57,7 @@ const ( // Config includes all the configurations for pruning. type Config struct { Datadir string // The directory of the state database + Cachedir string // The directory of state clean cache BloomSize uint64 // The Megabytes of memory allocated to bloom-filter } @@ -261,7 +262,7 @@ func (p *Pruner) Prune(root common.Hash) error { } if stateBloomRoot != (common.Hash{}) { - return RecoverPruning(p.config.Datadir, p.db) + return RecoverPruning(p.config.Datadir, p.db, p.config.Cachedir) } // If the target state root is not specified, use the HEAD-127 as the // target. The reason for picking it is: @@ -286,8 +287,8 @@ func (p *Pruner) Prune(root common.Hash) error { // is the presence of root can indicate the presence of the // entire trie. if !rawdb.HasLegacyTrieNode(p.db, root) { - // The special case is for clique based networks(goerli - // and some other private networks), it's possible that two + // The special case is for clique based networks(goerli and + // some other private networks), it's possible that two // consecutive blocks will have same root. In this case snapshot // difflayer won't be created. So HEAD-127 may not paired with // head-127 layer. Instead the paired layer is higher than the @@ -324,6 +325,12 @@ func (p *Pruner) Prune(root common.Hash) error { log.Info("Selecting user-specified state as the pruning target", "root", root) } } + // Before start the pruning, delete the clean trie cache first. + // It's necessary otherwise in the next restart we will hit the + // deleted state root in the "clean cache" so that the incomplete + // state is picked for usage. + deleteCleanTrieCache(p.config.Cachedir) + // All the state roots of the middle layer should be forcibly pruned, // otherwise the dangling state will be left. middleRoots := make(map[common.Hash]struct{}) @@ -368,7 +375,7 @@ func (p *Pruner) Prune(root common.Hash) error { // pruning can be resumed. What's more if the bloom filter is constructed, the // pruning **has to be resumed**. Otherwise a lot of dangling nodes may be left // in the disk. -func RecoverPruning(datadir string, db ethdb.Database) error { +func RecoverPruning(datadir string, db ethdb.Database, trieCachePath string) error { stateBloomPath, stateBloomRoot, err := findBloomFilter(datadir) if err != nil { return err @@ -409,6 +416,12 @@ func RecoverPruning(datadir string, db ethdb.Database) error { log.Info("Loaded state bloom filter", "path", stateBloomPath) + // Before start the pruning, delete the clean trie cache first. + // It's necessary otherwise in the next restart we will hit the + // deleted state root in the "clean cache" so that the incomplete + // state is picked for usage. + deleteCleanTrieCache(trieCachePath) + // All the state roots of the middle layers should be forcibly pruned, // otherwise the dangling state will be left. var ( @@ -451,6 +464,7 @@ func extractGenesis(db ethdb.Database, stateBloom *stateBloom) error { if err != nil { return err } + accIter, err := t.NodeIterator(nil) if err != nil { return err @@ -477,6 +491,7 @@ func extractGenesis(db ethdb.Database, stateBloom *stateBloom) error { if err != nil { return err } + storageIter, err := storageTrie.NodeIterator(nil) if err != nil { return err @@ -536,3 +551,24 @@ func findBloomFilter(datadir string) (string, common.Hash, error) { return stateBloomPath, stateBloomRoot, nil } + +const warningLog = ` + +WARNING! + +The clean trie cache is not found. Please delete it by yourself after the +pruning. Remember don't start the Geth without deleting the clean trie cache +otherwise the entire database may be damaged! + +Check the command description "geth snapshot prune-state --help" for more details. +` + +func deleteCleanTrieCache(path string) { + if !common.FileExist(path) { + log.Warn(warningLog) + return + } + + os.RemoveAll(path) + log.Info("Deleted trie clean cache", "path", path) +} From 82f3b2ac3bd3388cf00022ffc9e066d0b78b039c Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Mon, 18 Dec 2023 15:14:51 +0530 Subject: [PATCH 20/49] fix issue --- eth/backend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/backend.go b/eth/backend.go index e8d9fabbff..df4175a3de 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -143,7 +143,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { if err != nil { return nil, err } - if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb); err != nil { + if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb, ""); err != nil { log.Error("Failed to recover state", "error", err) } From fca83f0062181fc8bc1e7bcdd03fdb2a4e437cc3 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Mon, 18 Dec 2023 15:23:35 +0530 Subject: [PATCH 21/49] version change --- cmd/evm/testdata/3/readme.md | 6 +----- cmd/evm/testdata/4/readme.md | 6 +----- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 9 files changed, 12 insertions(+), 20 deletions(-) diff --git a/cmd/evm/testdata/3/readme.md b/cmd/evm/testdata/3/readme.md index 016887f865..7a52c9833e 100644 --- a/cmd/evm/testdata/3/readme.md +++ b/cmd/evm/testdata/3/readme.md @@ -1,6 +1,2 @@ -<<<<<<< HEAD These files examplify a transition where a transaction (executed on block 5) requests -======= -These files exemplify a transition where a transaction (executed on block 5) requests ->>>>>>> bed84606583893fdb698cc1b5058cc47b4dbd837 -the blockhash for block `1`. +the blockhash for block `1`. diff --git a/cmd/evm/testdata/4/readme.md b/cmd/evm/testdata/4/readme.md index 9d1c946a86..56846dfdd2 100644 --- a/cmd/evm/testdata/4/readme.md +++ b/cmd/evm/testdata/4/readme.md @@ -1,7 +1,3 @@ -<<<<<<< HEAD -These files examplify a transition where a transaction (executed on block 5) requests -======= These files exemplify a transition where a transaction (executed on block 5) requests ->>>>>>> bed84606583893fdb698cc1b5058cc47b4dbd837 -the blockhash for block `4`, but where the hash for that block is missing. +the blockhash for block `4`, but where the hash for that block is missing. It's expected that executing these should cause `exit` with errorcode `4`. diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index eb90e92d82..a48292453d 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.0 +Version: 1.2.1-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index f07ee18113..56d4cc40a4 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.0 +Version: 1.2.1-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index f58ef6ffad..999c0dc144 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0 +Version: 1.2.1-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 8465229b95..9db9e3eb08 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0 +Version: 1.2.1-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 085dd4e11d..836fd99418 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0 +Version: 1.2.1-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index d0a6ac7e80..572c34306f 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.0 +Version: 1.2.1-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index ee3d820c50..110d4d09fb 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 0 // Patch version component of the current release - VersionMeta = "" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 1 // Patch version component of the current release + VersionMeta = "beta" // Version metadata to append to the version string ) var GitCommit string From 964494f5a83c17f9a7d82809c596975a42ac71b7 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 19 Dec 2023 00:45:40 +0530 Subject: [PATCH 22/49] upgrade version --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index a48292453d..5b249281c7 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.1-beta +Version: 1.2.1 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 56d4cc40a4..d6ea25f3b8 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.1-beta +Version: 1.2.1 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 999c0dc144..5272652792 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.1-beta +Version: 1.2.1 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 9db9e3eb08..d229ab68dc 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.1-beta +Version: 1.2.1 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 836fd99418..41c1e7f3c3 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.1-beta +Version: 1.2.1 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 572c34306f..7d94bb7cbe 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.1-beta +Version: 1.2.1 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index 110d4d09fb..39e283fb0d 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 1 // Patch version component of the current release - VersionMeta = "beta" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 1 // Patch version component of the current release + VersionMeta = "" // Version metadata to append to the version string ) var GitCommit string From e5fc28d6caa7eae016fd20de41305ddc537e4f5d Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 27 Dec 2023 16:35:04 +0530 Subject: [PATCH 23/49] use config value for triesInMemory instead of default --- eth/backend.go | 1 + 1 file changed, 1 insertion(+) diff --git a/eth/backend.go b/eth/backend.go index df4175a3de..81b794283e 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -229,6 +229,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { TrieTimeLimit: config.TrieTimeout, SnapshotLimit: config.SnapshotCache, Preimages: config.Preimages, + TriesInMemory: config.TriesInMemory, } ) From 46bd7d7d6c0876b1f7e89373397ab9039577823c Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 27 Dec 2023 16:35:43 +0530 Subject: [PATCH 24/49] update version --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 5b249281c7..3b63ec6f95 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.1 +Version: 1.2.2-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index d6ea25f3b8..a2c15ad001 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.1 +Version: 1.2.2-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 5272652792..c346b361de 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.1 +Version: 1.2.2-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index d229ab68dc..b1943f90fd 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.1 +Version: 1.2.2-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 41c1e7f3c3..797086ba18 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.1 +Version: 1.2.2-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 7d94bb7cbe..d701656a88 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.1 +Version: 1.2.2-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index 39e283fb0d..4e8a641e74 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 1 // Patch version component of the current release - VersionMeta = "" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 2 // Patch version component of the current release + VersionMeta = "beta" // Version metadata to append to the version string ) var GitCommit string From 7253babddc58891560dd10078b6a4e25838fd7ee Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 27 Dec 2023 16:42:06 +0530 Subject: [PATCH 25/49] revert pruning hotfix --- core/state/pruner/pruner.go | 96 ++----------------------------------- eth/backend.go | 2 +- 2 files changed, 5 insertions(+), 93 deletions(-) diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go index ea021c3be2..64c4a3a6eb 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -57,7 +57,6 @@ const ( // Config includes all the configurations for pruning. type Config struct { Datadir string // The directory of the state database - Cachedir string // The directory of state clean cache BloomSize uint64 // The Megabytes of memory allocated to bloom-filter } @@ -86,14 +85,12 @@ func NewPruner(db ethdb.Database, config Config) (*Pruner, error) { if headBlock == nil { return nil, errors.New("failed to load head block") } - snapconfig := snapshot.Config{ CacheSize: 256, Recovery: false, NoBuild: true, AsyncBuild: false, } - snaptree, err := snapshot.New(snapconfig, db, trie.NewDatabase(db), headBlock.Root()) if err != nil { return nil, err // The relevant snapshot(s) might not exist @@ -103,12 +100,10 @@ func NewPruner(db ethdb.Database, config Config) (*Pruner, error) { log.Warn("Sanitizing bloomfilter size", "provided(MB)", config.BloomSize, "updated(MB)", 256) config.BloomSize = 256 } - stateBloom, err := newStateBloomWithSize(config.BloomSize) if err != nil { return nil, err } - return &Pruner{ config: config, chainHeader: headBlock.Header(), @@ -134,7 +129,6 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta batch = maindb.NewBatch() iter = maindb.NewIterator(nil, nil) ) - for iter.Next() { key := iter.Key() @@ -148,7 +142,6 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta if isCode { checkKey = codeKey } - if _, exist := middleStateRoots[common.BytesToHash(checkKey)]; exist { log.Debug("Forcibly delete the middle state roots", "hash", common.BytesToHash(checkKey)) } else { @@ -156,26 +149,21 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta continue } } - count += 1 size += common.StorageSize(len(key) + len(iter.Value())) batch.Delete(key) var eta time.Duration // Realistically will never remain uninited - if done := binary.BigEndian.Uint64(key[:8]); done > 0 { var ( left = math.MaxUint64 - binary.BigEndian.Uint64(key[:8]) speed = done/uint64(time.Since(pstart)/time.Millisecond+1) + 1 // +1s to avoid division by zero ) - eta = time.Duration(left/speed) * time.Millisecond } - if time.Since(logged) > 8*time.Second { log.Info("Pruning state data", "nodes", count, "size", size, "elapsed", common.PrettyDuration(time.Since(pstart)), "eta", common.PrettyDuration(eta)) - logged = time.Now() } // Recreate the iterator after every batch commit in order @@ -189,12 +177,10 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta } } } - if batch.ValueSize() > 0 { batch.Write() batch.Reset() } - iter.Release() log.Info("Pruned state data", "nodes", count, "size", size, "elapsed", common.PrettyDuration(time.Since(pstart))) @@ -221,19 +207,15 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta // Note for small pruning, the compaction is skipped. if count >= rangeCompactionThreshold { cstart := time.Now() - for b := 0x00; b <= 0xf0; b += 0x10 { var ( start = []byte{byte(b)} end = []byte{byte(b + 0x10)} ) - if b == 0xf0 { end = nil } - log.Info("Compacting database", "range", fmt.Sprintf("%#x-%#x", start, end), "elapsed", common.PrettyDuration(time.Since(cstart))) - if err := maindb.Compact(start, end); err != nil { log.Error("Database compaction failed", "error", err) return err @@ -241,16 +223,13 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta } log.Info("Database compaction finished", "elapsed", common.PrettyDuration(time.Since(cstart))) } - log.Info("State pruning successful", "pruned", size, "elapsed", common.PrettyDuration(time.Since(start))) - return nil } // Prune deletes all historical state nodes except the nodes belong to the // specified state version. If user doesn't specify the state version, use // the bottom-most snapshot diff layer as the target. -// nolint:nestif func (p *Pruner) Prune(root common.Hash) error { // If the state bloom filter is already committed previously, // reuse it for pruning instead of generating a new one. It's @@ -260,9 +239,8 @@ func (p *Pruner) Prune(root common.Hash) error { if err != nil { return err } - if stateBloomRoot != (common.Hash{}) { - return RecoverPruning(p.config.Datadir, p.db, p.config.Cachedir) + return RecoverPruning(p.config.Datadir, p.db) } // If the target state root is not specified, use the HEAD-127 as the // target. The reason for picking it is: @@ -287,8 +265,8 @@ func (p *Pruner) Prune(root common.Hash) error { // is the presence of root can indicate the presence of the // entire trie. if !rawdb.HasLegacyTrieNode(p.db, root) { - // The special case is for clique based networks(goerli and - // some other private networks), it's possible that two + // The special case is for clique based networks(goerli + // and some other private networks), it's possible that two // consecutive blocks will have same root. In this case snapshot // difflayer won't be created. So HEAD-127 may not paired with // head-127 layer. Instead the paired layer is higher than the @@ -299,23 +277,18 @@ func (p *Pruner) Prune(root common.Hash) error { // state available, but we don't want to use the topmost state // as the pruning target. var found bool - for i := len(layers) - 2; i >= 2; i-- { if rawdb.HasLegacyTrieNode(p.db, layers[i].Root()) { root = layers[i].Root() found = true - log.Info("Selecting middle-layer as the pruning target", "root", root, "depth", i) - break } } - if !found { if len(layers) > 0 { return errors.New("no snapshot paired state") } - return fmt.Errorf("associated state[%x] is not present", root) } } else { @@ -325,27 +298,18 @@ func (p *Pruner) Prune(root common.Hash) error { log.Info("Selecting user-specified state as the pruning target", "root", root) } } - // Before start the pruning, delete the clean trie cache first. - // It's necessary otherwise in the next restart we will hit the - // deleted state root in the "clean cache" so that the incomplete - // state is picked for usage. - deleteCleanTrieCache(p.config.Cachedir) - // All the state roots of the middle layer should be forcibly pruned, // otherwise the dangling state will be left. middleRoots := make(map[common.Hash]struct{}) - for _, layer := range layers { if layer.Root() == root { break } - middleRoots[layer.Root()] = struct{}{} } // Traverse the target state, re-construct the whole state trie and // commit to the given bloom filter. start := time.Now() - if err := snapshot.GenerateTrie(p.snaptree, root, p.db, p.stateBloom); err != nil { return err } @@ -354,17 +318,13 @@ func (p *Pruner) Prune(root common.Hash) error { if err := extractGenesis(p.db, p.stateBloom); err != nil { return err } - filterName := bloomFilterName(p.config.Datadir, root) log.Info("Writing state bloom to disk", "name", filterName) - if err := p.stateBloom.Commit(filterName, filterName+stateBloomFileTempSuffix); err != nil { return err } - log.Info("State bloom filter committed", "name", filterName) - return prune(p.snaptree, root, p.db, p.stateBloom, filterName, middleRoots, start) } @@ -375,16 +335,14 @@ func (p *Pruner) Prune(root common.Hash) error { // pruning can be resumed. What's more if the bloom filter is constructed, the // pruning **has to be resumed**. Otherwise a lot of dangling nodes may be left // in the disk. -func RecoverPruning(datadir string, db ethdb.Database, trieCachePath string) error { +func RecoverPruning(datadir string, db ethdb.Database) error { stateBloomPath, stateBloomRoot, err := findBloomFilter(datadir) if err != nil { return err } - if stateBloomPath == "" { return nil // nothing to recover } - headBlock := rawdb.ReadHeadBlock(db) if headBlock == nil { return errors.New("failed to load head block") @@ -403,25 +361,16 @@ func RecoverPruning(datadir string, db ethdb.Database, trieCachePath string) err NoBuild: true, AsyncBuild: false, } - snaptree, err := snapshot.New(snapconfig, db, trie.NewDatabase(db), headBlock.Root()) if err != nil { return err // The relevant snapshot(s) might not exist } - stateBloom, err := NewStateBloomFromDisk(stateBloomPath) if err != nil { return err } - log.Info("Loaded state bloom filter", "path", stateBloomPath) - // Before start the pruning, delete the clean trie cache first. - // It's necessary otherwise in the next restart we will hit the - // deleted state root in the "clean cache" so that the incomplete - // state is picked for usage. - deleteCleanTrieCache(trieCachePath) - // All the state roots of the middle layers should be forcibly pruned, // otherwise the dangling state will be left. var ( @@ -429,21 +378,17 @@ func RecoverPruning(datadir string, db ethdb.Database, trieCachePath string) err layers = snaptree.Snapshots(headBlock.Root(), 128, true) middleRoots = make(map[common.Hash]struct{}) ) - for _, layer := range layers { if layer.Root() == stateBloomRoot { found = true break } - middleRoots[layer.Root()] = struct{}{} } - if !found { log.Error("Pruning target state is not existent") return errors.New("non-existent target state") } - return prune(snaptree, stateBloomRoot, db, stateBloom, stateBloomPath, middleRoots, time.Now()) } @@ -454,17 +399,14 @@ func extractGenesis(db ethdb.Database, stateBloom *stateBloom) error { if genesisHash == (common.Hash{}) { return errors.New("missing genesis hash") } - genesis := rawdb.ReadBlock(db, genesisHash, 0) if genesis == nil { return errors.New("missing genesis block") } - t, err := trie.NewStateTrie(trie.StateTrieID(genesis.Root()), trie.NewDatabase(db)) if err != nil { return err } - accIter, err := t.NodeIterator(nil) if err != nil { return err @@ -483,15 +425,12 @@ func extractGenesis(db ethdb.Database, stateBloom *stateBloom) error { if err := rlp.DecodeBytes(accIter.LeafBlob(), &acc); err != nil { return err } - if acc.Root != types.EmptyRootHash { id := trie.StorageTrieID(genesis.Root(), common.BytesToHash(accIter.LeafKey()), acc.Root) - storageTrie, err := trie.NewStateTrie(id, trie.NewDatabase(db)) if err != nil { return err } - storageIter, err := storageTrie.NodeIterator(nil) if err != nil { return err @@ -502,18 +441,15 @@ func extractGenesis(db ethdb.Database, stateBloom *stateBloom) error { stateBloom.Put(hash.Bytes(), nil) } } - if storageIter.Error() != nil { return storageIter.Error() } } - if !bytes.Equal(acc.CodeHash, types.EmptyCodeHash.Bytes()) { stateBloom.Put(acc.CodeHash, nil) } } } - return accIter.Error() } @@ -526,7 +462,6 @@ func isBloomFilter(filename string) (bool, common.Hash) { if strings.HasPrefix(filename, stateBloomFilePrefix) && strings.HasSuffix(filename, stateBloomFileSuffix) { return true, common.HexToHash(filename[len(stateBloomFilePrefix)+1 : len(filename)-len(stateBloomFileSuffix)-1]) } - return false, common.Hash{} } @@ -535,7 +470,6 @@ func findBloomFilter(datadir string) (string, common.Hash, error) { stateBloomPath string stateBloomRoot common.Hash ) - if err := filepath.Walk(datadir, func(path string, info os.FileInfo, err error) error { if info != nil && !info.IsDir() { ok, root := isBloomFilter(path) @@ -548,27 +482,5 @@ func findBloomFilter(datadir string) (string, common.Hash, error) { }); err != nil { return "", common.Hash{}, err } - return stateBloomPath, stateBloomRoot, nil } - -const warningLog = ` - -WARNING! - -The clean trie cache is not found. Please delete it by yourself after the -pruning. Remember don't start the Geth without deleting the clean trie cache -otherwise the entire database may be damaged! - -Check the command description "geth snapshot prune-state --help" for more details. -` - -func deleteCleanTrieCache(path string) { - if !common.FileExist(path) { - log.Warn(warningLog) - return - } - - os.RemoveAll(path) - log.Info("Deleted trie clean cache", "path", path) -} diff --git a/eth/backend.go b/eth/backend.go index 81b794283e..12af9046cc 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -143,7 +143,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { if err != nil { return nil, err } - if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb, ""); err != nil { + if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb); err != nil { log.Error("Failed to recover state", "error", err) } From 930c9463886d7695b1335b7daf275eb88514a8a7 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Tue, 2 Jan 2024 15:06:41 +0100 Subject: [PATCH 26/49] chg: bump some deps for sec vulsn (#1114) * chg: bump some deps for sec vulsn * chg: use newer matic-cli and node version --- .github/workflows/ci.yml | 6 +++--- go.mod | 6 +++--- go.sum | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d8c35d572..f339deb474 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,7 +106,7 @@ jobs: - name: Test run: make test - + - uses: actions/upload-artifact@v2 with: name: unitTest-coverage @@ -217,7 +217,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: '16.17.1' + node-version: '18.19.0' cache: 'npm' cache-dependency-path: | matic-cli/package-lock.json @@ -231,7 +231,7 @@ jobs: npm install --prefer-offline --no-audit --progress=false mkdir devnet cd devnet - ../bin/matic-cli setup devnet -c ../../bor/.github/matic-cli-config.yml + ../bin/matic-cli.js setup devnet -c ../../bor/.github/matic-cli-config.yml - name: Launch devnet run: | diff --git a/go.mod b/go.mod index e0743c33e5..d26aab17b2 100644 --- a/go.mod +++ b/go.mod @@ -81,11 +81,11 @@ require ( github.com/tyler-smith/go-bip39 v1.1.0 github.com/urfave/cli/v2 v2.24.1 go.uber.org/automaxprocs v1.5.2 - golang.org/x/crypto v0.14.0 + golang.org/x/crypto v0.17.0 golang.org/x/exp v0.0.0-20230810033253-352e893a4cad golang.org/x/sync v0.3.0 - golang.org/x/sys v0.13.0 - golang.org/x/text v0.13.0 + golang.org/x/sys v0.15.0 + golang.org/x/text v0.14.0 golang.org/x/time v0.3.0 golang.org/x/tools v0.10.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0 diff --git a/go.sum b/go.sum index 4fedf2b11b..fd6c869cc7 100644 --- a/go.sum +++ b/go.sum @@ -2256,8 +2256,8 @@ golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -2618,8 +2618,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -2651,8 +2651,8 @@ golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From a517342e6f6d63ff54f48de424d4382607c4801e Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 11 Jan 2024 10:28:43 +0530 Subject: [PATCH 27/49] update version --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 3b63ec6f95..0ab4453759 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.2-beta +Version: 1.2.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index a2c15ad001..19405907ee 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.2-beta +Version: 1.2.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index c346b361de..258d94c534 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.2-beta +Version: 1.2.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index b1943f90fd..803d01365e 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.2-beta +Version: 1.2.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 797086ba18..6bb38c5958 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.2-beta +Version: 1.2.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index d701656a88..c5d00f3d4c 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.2-beta +Version: 1.2.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index 4e8a641e74..1a9308fa81 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 2 // Patch version component of the current release - VersionMeta = "beta" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 2 // Patch version component of the current release + VersionMeta = "" // Version metadata to append to the version string ) var GitCommit string From 1e5211c1c7d9968655cc3287cfab9868f5922121 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Fri, 12 Jan 2024 20:45:10 +0530 Subject: [PATCH 28/49] add test cases --- core/vm/contracts.go | 34 +++++++------------- core/vm/contracts_test.go | 6 ++-- core/vm/testdata/precompiles/p256Verify.json | 28 ++++++++++++++++ params/config.go | 9 +----- 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 70eb0748ad..9e907f97b2 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -96,16 +96,17 @@ var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{ // PrecompiledContractsCancun contains the default set of pre-compiled Ethereum // contracts used in the Cancun release. var PrecompiledContractsCancun = 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{eip2565: true}, - common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, - common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, + 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{eip2565: true}, + common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, + common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, } // PrecompiledContractsBLS contains the set of pre-compiled Ethereum @@ -122,14 +123,7 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{18}): &bls12381MapG2{}, } -// PrecompiledContractsNapoli contains the precompiled Ethereum -// contract specified in EIP-7212. This is exported for testing purposes. -var PrecompiledContractsNapoli = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{19}): &p256Verify{}, -} - var ( - PrecompiledAddressesNapoli []common.Address PrecompiledAddressesCancun []common.Address PrecompiledAddressesBerlin []common.Address PrecompiledAddressesIstanbul []common.Address @@ -156,17 +150,11 @@ func init() { for k := range PrecompiledContractsCancun { PrecompiledAddressesCancun = append(PrecompiledAddressesCancun, k) } - - for k := range PrecompiledContractsNapoli { - PrecompiledAddressesNapoli = append(PrecompiledAddressesNapoli, k) - } } // ActivePrecompiles returns the precompiles enabled with the current configuration. func ActivePrecompiles(rules params.Rules) []common.Address { switch { - case rules.IsNapoli: - return PrecompiledAddressesNapoli case rules.IsCancun: return PrecompiledAddressesCancun case rules.IsBerlin: diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index f791cebc73..021dfe48eb 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -67,7 +67,7 @@ var allPrecompiles = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{0x0f, 0x10}): &bls12381Pairing{}, common.BytesToAddress([]byte{0x0f, 0x11}): &bls12381MapG1{}, common.BytesToAddress([]byte{0x0f, 0x12}): &bls12381MapG2{}, - common.BytesToAddress([]byte{19}): &p256Verify{}, + common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, } // EIP-152 test vectors @@ -424,11 +424,11 @@ func BenchmarkPrecompiledP256Verify(bench *testing.B) { Expected: "0000000000000000000000000000000000000000000000000000000000000001", Name: "p256Verify", } - benchmarkPrecompiled("13", t, bench) + benchmarkPrecompiled("100", t, bench) } func TestPrecompiledP256Verify(t *testing.T) { t.Parallel() - testJson("p256Verify", "13", t) + testJson("p256Verify", "100", t) } diff --git a/core/vm/testdata/precompiles/p256Verify.json b/core/vm/testdata/precompiles/p256Verify.json index c01387dda7..54723147a5 100644 --- a/core/vm/testdata/precompiles/p256Verify.json +++ b/core/vm/testdata/precompiles/p256Verify.json @@ -5,5 +5,33 @@ "Gas": 3450, "Name": "CallP256Verify", "NoBenchmark": false + }, + { + "Input": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9414de3726ee4d237b410c1d85ebcb05553dc578561d9f7942b7250795beb9b9027b657067322fc00ab35263fde0acabf998cd9fcf1282df9555f85dba7bdbbe2dc90f74c9e210bc3e0c60aeaa03729c9e6acde4a048ee58fd2e466c1e7b0374e606b8c22ad2985df7d792ff344f03ce94a079da801006b13640bc5af7932a7b9", + "Expected": "0000000000000000000000000000000000000000000000000000000000000001", + "Gas": 3450, + "Name": "CallP256Verify", + "NoBenchmark": false + }, + { + "Input": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9b35d6a4f7f6fc5620c97d4287696f5174b3d37fa537b74b5fc26997ba79c725d62fe5e5fe6da76eec924e822c5ef853ede6c17069a9e9133a38f87d61599f68e7d5f3c812a255436846ee84a262b79ec4d0783afccf2433deabdca9ecf62bef5ff24e90988c7f139d378549c3a8bc6c94e6a1c911c1e02e6f48ed65aaf3d296e", + "Expected": "0000000000000000000000000000000000000000000000000000000000000001", + "Gas": 3450, + "Name": "CallP256Verify", + "NoBenchmark": false + }, + { + "Input": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9c29c3df6ce3431b6f030b1b68b1589508ad9d1a149830489c638653aa4b08af93f6e86a9a7643403b6f5c593410d9f7234a8cd27309bce90447073ce17476850615ff147863bc8652be1e369444f90bbc5f9df05a26362e609f73ab1f1839fe3cd34fd2ae672c110671d49115825fc56b5148321aabe5ba39f2b46f71149cff9", + "Expected": "", + "Gas": 3450, + "Name": "CallP256Verify", + "NoBenchmark": false + }, + { + "Input": "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", + "Expected": "", + "Gas": 3450, + "Name": "CallP256Verify", + "NoBenchmark": false } ] \ No newline at end of file diff --git a/params/config.go b/params/config.go index 3184c4416d..ea00979850 100644 --- a/params/config.go +++ b/params/config.go @@ -518,7 +518,6 @@ type ChainConfig struct { CancunBlock *big.Int `json:"cancunBlock,omitempty"` // Cancun switch Block (nil = no fork, 0 = already on cancun) PragueBlock *big.Int `json:"pragueBlock,omitempty"` // Prague switch Block (nil = no fork, 0 = already on prague) VerkleBlock *big.Int `json:"verkleBlock,omitempty"` // Verkle switch Block (nil = no fork, 0 = already on verkle) - NapoliBlock *big.Int `json:"napoliBlock,omitempty"` // Napoli switch Block (nil = no fork, 0 = already on Napoli) // TerminalTotalDifficulty is the amount of total difficulty reached by // the network that triggers the consensus upgrade. @@ -858,11 +857,6 @@ func (c *ChainConfig) IsPrague(num *big.Int) bool { return isBlockForked(c.PragueBlock, num) } -// IsNapoli returns whether num is either equal to the Napoli fork block or greater. -func (c *ChainConfig) IsNapoli(num *big.Int) bool { - return isBlockForked(c.NapoliBlock, num) -} - // CheckCompatible checks whether scheduled fork transitions have been imported // with a mismatching chain configuration. func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64, time uint64) *ConfigCompatError { @@ -1151,7 +1145,7 @@ type Rules struct { IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool IsBerlin, IsLondon bool IsMerge, IsShanghai, IsCancun, IsPrague bool - IsVerkle, IsNapoli bool + IsVerkle bool } // Rules ensures c's ChainID is not nil. @@ -1177,6 +1171,5 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsShanghai: c.IsShanghai(num), IsCancun: c.IsCancun(num), IsPrague: c.IsPrague(num), - IsNapoli: c.IsNapoli(num), } } From b54c9b93d246e9cc16e462a6c6a09230a16898d6 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Sat, 13 Jan 2024 11:15:33 +0530 Subject: [PATCH 29/49] chg: make HF consistent --- params/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/params/config.go b/params/config.go index ea00979850..6188a698f4 100644 --- a/params/config.go +++ b/params/config.go @@ -912,9 +912,9 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true}, {name: "grayGlacierBlock", block: c.GrayGlacierBlock, optional: true}, {name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true}, - {name: "ShanghaiBlock", block: c.ShanghaiBlock}, - {name: "CancunBlock", block: c.CancunBlock, optional: true}, - {name: "pragueTime", block: c.PragueBlock, optional: true}, + {name: "shanghaiBlock", block: c.ShanghaiBlock}, + {name: "cancunBlock", block: c.CancunBlock, optional: true}, + {name: "pragueBlock", block: c.PragueBlock, optional: true}, } { if lastFork.name != "" { switch { From dac1a42fa8390dad156c23cb1f1e78ff60bde9ee Mon Sep 17 00:00:00 2001 From: PeaStew <34198053+PeaStew@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:46:15 +0100 Subject: [PATCH 30/49] Update client.go to allow the use of paths with the heimdall url (#1126) * Update client.go to allow the use of paths with the heimdall url As reported to the polygon team 2 months ago in the Ankr polygon slack, the current code prevents the use of a path with the heimdall url, this was fixed in erigon ledgerwatch/erigon@a3a6170 in response to my request by Mark Holt, and it seems this code was just copied from bor where it is incorrect too. This patch fixes that. * Add reference to path library * Fix reversed order of values in unit tests and test removal of setting u.path to rawPath (otherwise why do we need rawPath at all) seems like there were work arounds done here in bioth the unit tests AND the makeURL but logic needs to be examined --- consensus/bor/heimdall/client.go | 3 ++- consensus/bor/heimdall/client_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/consensus/bor/heimdall/client.go b/consensus/bor/heimdall/client.go index d69f5ead3c..5c65721574 100644 --- a/consensus/bor/heimdall/client.go +++ b/consensus/bor/heimdall/client.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "net/url" + "path" "sort" "time" @@ -420,7 +421,7 @@ func makeURL(urlString, rawPath, rawQuery string) (*url.URL, error) { return nil, err } - u.Path = rawPath + u.Path = path.Join(u.Path, rawPath) u.RawQuery = rawQuery return u, err diff --git a/consensus/bor/heimdall/client_test.go b/consensus/bor/heimdall/client_test.go index 5023b847a5..737875028c 100644 --- a/consensus/bor/heimdall/client_test.go +++ b/consensus/bor/heimdall/client_test.go @@ -399,7 +399,7 @@ func TestSpanURL(t *testing.T) { const expected = "http://bor0/bor/span/1" if url.String() != expected { - t.Fatalf("expected URL %q, got %q", url.String(), expected) + t.Fatalf("expected URL %q, got %q", expected, url.String()) } } @@ -414,6 +414,6 @@ func TestStateSyncURL(t *testing.T) { const expected = "http://bor0/clerk/event-record/list?from-id=10&to-time=100&limit=50" if url.String() != expected { - t.Fatalf("expected URL %q, got %q", url.String(), expected) + t.Fatalf("expected URL %q, got %q", expected, url.String()) } } From 70e4fe96575d055c1e9f57435fc8fdbfa79f8251 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Fri, 19 Jan 2024 16:47:29 +0530 Subject: [PATCH 31/49] internal/ethapi: fix call with state api --- internal/ethapi/api.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 83b8f22edf..25c6ab97f6 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1264,12 +1264,31 @@ func doCallWithState(ctx context.Context, b Backend, args TransactionArgs, heade return result, nil } -func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides, timeout time.Duration, globalGasCap uint64) (*core.ExecutionResult, error) { +func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, state *state.StateDB, overrides *StateOverride, blockOverrides *BlockOverrides, timeout time.Duration, globalGasCap uint64) (*core.ExecutionResult, error) { defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now()) - state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) - if state == nil || err != nil { - return nil, err + var ( + header *types.Header + err error + ) + + // BOR: This is used by bor consensus to fetch data from genesis contracts for state-sync + // Fetch the state and header from blockNumberOrHash if it's coming from normal eth_call path. + if state == nil { + state, header, err = b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) + if state == nil || err != nil { + return nil, err + } + } else { + // Fetch the header from the given blockNumberOrHash. Note that this path is only taken + // when we're doing a call from bor consensus to fetch data from genesis contracts. It's + // necessary to fetch header using header hash as we might be experiencing a reorg and there + // can be multiple headers with same number. + header, err = b.HeaderByHash(ctx, *blockNrOrHash.BlockHash) + if header == nil || err != nil { + log.Warn("Error fetching header on CallWithState", "err", err) + return nil, err + } } return doCall(ctx, b, args, state, header, overrides, blockOverrides, timeout, globalGasCap) @@ -1327,7 +1346,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO // Note, this function doesn't make and changes in the state/blockchain and is // useful to execute and retrieve values. func (s *BlockChainAPI) CallWithState(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, state *state.StateDB, overrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) { - result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap()) + result, err := DoCall(ctx, s.b, args, blockNrOrHash, state, overrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap()) if err != nil { return nil, err } From f92c3c0c9bdc129c4b19bed4ca740f8892898aaf Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Fri, 19 Jan 2024 16:47:37 +0530 Subject: [PATCH 32/49] graphql: fix eth call params --- graphql/graphql.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index 7aa427b458..f03644eeb4 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -1121,7 +1121,7 @@ func (c *CallResult) Status() hexutil.Uint64 { func (b *Block) Call(ctx context.Context, args struct { Data ethapi.TransactionArgs }) (*CallResult, error) { - result, err := ethapi.DoCall(ctx, b.r.backend, args.Data, *b.numberOrHash, nil, nil, b.r.backend.RPCEVMTimeout(), b.r.backend.RPCGasCap()) + result, err := ethapi.DoCall(ctx, b.r.backend, args.Data, *b.numberOrHash, nil, nil, nil, b.r.backend.RPCEVMTimeout(), b.r.backend.RPCGasCap()) if err != nil { return nil, err } @@ -1184,7 +1184,7 @@ func (p *Pending) Call(ctx context.Context, args struct { Data ethapi.TransactionArgs }) (*CallResult, error) { pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) - result, err := ethapi.DoCall(ctx, p.r.backend, args.Data, pendingBlockNr, nil, nil, p.r.backend.RPCEVMTimeout(), p.r.backend.RPCGasCap()) + result, err := ethapi.DoCall(ctx, p.r.backend, args.Data, pendingBlockNr, nil, nil, nil, p.r.backend.RPCEVMTimeout(), p.r.backend.RPCGasCap()) if err != nil { return nil, err } From 0c08204d7dcd4a7916bef5772d58757978c55a8a Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Thu, 18 Jan 2024 13:11:50 +0530 Subject: [PATCH 33/49] integration-tests: update ipc path on ci tests (#1127) * integration-tests: update ipc path on ci tests * added devnetBorFlags in matic-cli-config.yml --------- Co-authored-by: Pratik Patil --- .github/matic-cli-config.yml | 1 + integration-tests/bor_health.sh | 4 ++-- integration-tests/smoke_test.sh | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/matic-cli-config.yml b/.github/matic-cli-config.yml index 8c31e17dc6..e3200ec8b8 100644 --- a/.github/matic-cli-config.yml +++ b/.github/matic-cli-config.yml @@ -23,3 +23,4 @@ borDockerBuildContext: "../../bor" heimdallDockerBuildContext: "https://github.com/maticnetwork/heimdall.git#develop" sprintSizeBlockNumber: - '0' +devnetBorFlags: config,config,config diff --git a/integration-tests/bor_health.sh b/integration-tests/bor_health.sh index 3288739f85..63aba9aab1 100644 --- a/integration-tests/bor_health.sh +++ b/integration-tests/bor_health.sh @@ -3,8 +3,8 @@ set -e while true do - peers=$(docker exec bor0 bash -c "bor attach /root/.bor/data/bor.ipc -exec 'admin.peers'") - block=$(docker exec bor0 bash -c "bor attach /root/.bor/data/bor.ipc -exec 'eth.blockNumber'") + peers=$(docker exec bor0 bash -c "bor attach /root/var/lib/bor/data/bor.ipc -exec 'admin.peers'") + block=$(docker exec bor0 bash -c "bor attach /root/var/lib/bor/data/bor.ipc -exec 'eth.blockNumber'") if [[ -n "$peers" ]] && [[ -n "$block" ]]; then break diff --git a/integration-tests/smoke_test.sh b/integration-tests/smoke_test.sh index 62ca370ee7..9275093b16 100644 --- a/integration-tests/smoke_test.sh +++ b/integration-tests/smoke_test.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -balanceInit=$(docker exec bor0 bash -c "bor attach /root/.bor/data/bor.ipc -exec 'Math.round(web3.fromWei(eth.getBalance(eth.accounts[0])))'") +balanceInit=$(docker exec bor0 bash -c "bor attach /root/var/lib/bor/data/bor.ipc -exec 'Math.round(web3.fromWei(eth.getBalance(eth.accounts[0])))'") stateSyncFound="false" checkpointFound="false" @@ -11,7 +11,7 @@ start_time=$SECONDS while true do - balance=$(docker exec bor0 bash -c "bor attach /root/.bor/data/bor.ipc -exec 'Math.round(web3.fromWei(eth.getBalance(eth.accounts[0])))'") + balance=$(docker exec bor0 bash -c "bor attach /root/var/lib/bor/data/bor.ipc -exec 'Math.round(web3.fromWei(eth.getBalance(eth.accounts[0])))'") if ! [[ "$balance" =~ ^[0-9]+$ ]]; then echo "Something is wrong! Can't find the balance of first account in bor network." From 5fc30aeaac2b143eb4163b12547c6bbb007c381a Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Fri, 19 Jan 2024 17:19:12 +0530 Subject: [PATCH 34/49] Revert "Consistent" --- consensus/bor/bor.go | 4 - consensus/bor/bor_test.go | 31 +-- core/txpool/legacypool/legacypool.go | 16 +- core/txpool/validation.go | 4 +- core/types/transaction_signing.go | 35 --- core/vm/contracts.go | 56 +---- core/vm/contracts_test.go | 17 -- core/vm/testdata/precompiles/p256Verify.json | 37 --- crypto/secp256r1/publickey.go | 26 -- crypto/secp256r1/verifier.go | 21 -- eth/backend.go | 3 +- eth/bor_api_backend.go | 15 ++ internal/cli/server/config_legacy_test.go | 19 -- internal/cli/server/testdata/default.toml | 193 --------------- internal/ethapi/api.go | 15 +- internal/ethapi/api_test.go | 248 ------------------- params/config.go | 12 +- params/protocol_params.go | 2 - 18 files changed, 50 insertions(+), 704 deletions(-) delete mode 100644 core/vm/testdata/precompiles/p256Verify.json delete mode 100644 crypto/secp256r1/publickey.go delete mode 100644 crypto/secp256r1/verifier.go delete mode 100644 internal/cli/server/testdata/default.toml diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index c54eef564b..24590ea516 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -883,10 +883,6 @@ func (c *Bor) changeContractCodeIfNeeded(headerNumber uint64, state *state.State for addr, account := range allocs { log.Info("change contract code", "address", addr) state.SetCode(addr, account.Code) - - if state.GetBalance(addr).Cmp(big.NewInt(0)) == 0 { - state.SetBalance(addr, account.Balance) - } } } } diff --git a/consensus/bor/bor_test.go b/consensus/bor/bor_test.go index ca60d5f66f..52c93c77ad 100644 --- a/consensus/bor/bor_test.go +++ b/consensus/bor/bor_test.go @@ -40,12 +40,6 @@ func TestGenesisContractChange(t *testing.T) { "balance": "0x1000", }, }, - "6": map[string]interface{}{ - addr0.Hex(): map[string]interface{}{ - "code": hexutil.Bytes{0x1, 0x4}, - "balance": "0x2000", - }, - }, }, }, } @@ -91,35 +85,24 @@ func TestGenesisContractChange(t *testing.T) { root := genesis.Root() - // code does not change, balance remains 0 + // code does not change root, statedb = addBlock(root, 1) require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x1}) - require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0)) - // code changes 1st time, balance remains 0 + // code changes 1st time root, statedb = addBlock(root, 2) require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x2}) - require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0)) - // code same as 1st change, balance remains 0 + // code same as 1st change root, statedb = addBlock(root, 3) require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x2}) - require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0)) - - // code changes 2nd time, balance updates to 4096 - root, statedb = addBlock(root, 4) - require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x3}) - require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096)) - // code same as 2nd change, balance remains 4096 - root, statedb = addBlock(root, 5) + // code changes 2nd time + _, statedb = addBlock(root, 4) require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x3}) - require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096)) - // code changes 3rd time, balance remains 4096 - _, statedb = addBlock(root, 6) - require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x4}) - require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096)) + // make sure balance change DOES NOT take effect + require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0)) } func TestEncodeSigHeaderJaipur(t *testing.T) { diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index d37f5ef4bc..db4af0ee8d 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -159,8 +159,7 @@ var DefaultConfig = Config{ AccountQueue: 64, GlobalQueue: 1024, - Lifetime: 3 * time.Hour, - AllowUnprotectedTxs: false, + Lifetime: 3 * time.Hour, } // sanitize checks the provided user configurations and changes anything that's @@ -591,8 +590,7 @@ func (pool *LegacyPool) local() map[common.Address]types.Transactions { // and does not require the pool mutex to be held. func (pool *LegacyPool) validateTxBasics(tx *types.Transaction, local bool) error { opts := &txpool.ValidationOptions{ - Config: pool.chainconfig, - AllowUnprotectedTxs: pool.config.AllowUnprotectedTxs, + Config: pool.chainconfig, Accept: 0 | 1<= 0 } -// IsShanghai returns whether num is either equal to the Shanghai fork block or greater. +// IsShanghai returns whether time is either equal to the Shanghai fork time or greater. func (c *ChainConfig) IsShanghai(num *big.Int) bool { return isBlockForked(c.ShanghaiBlock, num) } -// IsCancun returns whether num is either equal to the Cancun fork block or greater. +// IsCancun returns whether num is either equal to the Cancun fork time or greater. func (c *ChainConfig) IsCancun(num *big.Int) bool { return isBlockForked(c.CancunBlock, num) } -// IsPrague returns whether num is either equal to the Prague fork block or greater. +// IsPrague returns whether num is either equal to the Prague fork time or greater. func (c *ChainConfig) IsPrague(num *big.Int) bool { return isBlockForked(c.PragueBlock, num) } @@ -912,9 +912,9 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true}, {name: "grayGlacierBlock", block: c.GrayGlacierBlock, optional: true}, {name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true}, - {name: "shanghaiBlock", block: c.ShanghaiBlock}, - {name: "cancunBlock", block: c.CancunBlock, optional: true}, - {name: "pragueBlock", block: c.PragueBlock, optional: true}, + {name: "ShanghaiBlock", block: c.ShanghaiBlock}, + {name: "CancunBlock", block: c.CancunBlock, optional: true}, + {name: "pragueTime", block: c.PragueBlock, optional: true}, } { if lastFork.name != "" { switch { diff --git a/params/protocol_params.go b/params/protocol_params.go index ef5f267172..8eb5e247a9 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -160,8 +160,6 @@ const ( 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 - 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, // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529 RefundQuotient uint64 = 2 From 8d164b976a22f00fe3aaf14fc7e2000e7dee8794 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Fri, 19 Jan 2024 17:34:28 +0530 Subject: [PATCH 35/49] remove: kgz precompile --- core/vm/contracts.go | 1 - 1 file changed, 1 deletion(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index fe7c770815..3ccaf61667 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -104,7 +104,6 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, common.BytesToAddress([]byte{9}): &blake2F{}, - common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, } // PrecompiledContractsBLS contains the set of pre-compiled Ethereum From e070986483b70c9c076cf8640929b4c8e444d15d Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Fri, 19 Jan 2024 17:35:17 +0530 Subject: [PATCH 36/49] remove: kgz precompile --- core/vm/contracts.go | 1 - 1 file changed, 1 deletion(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 9e907f97b2..382c1ab405 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -105,7 +105,6 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, common.BytesToAddress([]byte{9}): &blake2F{}, - common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, } From eb528aee718a1db8772ac41f045ceb567e93c2a1 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Fri, 19 Jan 2024 19:07:39 +0530 Subject: [PATCH 37/49] update version --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- packaging/templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 0ab4453759..94eeea3661 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.2 +Version: 1.2.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 19405907ee..809d705aa6 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.2 +Version: 1.2.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 258d94c534..22470ccd49 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.2 +Version: 1.2.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 803d01365e..4a52b2e063 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.2 +Version: 1.2.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 6bb38c5958..00b517c3b0 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.2 +Version: 1.2.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index c5d00f3d4c..725a4ec394 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.2 +Version: 1.2.3 Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index 1a9308fa81..b44ab8079c 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 2 // Minor version component of the current release - VersionPatch = 2 // Patch version component of the current release + VersionPatch = 3 // Patch version component of the current release VersionMeta = "" // Version metadata to append to the version string ) From c629c0fdb67ff801c09b08d77b80585ad9a6a68b Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Mon, 22 Jan 2024 21:10:45 +0800 Subject: [PATCH 38/49] break loop when delayFlag becomes false (#1121) --- miner/worker.go | 1 + 1 file changed, 1 insertion(+) diff --git a/miner/worker.go b/miner/worker.go index 7e2e0b8650..4a92776f56 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1124,6 +1124,7 @@ mainloop: if ok1 || ok2 { delayFlag = false + break } for j := range deps[i] { From c559619c805ec6a80fd7012428190933d64b40db Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Mon, 22 Jan 2024 20:47:47 +0530 Subject: [PATCH 39/49] fix bug: should use Lock when mutating the flag (#1141) * should use Lock when mutating the flag * same problem in MVHashMap.Write * hole the rlock while reading WriteCell --------- Co-authored-by: zhiqiangxu <652732310@qq.com> --- core/blockstm/mvhashmap.go | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/core/blockstm/mvhashmap.go b/core/blockstm/mvhashmap.go index 59085138cf..003de91e70 100644 --- a/core/blockstm/mvhashmap.go +++ b/core/blockstm/mvhashmap.go @@ -121,34 +121,23 @@ func (mv *MVHashMap) Write(k Key, v Version, data interface{}) { return }) - cells.rw.RLock() - ci, ok := cells.tm.Get(v.TxnIndex) - cells.rw.RUnlock() - - if ok { + cells.rw.Lock() + if ci, ok := cells.tm.Get(v.TxnIndex); !ok { + cells.tm.Put(v.TxnIndex, &WriteCell{ + flag: FlagDone, + incarnation: v.Incarnation, + data: data, + }) + } else { if ci.(*WriteCell).incarnation > v.Incarnation { panic(fmt.Errorf("existing transaction value does not have lower incarnation: %v, %v", k, v.TxnIndex)) } - ci.(*WriteCell).flag = FlagDone ci.(*WriteCell).incarnation = v.Incarnation ci.(*WriteCell).data = data - } else { - cells.rw.Lock() - if ci, ok = cells.tm.Get(v.TxnIndex); !ok { - cells.tm.Put(v.TxnIndex, &WriteCell{ - flag: FlagDone, - incarnation: v.Incarnation, - data: data, - }) - } else { - ci.(*WriteCell).flag = FlagDone - ci.(*WriteCell).incarnation = v.Incarnation - ci.(*WriteCell).data = data - } - cells.rw.Unlock() } + cells.rw.Unlock() } func (mv *MVHashMap) ReadStorage(k Key, fallBack func() any) any { @@ -166,13 +155,13 @@ func (mv *MVHashMap) MarkEstimate(k Key, txIdx int) { panic(fmt.Errorf("path must already exist")) }) - cells.rw.RLock() + cells.rw.Lock() if ci, ok := cells.tm.Get(txIdx); !ok { panic(fmt.Sprintf("should not happen - cell should be present for path. TxIdx: %v, path, %x, cells keys: %v", txIdx, k, cells.tm.Keys())) } else { ci.(*WriteCell).flag = FlagEstimate } - cells.rw.RUnlock() + cells.rw.Unlock() } func (mv *MVHashMap) Delete(k Key, txIdx int) { @@ -233,8 +222,8 @@ func (mv *MVHashMap) Read(k Key, txIdx int) (res MVReadResult) { } cells.rw.RLock() + fk, fv := cells.tm.Floor(txIdx - 1) - cells.rw.RUnlock() if fk != nil && fv != nil { c := fv.(*WriteCell) @@ -253,6 +242,8 @@ func (mv *MVHashMap) Read(k Key, txIdx int) (res MVReadResult) { } } + cells.rw.RUnlock() + return } From f1e0b1d9261977725b8437946cf5ee46590620eb Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Tue, 23 Jan 2024 10:52:00 +0530 Subject: [PATCH 40/49] Changed parallel universe HF to Cancun HF and some important fixes (#1132) * changed parallel universe HF to napoli HF * integration-tests: update ipc path on ci tests (#1127) * integration-tests: update ipc path on ci tests * added devnetBorFlags in matic-cli-config.yml --------- Co-authored-by: Pratik Patil * Revert "integration-tests: update ipc path on ci tests (#1127)" This reverts commit 0660fac39b5d5a31cd4da54e48b4ca8eda4d7cb4. * using cancun for block-stm metadata instead of napoli * added a check to verify tx dependencies and test cases * fix in snapshot.chainConfig * removed snapshot.*params.BorConfig using snapshot.chainConfig.Bor instead * removed unnecessary if statement in ParallelStateProcessor.Process * addressed comment * small fix in commitTransactions * dependency calculation bug fix in miner/worker.go --------- Co-authored-by: Manav Darji Co-authored-by: Arpit Temani --- builder/files/genesis-mainnet-v1.json | 1 - builder/files/genesis-testnet-v4.json | 1 - consensus/bor/bor.go | 16 ++-- consensus/bor/snapshot.go | 25 ++--- core/parallel_state_processor.go | 96 +++++++++---------- core/parallel_state_processor_test.go | 30 ++++++ core/types/block.go | 4 +- core/types/block_test.go | 1 - internal/cli/server/chains/mainnet.go | 7 +- internal/cli/server/chains/mumbai.go | 7 +- .../chains/test_files/chain_legacy_test.json | 1 - .../server/chains/test_files/chain_test.json | 1 - miner/worker.go | 60 ++++++------ miner/worker_test.go | 2 +- params/config.go | 34 +++---- 15 files changed, 148 insertions(+), 138 deletions(-) create mode 100644 core/parallel_state_processor_test.go diff --git a/builder/files/genesis-mainnet-v1.json b/builder/files/genesis-mainnet-v1.json index f4b2e4a6b4..11d64cabab 100644 --- a/builder/files/genesis-mainnet-v1.json +++ b/builder/files/genesis-mainnet-v1.json @@ -17,7 +17,6 @@ "bor": { "jaipurBlock": 23850000, "delhiBlock": 38189056, - "parallelUniverseBlock": 0, "indoreBlock": 44934656, "stateSyncConfirmationDelay": { "44934656": 128 diff --git a/builder/files/genesis-testnet-v4.json b/builder/files/genesis-testnet-v4.json index c848d5dce0..afad138492 100644 --- a/builder/files/genesis-testnet-v4.json +++ b/builder/files/genesis-testnet-v4.json @@ -17,7 +17,6 @@ "bor": { "jaipurBlock": 22770000, "delhiBlock": 29638656, - "parallelUniverseBlock": 0, "indoreBlock": 37075456, "stateSyncConfirmationDelay": { "37075456": 128 diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 24590ea516..40999f73c4 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -353,7 +353,7 @@ func (c *Bor) verifyHeader(chain consensus.ChainHeaderReader, header *types.Head isSprintEnd := IsSprintStart(number+1, c.config.CalculateSprint(number)) // Ensure that the extra-data contains a signer list on checkpoint, but none otherwise - signersBytes := len(header.GetValidatorBytes(c.config)) + signersBytes := len(header.GetValidatorBytes(c.chainConfig)) if !isSprintEnd && signersBytes != 0 { return errExtraValidators @@ -472,7 +472,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t sort.Sort(valset.ValidatorsByAddress(newValidators)) - headerVals, err := valset.ParseValidators(header.GetValidatorBytes(c.config)) + headerVals, err := valset.ParseValidators(header.GetValidatorBytes(c.chainConfig)) if err != nil { return err } @@ -490,7 +490,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t // verify the validator list in the last sprint block if IsSprintStart(number, c.config.CalculateSprint(number)) { - parentValidatorBytes := parent.GetValidatorBytes(c.config) + parentValidatorBytes := parent.GetValidatorBytes(c.chainConfig) validatorsBytes := make([]byte, len(snap.ValidatorSet.Validators)*validatorHeaderBytesLength) currentValidators := snap.ValidatorSet.Copy().Validators @@ -521,7 +521,7 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co val := valset.NewValidator(signer, 1000) validatorset := valset.NewValidatorSet([]*valset.Validator{val}) - snapshot := newSnapshot(c.config, c.signatures, number, hash, validatorset.Validators) + snapshot := newSnapshot(c.chainConfig, c.signatures, number, hash, validatorset.Validators) return snapshot, nil } @@ -541,7 +541,7 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co // If an on-disk checkpoint snapshot can be found, use that if number%checkpointInterval == 0 { - if s, err := loadSnapshot(c.config, c.signatures, c.db, hash); err == nil { + if s, err := loadSnapshot(c.chainConfig, c.config, c.signatures, c.db, hash); err == nil { log.Trace("Loaded snapshot from disk", "number", number, "hash", hash) snap = s @@ -570,7 +570,7 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co } // new snap shot - snap = newSnapshot(c.config, c.signatures, number, hash, validators) + snap = newSnapshot(c.chainConfig, c.signatures, number, hash, validators) if err := snap.store(c.db); err != nil { return nil, err } @@ -742,7 +742,7 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e // sort validator by address sort.Sort(valset.ValidatorsByAddress(newValidators)) - if c.config.IsParallelUniverse(header.Number) { + if c.chainConfig.IsCancun(header.Number) { var tempValidatorBytes []byte for _, validator := range newValidators { @@ -766,7 +766,7 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e header.Extra = append(header.Extra, validator.HeaderBytes()...) } } - } else if c.config.IsParallelUniverse(header.Number) { + } else if c.chainConfig.IsCancun(header.Number) { blockExtraData := &types.BlockExtraData{ ValidatorBytes: nil, TxDependency: nil, diff --git a/consensus/bor/snapshot.go b/consensus/bor/snapshot.go index 7ced09c3b8..87e3fb163c 100644 --- a/consensus/bor/snapshot.go +++ b/consensus/bor/snapshot.go @@ -15,8 +15,9 @@ import ( // Snapshot is the state of the authorization voting at a given point in time. type Snapshot struct { - config *params.BorConfig // Consensus engine parameters to fine tune behavior - sigcache *lru.ARCCache // Cache of recent block signatures to speed up ecrecover + chainConfig *params.ChainConfig + + sigcache *lru.ARCCache // Cache of recent block signatures to speed up ecrecover Number uint64 `json:"number"` // Block number where the snapshot was created Hash common.Hash `json:"hash"` // Block hash where the snapshot was created @@ -28,14 +29,14 @@ type Snapshot struct { // method does not initialize the set of recent signers, so only ever use if for // the genesis block. func newSnapshot( - config *params.BorConfig, + chainConfig *params.ChainConfig, sigcache *lru.ARCCache, number uint64, hash common.Hash, validators []*valset.Validator, ) *Snapshot { snap := &Snapshot{ - config: config, + chainConfig: chainConfig, sigcache: sigcache, Number: number, Hash: hash, @@ -47,7 +48,7 @@ func newSnapshot( } // loadSnapshot loads an existing snapshot from the database. -func loadSnapshot(config *params.BorConfig, sigcache *lru.ARCCache, db ethdb.Database, hash common.Hash) (*Snapshot, error) { +func loadSnapshot(chainConfig *params.ChainConfig, config *params.BorConfig, sigcache *lru.ARCCache, db ethdb.Database, hash common.Hash) (*Snapshot, error) { blob, err := db.Get(append([]byte("bor-"), hash[:]...)) if err != nil { return nil, err @@ -61,7 +62,7 @@ func loadSnapshot(config *params.BorConfig, sigcache *lru.ARCCache, db ethdb.Dat snap.ValidatorSet.UpdateValidatorMap() - snap.config = config + snap.chainConfig = chainConfig snap.sigcache = sigcache // update total voting power @@ -85,7 +86,7 @@ func (s *Snapshot) store(db ethdb.Database) error { // copy creates a deep copy of the snapshot, though not the individual votes. func (s *Snapshot) copy() *Snapshot { cpy := &Snapshot{ - config: s.config, + chainConfig: s.chainConfig, sigcache: s.sigcache, Number: s.Number, Hash: s.Hash, @@ -122,12 +123,12 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) { number := header.Number.Uint64() // Delete the oldest signer from the recent list to allow it signing again - if number >= s.config.CalculateSprint(number) { - delete(snap.Recents, number-s.config.CalculateSprint(number)) + if number >= s.chainConfig.Bor.CalculateSprint(number) { + delete(snap.Recents, number-s.chainConfig.Bor.CalculateSprint(number)) } // Resolve the authorization key and check against signers - signer, err := ecrecover(header, s.sigcache, s.config) + signer, err := ecrecover(header, s.sigcache, s.chainConfig.Bor) if err != nil { return nil, err } @@ -145,12 +146,12 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) { snap.Recents[number] = signer // change validator set and change proposer - if number > 0 && (number+1)%s.config.CalculateSprint(number) == 0 { + if number > 0 && (number+1)%s.chainConfig.Bor.CalculateSprint(number) == 0 { if err := validateHeaderExtraField(header.Extra); err != nil { return nil, err } - validatorBytes := header.GetValidatorBytes(s.config) + validatorBytes := header.GetValidatorBytes(s.chainConfig) // get validators from headers and use that for new validator set newVals, _ := valset.ParseValidators(validatorBytes) diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index 2dfff35349..2074c9727b 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -288,6 +288,11 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat deps := GetDeps(blockTxDependency) + if !VerifyDeps(deps) || len(blockTxDependency) != len(block.Transactions()) { + blockTxDependency = nil + deps = make(map[int][]int) + } + if blockTxDependency != nil { metadata = true } @@ -308,57 +313,30 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat shouldDelayFeeCal = false } - if len(blockTxDependency) != len(block.Transactions()) { - task := &ExecutionTask{ - msg: *msg, - config: p.config, - gasLimit: block.GasLimit(), - blockNumber: blockNumber, - blockHash: blockHash, - tx: tx, - index: i, - cleanStateDB: cleansdb, - finalStateDB: statedb, - blockChain: p.bc, - header: header, - evmConfig: cfg, - shouldDelayFeeCal: &shouldDelayFeeCal, - sender: msg.From, - totalUsedGas: usedGas, - receipts: &receipts, - allLogs: &allLogs, - dependencies: deps[i], - coinbase: coinbase, - blockContext: blockContext, - } - - tasks = append(tasks, task) - } else { - task := &ExecutionTask{ - msg: *msg, - config: p.config, - gasLimit: block.GasLimit(), - blockNumber: blockNumber, - blockHash: blockHash, - tx: tx, - index: i, - cleanStateDB: cleansdb, - finalStateDB: statedb, - blockChain: p.bc, - header: header, - evmConfig: cfg, - shouldDelayFeeCal: &shouldDelayFeeCal, - sender: msg.From, - totalUsedGas: usedGas, - receipts: &receipts, - allLogs: &allLogs, - dependencies: nil, - coinbase: coinbase, - blockContext: blockContext, - } - - tasks = append(tasks, task) + task := &ExecutionTask{ + msg: *msg, + config: p.config, + gasLimit: block.GasLimit(), + blockNumber: blockNumber, + blockHash: blockHash, + tx: tx, + index: i, + cleanStateDB: cleansdb, + finalStateDB: statedb, + blockChain: p.bc, + header: header, + evmConfig: cfg, + shouldDelayFeeCal: &shouldDelayFeeCal, + sender: msg.From, + totalUsedGas: usedGas, + receipts: &receipts, + allLogs: &allLogs, + dependencies: deps[i], + coinbase: coinbase, + blockContext: blockContext, } + + tasks = append(tasks, task) } backupStateDB := statedb.Copy() @@ -427,3 +405,21 @@ func GetDeps(txDependency [][]uint64) map[int][]int { return deps } + +// returns true if dependencies are correct +func VerifyDeps(deps map[int][]int) bool { + // number of transactions in the block + n := len(deps) + + // Handle out-of-range and circular dependency problem + for i := 0; i <= n-1; i++ { + val := deps[i] + for _, depTx := range val { + if depTx >= n || depTx >= i { + return false + } + } + } + + return true +} diff --git a/core/parallel_state_processor_test.go b/core/parallel_state_processor_test.go new file mode 100644 index 0000000000..424ea4282a --- /dev/null +++ b/core/parallel_state_processor_test.go @@ -0,0 +1,30 @@ +package core + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMetadata(t *testing.T) { + t.Parallel() + + correctTxDependency := [][]uint64{{}, {0}, {}, {1}, {3}, {}, {0, 2}, {5}, {}, {8}} + wrongTxDependency := [][]uint64{{0}} + wrongTxDependencyCircular := [][]uint64{{}, {2}, {1}} + wrongTxDependencyOutOfRange := [][]uint64{{}, {}, {3}} + + var temp map[int][]int + + temp = GetDeps(correctTxDependency) + assert.Equal(t, true, VerifyDeps(temp)) + + temp = GetDeps(wrongTxDependency) + assert.Equal(t, false, VerifyDeps(temp)) + + temp = GetDeps(wrongTxDependencyCircular) + assert.Equal(t, false, VerifyDeps(temp)) + + temp = GetDeps(wrongTxDependencyOutOfRange) + assert.Equal(t, false, VerifyDeps(temp)) +} diff --git a/core/types/block.go b/core/types/block.go index 1ffaea554c..1cebb65b24 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -456,8 +456,8 @@ func (b *Block) GetTxDependency() [][]uint64 { return blockExtraData.TxDependency } -func (h *Header) GetValidatorBytes(config *params.BorConfig) []byte { - if !config.IsParallelUniverse(h.Number) { +func (h *Header) GetValidatorBytes(chainConfig *params.ChainConfig) []byte { + if !chainConfig.IsCancun(h.Number) { return h.Extra[ExtraVanityLength : len(h.Extra)-ExtraSealLength] } diff --git a/core/types/block_test.go b/core/types/block_test.go index 218205e564..a42d578f33 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -74,7 +74,6 @@ func TestBlockEncoding(t *testing.T) { } // This is a replica of `(h *Header) GetValidatorBytes` function -// This was needed because currently, `IsParallelUniverse` will always return false. func GetValidatorBytesTest(h *Header) []byte { if len(h.Extra) < ExtraVanityLength+ExtraSealLength { log.Error("length of extra less is than vanity and seal") diff --git a/internal/cli/server/chains/mainnet.go b/internal/cli/server/chains/mainnet.go index b9efd9a4e2..5548f8edba 100644 --- a/internal/cli/server/chains/mainnet.go +++ b/internal/cli/server/chains/mainnet.go @@ -29,10 +29,9 @@ var mainnetBor = &Chain{ LondonBlock: big.NewInt(23850000), ShanghaiBlock: big.NewInt(50523000), Bor: ¶ms.BorConfig{ - JaipurBlock: big.NewInt(23850000), - DelhiBlock: big.NewInt(38189056), - ParallelUniverseBlock: big.NewInt(0), - IndoreBlock: big.NewInt(44934656), + JaipurBlock: big.NewInt(23850000), + DelhiBlock: big.NewInt(38189056), + IndoreBlock: big.NewInt(44934656), StateSyncConfirmationDelay: map[string]uint64{ "44934656": 128, }, diff --git a/internal/cli/server/chains/mumbai.go b/internal/cli/server/chains/mumbai.go index 45f36fbe89..7fe25554c5 100644 --- a/internal/cli/server/chains/mumbai.go +++ b/internal/cli/server/chains/mumbai.go @@ -29,10 +29,9 @@ var mumbaiTestnet = &Chain{ LondonBlock: big.NewInt(22640000), ShanghaiBlock: big.NewInt(41874000), Bor: ¶ms.BorConfig{ - JaipurBlock: big.NewInt(22770000), - DelhiBlock: big.NewInt(29638656), - ParallelUniverseBlock: big.NewInt(0), - IndoreBlock: big.NewInt(37075456), + JaipurBlock: big.NewInt(22770000), + DelhiBlock: big.NewInt(29638656), + IndoreBlock: big.NewInt(37075456), StateSyncConfirmationDelay: map[string]uint64{ "37075456": 128, }, diff --git a/internal/cli/server/chains/test_files/chain_legacy_test.json b/internal/cli/server/chains/test_files/chain_legacy_test.json index a64fbf3e23..c3e9b3c7bf 100644 --- a/internal/cli/server/chains/test_files/chain_legacy_test.json +++ b/internal/cli/server/chains/test_files/chain_legacy_test.json @@ -57,7 +57,6 @@ }, "jaipurBlock": 22770000, "delhiBlock": 29638656, - "parallelUniverseBlock": 0, "indoreBlock": 37075456, "stateSyncConfirmationDelay": { "37075456": 128 diff --git a/internal/cli/server/chains/test_files/chain_test.json b/internal/cli/server/chains/test_files/chain_test.json index ba207bf770..8555833321 100644 --- a/internal/cli/server/chains/test_files/chain_test.json +++ b/internal/cli/server/chains/test_files/chain_test.json @@ -59,7 +59,6 @@ }, "jaipurBlock":22770000, "delhiBlock": 29638656, - "parallelUniverseBlock": 0, "indoreBlock": 37075456, "stateSyncConfirmationDelay": { "37075456": 128 diff --git a/miner/worker.go b/miner/worker.go index 4a92776f56..3573eccfee 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -109,17 +109,22 @@ type environment struct { header *types.Header txs []*types.Transaction receipts []*types.Receipt + + depsMVFullWriteList [][]blockstm.WriteDescriptor + mvReadMapList []map[blockstm.Key]blockstm.ReadDescriptor } // copy creates a deep copy of environment. func (env *environment) copy() *environment { cpy := &environment{ - signer: env.signer, - state: env.state.Copy(), - tcount: env.tcount, - coinbase: env.coinbase, - header: types.CopyHeader(env.header), - receipts: copyReceipts(env.receipts), + signer: env.signer, + state: env.state.Copy(), + tcount: env.tcount, + coinbase: env.coinbase, + header: types.CopyHeader(env.header), + receipts: copyReceipts(env.receipts), + depsMVFullWriteList: env.depsMVFullWriteList, + mvReadMapList: env.mvReadMapList, } if env.gasPool != nil { @@ -854,6 +859,9 @@ func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase co // Keep track of transactions which return errors so they can be removed env.tcount = 0 + env.depsMVFullWriteList = [][]blockstm.WriteDescriptor{} + env.mvReadMapList = []map[blockstm.Key]blockstm.ReadDescriptor{} + return env, nil } @@ -903,36 +911,20 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn var coalescedLogs []*types.Log - var depsMVReadList [][]blockstm.ReadDescriptor - - var depsMVFullWriteList [][]blockstm.WriteDescriptor - - var mvReadMapList []map[blockstm.Key]blockstm.ReadDescriptor - var deps map[int]map[int]bool chDeps := make(chan blockstm.TxDep) - var count int - var depsWg sync.WaitGroup - EnableMVHashMap := w.chainConfig.Bor.IsParallelUniverse(env.header.Number) + EnableMVHashMap := w.chainConfig.IsCancun(env.header.Number) // create and add empty mvHashMap in statedb if EnableMVHashMap { - depsMVReadList = [][]blockstm.ReadDescriptor{} - - depsMVFullWriteList = [][]blockstm.WriteDescriptor{} - - mvReadMapList = []map[blockstm.Key]blockstm.ReadDescriptor{} - deps = map[int]map[int]bool{} chDeps = make(chan blockstm.TxDep) - count = 0 - depsWg.Add(1) go func(chDeps chan blockstm.TxDep) { @@ -1064,18 +1056,20 @@ mainloop: env.tcount++ if EnableMVHashMap { - depsMVReadList = append(depsMVReadList, env.state.MVReadList()) - depsMVFullWriteList = append(depsMVFullWriteList, env.state.MVFullWriteList()) - mvReadMapList = append(mvReadMapList, env.state.MVReadMap()) + env.depsMVFullWriteList = append(env.depsMVFullWriteList, env.state.MVFullWriteList()) + env.mvReadMapList = append(env.mvReadMapList, env.state.MVReadMap()) + + if env.tcount > len(env.depsMVFullWriteList) { + log.Warn("blockstm - env.tcount > len(env.depsMVFullWriteList)", "env.tcount", env.tcount, "len(depsMVFullWriteList)", len(env.depsMVFullWriteList)) + } temp := blockstm.TxDep{ Index: env.tcount - 1, - ReadList: depsMVReadList[count], - FullWriteList: depsMVFullWriteList, + ReadList: env.state.MVReadList(), + FullWriteList: env.depsMVFullWriteList, } chDeps <- temp - count++ } txs.Shift() @@ -1107,8 +1101,8 @@ mainloop: tempVanity := env.header.Extra[:types.ExtraVanityLength] tempSeal := env.header.Extra[len(env.header.Extra)-types.ExtraSealLength:] - if len(mvReadMapList) > 0 { - tempDeps := make([][]uint64, len(mvReadMapList)) + if len(env.mvReadMapList) > 0 { + tempDeps := make([][]uint64, len(env.mvReadMapList)) for j := range deps[0] { tempDeps[0] = append(tempDeps[0], uint64(j)) @@ -1116,8 +1110,8 @@ mainloop: delayFlag := true - for i := 1; i <= len(mvReadMapList)-1; i++ { - reads := mvReadMapList[i-1] + for i := 1; i <= len(env.mvReadMapList)-1; i++ { + reads := env.mvReadMapList[i-1] _, ok1 := reads[blockstm.NewSubpathKey(env.coinbase, state.BalancePath)] _, ok2 := reads[blockstm.NewSubpathKey(common.HexToAddress(w.chainConfig.Bor.CalculateBurntContract(env.header.Number.Uint64())), state.BalancePath)] diff --git a/miner/worker_test.go b/miner/worker_test.go index 88f7924b00..57bb26511c 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -909,7 +909,7 @@ func BenchmarkBorMining(b *testing.B) { } // uses core.NewParallelBlockChain to use the dependencies present in the block header -// params.BorUnittestChainConfig contains the ParallelUniverseBlock ad big.NewInt(5), so the first 4 blocks will not have metadata. +// params.BorUnittestChainConfig contains the NapoliBlock as big.NewInt(5), so the first 4 blocks will not have metadata. // nolint: gocognit func BenchmarkBorMiningBlockSTMMetadata(b *testing.B) { chainConfig := params.BorUnittestChainConfig diff --git a/params/config.go b/params/config.go index ea00979850..e724a02747 100644 --- a/params/config.go +++ b/params/config.go @@ -159,7 +159,6 @@ var ( BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), Bor: &BorConfig{ - ParallelUniverseBlock: big.NewInt(5), Period: map[string]uint64{ "0": 1, }, @@ -198,10 +197,9 @@ var ( LondonBlock: big.NewInt(22640000), ShanghaiBlock: big.NewInt(41874000), Bor: &BorConfig{ - JaipurBlock: big.NewInt(22770000), - DelhiBlock: big.NewInt(29638656), - ParallelUniverseBlock: big.NewInt(0), - IndoreBlock: big.NewInt(37075456), + JaipurBlock: big.NewInt(22770000), + DelhiBlock: big.NewInt(29638656), + IndoreBlock: big.NewInt(37075456), StateSyncConfirmationDelay: map[string]uint64{ "37075456": 128, }, @@ -264,10 +262,9 @@ var ( LondonBlock: big.NewInt(23850000), ShanghaiBlock: big.NewInt(50523000), Bor: &BorConfig{ - JaipurBlock: big.NewInt(23850000), - DelhiBlock: big.NewInt(38189056), - ParallelUniverseBlock: big.NewInt(0), - IndoreBlock: big.NewInt(44934656), + JaipurBlock: big.NewInt(23850000), + DelhiBlock: big.NewInt(38189056), + IndoreBlock: big.NewInt(44934656), StateSyncConfirmationDelay: map[string]uint64{ "44934656": 128, }, @@ -567,7 +564,6 @@ type BorConfig struct { BurntContract map[string]string `json:"burntContract"` // governance contract where the token will be sent to and burnt in london fork JaipurBlock *big.Int `json:"jaipurBlock"` // Jaipur switch block (nil = no fork, 0 = already on jaipur) DelhiBlock *big.Int `json:"delhiBlock"` // Delhi switch block (nil = no fork, 0 = already on delhi) - ParallelUniverseBlock *big.Int `json:"parallelUniverseBlock"` // TODO: update all occurrence, change name and finalize number (hardfork for block-stm related changes) IndoreBlock *big.Int `json:"indoreBlock"` // Indore switch block (nil = no fork, 0 = already on indore) StateSyncConfirmationDelay map[string]uint64 `json:"stateSyncConfirmationDelay"` // StateSync Confirmation Delay, in seconds, to calculate `to` } @@ -609,16 +605,16 @@ func (c *BorConfig) CalculateStateSyncDelay(number uint64) uint64 { return borKeyValueConfigHelper(c.StateSyncConfirmationDelay, number) } -// TODO: modify this function once the block number is finalized -func (c *BorConfig) IsParallelUniverse(number *big.Int) bool { - if c.ParallelUniverseBlock != nil { - if c.ParallelUniverseBlock.Cmp(big.NewInt(0)) == 0 { - return false - } - } +// // TODO: modify this function once the block number is finalized +// func (c *BorConfig) IsNapoli(number *big.Int) bool { +// if c.NapoliBlock != nil { +// if c.NapoliBlock.Cmp(big.NewInt(0)) == 0 { +// return false +// } +// } - return isBlockForked(c.ParallelUniverseBlock, number) -} +// return isBlockForked(c.NapoliBlock, number) +// } func (c *BorConfig) IsSprintStart(number uint64) bool { return number%c.CalculateSprint(number) == 0 From 3a9d1539bb32ce7405508ffad77013df6f391111 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Mon, 29 Jan 2024 19:55:25 +0530 Subject: [PATCH 41/49] fix: bootnode --- cmd/bootnode/main.go | 12 +++++++++++- internal/cli/bootnode.go | 27 ++++++++++----------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index 491a35fb6d..c90e23d0d9 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -15,7 +15,8 @@ // along with go-ethereum. If not, see . // bootnode runs a bootstrap node for the Ethereum Discovery Protocol. -package main +// Keep package as bootnode during upstram merge. +package bootnode import ( "crypto/ecdsa" @@ -213,3 +214,12 @@ func doPortMapping(natm nat.Interface, ln *enode.LocalNode, addr *net.UDPAddr) * return extaddr } + +// Implemented separate function so that there are minimal conflicts during upstream merge +func PrintNotice(nodeKey *ecdsa.PublicKey, addr net.UDPAddr) { + printNotice(nodeKey, addr) +} + +func DoPortMapping(natm nat.Interface, ln *enode.LocalNode, addr *net.UDPAddr) *net.UDPAddr { + return doPortMapping(natm, ln, addr) +} diff --git a/internal/cli/bootnode.go b/internal/cli/bootnode.go index 756956daa9..979d69ec23 100644 --- a/internal/cli/bootnode.go +++ b/internal/cli/bootnode.go @@ -13,6 +13,7 @@ import ( "syscall" "time" + "github.com/ethereum/go-ethereum/cmd/bootnode" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/internal/cli/flagset" @@ -213,33 +214,25 @@ func (b *BootnodeCommand) Run(args []string) int { } conn, err := net.ListenUDP("udp", addr) - if err != nil { b.UI.Error(fmt.Sprintf("failed to listen udp addr '%s': %v", b.listenAddr, err)) return 1 } + defer conn.Close() - realaddr := conn.LocalAddr().(*net.UDPAddr) - if natm != nil { - if !realaddr.IP.IsLoopback() { - go nat.Map(natm, nil, "udp", realaddr.Port, realaddr.Port, "ethereum discovery") - } + db, _ := enode.OpenDB("") + ln := enode.NewLocalNode(db, nodeKey) - if ext, err := natm.ExternalIP(); err == nil { - // nolint: govet - realaddr = &net.UDPAddr{IP: ext, Port: realaddr.Port} + listenerAddr := conn.LocalAddr().(*net.UDPAddr) + if natm != nil { + natAddr := bootnode.DoPortMapping(natm, ln, listenerAddr) + if natAddr != nil { + listenerAddr = natAddr } } - n := enode.NewV4(&nodeKey.PublicKey, addr.IP, addr.Port, addr.Port) - b.UI.Info(n.String()) - - if b.dryRun { - return 0 - } + bootnode.PrintNotice(&nodeKey.PublicKey, *listenerAddr) - db, _ := enode.OpenDB("") - ln := enode.NewLocalNode(db, nodeKey) cfg := discover.Config{ PrivateKey: nodeKey, Log: log.Root(), From 0a3d419570ab8b1ff89a7f22a24117ca763f6e28 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Mon, 29 Jan 2024 21:23:56 +0530 Subject: [PATCH 42/49] fix: lint --- cmd/bootnode/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index c90e23d0d9..4f744e102b 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -35,6 +35,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/netutil" ) +// nolint func main() { var ( listenAddr = flag.String("addr", ":30301", "listen address") @@ -215,7 +216,7 @@ func doPortMapping(natm nat.Interface, ln *enode.LocalNode, addr *net.UDPAddr) * return extaddr } -// Implemented separate function so that there are minimal conflicts during upstream merge +// Implemented separate functions so that there are minimal conflicts during upstream merge func PrintNotice(nodeKey *ecdsa.PublicKey, addr net.UDPAddr) { printNotice(nodeKey, addr) } From 5c8625c999eea10643fc0218262217aa919ec177 Mon Sep 17 00:00:00 2001 From: Vaibhav Jindal Date: Thu, 18 Jan 2024 04:00:32 +0530 Subject: [PATCH 43/49] Chg: Changed the maximum automatic rewind length from 256 to 126 --- eth/bor_checkpoint_verifier.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eth/bor_checkpoint_verifier.go b/eth/bor_checkpoint_verifier.go index f8ac341e74..a0bdfeac8e 100644 --- a/eth/bor_checkpoint_verifier.go +++ b/eth/bor_checkpoint_verifier.go @@ -37,6 +37,8 @@ var ( rewindLengthMeter = metrics.NewRegisteredMeter("chain/autorewind/length", nil) ) +const maxRewindLen uint64 = 126 + type borVerifier struct { verify func(ctx context.Context, eth *Ethereum, handler *ethHandler, start uint64, end uint64, hash string, isCheckpoint bool) (string, error) } @@ -117,8 +119,8 @@ func borVerify(ctx context.Context, eth *Ethereum, handler *ethHandler, start ui } } - if head-rewindTo > 255 { - rewindTo = head - 255 + if head-rewindTo > maxRewindLen { + rewindTo = head - maxRewindLen } if isCheckpoint { From 2f02c00e1fe390684fff84c3e9148cd1c7978641 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 30 Jan 2024 13:16:36 +0530 Subject: [PATCH 44/49] update version --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- .../templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 8 ++++---- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 94eeea3661..053cc684d9 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.3 +Version: 1.2.4-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 809d705aa6..25d6451a7f 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.3 +Version: 1.2.4-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 22470ccd49..40877bbd48 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.3 +Version: 1.2.4-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 4a52b2e063..e7bee6ac52 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.3 +Version: 1.2.4-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 00b517c3b0..66adba3502 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.3 +Version: 1.2.4-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 725a4ec394..596910a8a9 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.3 +Version: 1.2.4-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index b44ab8079c..c2e3e99b38 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 2 // Minor version component of the current release - VersionPatch = 3 // Patch version component of the current release - VersionMeta = "" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 2 // Minor version component of the current release + VersionPatch = 4 // Patch version component of the current release + VersionMeta = "beta" // Version metadata to append to the version string ) var GitCommit string From 5d34ab40d893299a9bb16a42c902006e503b7188 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 30 Jan 2024 13:31:36 +0530 Subject: [PATCH 45/49] add cancun Block for mumbai --- builder/files/genesis-testnet-v4.json | 1 + internal/cli/server/chains/mumbai.go | 1 + internal/cli/server/chains/test_files/chain_legacy_test.json | 1 + internal/cli/server/chains/test_files/chain_test.json | 1 + params/config.go | 1 + 5 files changed, 5 insertions(+) diff --git a/builder/files/genesis-testnet-v4.json b/builder/files/genesis-testnet-v4.json index afad138492..f3881b0166 100644 --- a/builder/files/genesis-testnet-v4.json +++ b/builder/files/genesis-testnet-v4.json @@ -14,6 +14,7 @@ "berlinBlock": 13996000, "londonBlock": 22640000, "shanghaiBlock": 41874000, + "cancunBlock": 45648608, "bor": { "jaipurBlock": 22770000, "delhiBlock": 29638656, diff --git a/internal/cli/server/chains/mumbai.go b/internal/cli/server/chains/mumbai.go index 7fe25554c5..56fe8a1d47 100644 --- a/internal/cli/server/chains/mumbai.go +++ b/internal/cli/server/chains/mumbai.go @@ -28,6 +28,7 @@ var mumbaiTestnet = &Chain{ BerlinBlock: big.NewInt(13996000), LondonBlock: big.NewInt(22640000), ShanghaiBlock: big.NewInt(41874000), + CancunBlock: big.NewInt(45648608), Bor: ¶ms.BorConfig{ JaipurBlock: big.NewInt(22770000), DelhiBlock: big.NewInt(29638656), diff --git a/internal/cli/server/chains/test_files/chain_legacy_test.json b/internal/cli/server/chains/test_files/chain_legacy_test.json index c3e9b3c7bf..cc81db1608 100644 --- a/internal/cli/server/chains/test_files/chain_legacy_test.json +++ b/internal/cli/server/chains/test_files/chain_legacy_test.json @@ -15,6 +15,7 @@ "berlinBlock": 13996000, "londonBlock": 13996000, "shanghaiBlock": 41874000, + "cancunBlock": 45648608, "bor": { "period": { "0": 2, diff --git a/internal/cli/server/chains/test_files/chain_test.json b/internal/cli/server/chains/test_files/chain_test.json index 8555833321..3f826d285f 100644 --- a/internal/cli/server/chains/test_files/chain_test.json +++ b/internal/cli/server/chains/test_files/chain_test.json @@ -17,6 +17,7 @@ "berlinBlock":13996000, "londonBlock":13996000, "shanghaiBlock": 41874000, + "cancunBlock": 45648608, "bor":{ "period":{ "0":2, diff --git a/params/config.go b/params/config.go index e724a02747..a82800206b 100644 --- a/params/config.go +++ b/params/config.go @@ -196,6 +196,7 @@ var ( BerlinBlock: big.NewInt(13996000), LondonBlock: big.NewInt(22640000), ShanghaiBlock: big.NewInt(41874000), + CancunBlock: big.NewInt(45648608), Bor: &BorConfig{ JaipurBlock: big.NewInt(22770000), DelhiBlock: big.NewInt(29638656), From f5a51afa04c4aacc7a4e4594eb9a1d1de9884866 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Fri, 9 Feb 2024 22:29:06 +0530 Subject: [PATCH 46/49] updated version to 1.2.5-beta --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- packaging/templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 053cc684d9..0dfbbab07f 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.4-beta +Version: 1.2.5-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 25d6451a7f..e7114840d5 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.4-beta +Version: 1.2.5-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 40877bbd48..5264be314c 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.4-beta +Version: 1.2.5-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index e7bee6ac52..76f68f8708 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.4-beta +Version: 1.2.5-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index 66adba3502..b1816d185f 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.4-beta +Version: 1.2.5-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 596910a8a9..b8e1430029 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.4-beta +Version: 1.2.5-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index c2e3e99b38..c08eb9c4b6 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 2 // Minor version component of the current release - VersionPatch = 4 // Patch version component of the current release + VersionPatch = 5 // Patch version component of the current release VersionMeta = "beta" // Version metadata to append to the version string ) From d193b95e14e3bfc03645b8eedc96f26cf8ee3af6 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Sat, 10 Feb 2024 00:12:21 +0530 Subject: [PATCH 47/49] hot fix in miner related to metadata calculation (#1159) --- miner/worker.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 3573eccfee..0e1dd83691 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -920,7 +920,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn EnableMVHashMap := w.chainConfig.IsCancun(env.header.Number) // create and add empty mvHashMap in statedb - if EnableMVHashMap { + if EnableMVHashMap && w.IsRunning() { deps = map[int]map[int]bool{} chDeps = make(chan blockstm.TxDep) @@ -956,7 +956,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn mainloop: for { if interruptCtx != nil { - if EnableMVHashMap { + if EnableMVHashMap && w.IsRunning() { env.state.AddEmptyMVHashMap() } @@ -1055,7 +1055,7 @@ mainloop: coalescedLogs = append(coalescedLogs, logs...) env.tcount++ - if EnableMVHashMap { + if EnableMVHashMap && w.IsRunning() { env.depsMVFullWriteList = append(env.depsMVFullWriteList, env.state.MVFullWriteList()) env.mvReadMapList = append(env.mvReadMapList, env.state.MVReadMap()) @@ -1085,7 +1085,7 @@ mainloop: txs.Pop() } - if EnableMVHashMap { + if EnableMVHashMap && w.IsRunning() { env.state.ClearReadMap() env.state.ClearWriteMap() } From 9f9e1be47e49a2854343927a3b5ec45d01394e12 Mon Sep 17 00:00:00 2001 From: lightclient <14004106+lightclient@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:22:15 -0600 Subject: [PATCH 48/49] core/types: fix unmarshalling of BlobTx values (#27939) FromBig returns true *when overflow occurs* --- core/types/transaction_marshalling.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index 1378cb4014..e5d71a85d6 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -373,20 +373,20 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error { itx.BlobHashes = dec.BlobVersionedHashes // signature R - var ok bool + var overflow bool if dec.R == nil { return errors.New("missing required field 'r' in transaction") } - itx.R, ok = uint256.FromBig((*big.Int)(dec.R)) - if !ok { + itx.R, overflow = uint256.FromBig((*big.Int)(dec.R)) + if overflow { return errors.New("'r' value overflows uint256") } // signature S if dec.S == nil { return errors.New("missing required field 's' in transaction") } - itx.S, ok = uint256.FromBig((*big.Int)(dec.S)) - if !ok { + itx.S, overflow = uint256.FromBig((*big.Int)(dec.S)) + if overflow { return errors.New("'s' value overflows uint256") } // signature V @@ -394,8 +394,8 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error { if err != nil { return err } - itx.V, ok = uint256.FromBig(vbig) - if !ok { + itx.V, overflow = uint256.FromBig(vbig) + if overflow { return errors.New("'v' value overflows uint256") } if itx.V.Sign() != 0 || itx.R.Sign() != 0 || itx.S.Sign() != 0 { From 2dd99739b55d611decebd6316b27194b64121554 Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 14 Feb 2024 13:15:05 +0530 Subject: [PATCH 49/49] bump version to v1.2.6-beta --- packaging/templates/package_scripts/control | 2 +- packaging/templates/package_scripts/control.arm64 | 2 +- packaging/templates/package_scripts/control.profile.amd64 | 2 +- packaging/templates/package_scripts/control.profile.arm64 | 2 +- packaging/templates/package_scripts/control.validator | 2 +- packaging/templates/package_scripts/control.validator.arm64 | 2 +- params/version.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 0dfbbab07f..2c226f14f6 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.5-beta +Version: 1.2.6-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index e7114840d5..ebbac43cb0 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.2.5-beta +Version: 1.2.6-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 5264be314c..e6eb93591b 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.5-beta +Version: 1.2.6-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 76f68f8708..0c91282243 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.5-beta +Version: 1.2.6-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index b1816d185f..178e56d491 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.5-beta +Version: 1.2.6-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index b8e1430029..031421d15b 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.2.5-beta +Version: 1.2.6-beta Section: develop Priority: standard Maintainer: Polygon diff --git a/params/version.go b/params/version.go index c08eb9c4b6..0f8ea8e9f5 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 2 // Minor version component of the current release - VersionPatch = 5 // Patch version component of the current release + VersionPatch = 6 // Patch version component of the current release VersionMeta = "beta" // Version metadata to append to the version string )