Skip to content

Commit d772bc2

Browse files
Darioush Jalaliceyonur
andauthored
Reduce diff with subnet-evm (#475)
Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>
1 parent 1c74731 commit d772bc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+236
-203
lines changed

SECURITY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Security Policy
22

3-
Avalanche takes the security of the platform and of its users very seriously. We and our community recognize the critical role of external security researchers and developers and welcome
3+
Avalanche takes the security of the platform and of its users very seriously. We and our community recognize the critical role of external security researchers and developers and welcome
44
responsible disclosures. Valid reports will be eligible for a reward (terms and conditions apply).
55

66
## Reporting a Vulnerability
77

88
**Please do not file a public ticket** mentioning the vulnerability. To disclose a vulnerability submit it through our [Bug Bounty Program](https://hackenproof.com/avalanche).
99

10-
Vulnerabilities must be disclosed to us privately with reasonable time to respond, and avoid compromise of other users and accounts, or loss of funds that are not your own. We do not reward spam or
11-
social engineering vulnerabilities.
10+
Vulnerabilities must be disclosed to us privately with reasonable time to respond, and avoid compromise of other users and accounts, or loss of funds that are not your own. We do not reward spam or
11+
social engineering vulnerabilities.
1212

1313
Do not test for or validate any security issues in the live Avalanche networks (Mainnet and Fuji testnet), confirm all exploits in a local private testnet.
1414

accounts/abi/bind/bind_test.go

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,7 @@ var bindTests = []struct {
17581758
key, _ := crypto.GenerateKey()
17591759
addr := crypto.PubkeyToAddress(key.PublicKey)
17601760
1761+
17611762
sim := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000000000000)}}, 1000000)
17621763
defer sim.Close()
17631764
@@ -1879,7 +1880,7 @@ var bindTests = []struct {
18791880
if count != 1 {
18801881
t.Fatal("Unexpected contract event number")
18811882
}
1882-
`,
1883+
`,
18831884
nil,
18841885
nil,
18851886
nil,
@@ -1889,51 +1890,51 @@ var bindTests = []struct {
18891890
{
18901891
`NewErrors`,
18911892
`
1892-
pragma solidity >0.8.4;
1893-
1894-
contract NewErrors {
1895-
error MyError(uint256);
1896-
error MyError1(uint256);
1897-
error MyError2(uint256, uint256);
1898-
error MyError3(uint256 a, uint256 b, uint256 c);
1899-
function Error() public pure {
1900-
revert MyError3(1,2,3);
1901-
}
1893+
pragma solidity >0.8.4;
1894+
1895+
contract NewErrors {
1896+
error MyError(uint256);
1897+
error MyError1(uint256);
1898+
error MyError2(uint256, uint256);
1899+
error MyError3(uint256 a, uint256 b, uint256 c);
1900+
function Error() public pure {
1901+
revert MyError3(1,2,3);
19021902
}
1903-
`,
1903+
}
1904+
`,
19041905
[]string{"0x6080604052348015600f57600080fd5b5060998061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063726c638214602d575b600080fd5b60336035565b005b60405163024876cd60e61b815260016004820152600260248201526003604482015260640160405180910390fdfea264697066735822122093f786a1bc60216540cd999fbb4a6109e0fef20abcff6e9107fb2817ca968f3c64736f6c63430008070033"},
19051906
[]string{`[{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"MyError","type":"error"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"MyError1","type":"error"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"MyError2","type":"error"},{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"},{"internalType":"uint256","name":"c","type":"uint256"}],"name":"MyError3","type":"error"},{"inputs":[],"name":"Error","outputs":[],"stateMutability":"pure","type":"function"}]`},
19061907
`
1907-
"math/big"
1908-
1909-
"github.com/ava-labs/coreth/accounts/abi/bind"
1910-
"github.com/ava-labs/coreth/accounts/abi/bind/backends"
1911-
"github.com/ava-labs/coreth/core"
1912-
"github.com/ethereum/go-ethereum/crypto"
1913-
`,
1914-
`
1915-
var (
1916-
key, _ = crypto.GenerateKey()
1917-
user, _ = bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
1918-
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, 10000000)
1919-
)
1920-
defer sim.Close()
1921-
1922-
_, tx, contract, err := DeployNewErrors(user, sim)
1923-
if err != nil {
1924-
t.Fatal(err)
1925-
}
1926-
sim.Commit(true)
1927-
_, err = bind.WaitDeployed(nil, sim, tx)
1928-
if err != nil {
1929-
t.Error(err)
1930-
}
1931-
if err := contract.Error(new(bind.CallOpts)); err == nil {
1932-
t.Fatalf("expected contract to throw error")
1933-
}
1934-
// TODO (MariusVanDerWijden unpack error using abigen
1935-
// once that is implemented
1936-
`,
1908+
"math/big"
1909+
1910+
"github.com/ava-labs/coreth/accounts/abi/bind"
1911+
"github.com/ava-labs/coreth/accounts/abi/bind/backends"
1912+
"github.com/ava-labs/coreth/core"
1913+
"github.com/ethereum/go-ethereum/crypto"
1914+
`,
1915+
`
1916+
var (
1917+
key, _ = crypto.GenerateKey()
1918+
user, _ = bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
1919+
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, 10000000)
1920+
)
1921+
defer sim.Close()
1922+
1923+
_, tx, contract, err := DeployNewErrors(user, sim)
1924+
if err != nil {
1925+
t.Fatal(err)
1926+
}
1927+
sim.Commit(true)
1928+
_, err = bind.WaitDeployed(nil, sim, tx)
1929+
if err != nil {
1930+
t.Error(err)
1931+
}
1932+
if err := contract.Error(new(bind.CallOpts)); err == nil {
1933+
t.Fatalf("expected contract to throw error")
1934+
}
1935+
// TODO (MariusVanDerWijden unpack error using abigen
1936+
// once that is implemented
1937+
`,
19371938
nil,
19381939
nil,
19391940
nil,
@@ -2172,7 +2173,7 @@ func golangBindings(t *testing.T, overload bool) {
21722173
if out, err := replacer.CombinedOutput(); err != nil {
21732174
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
21742175
}
2175-
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.19")
2176+
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.20")
21762177
tidier.Dir = pkg
21772178
if out, err := tidier.CombinedOutput(); err != nil {
21782179
t.Fatalf("failed to tidy Go module file: %v\n%s", err, out)

accounts/keystore/account_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var (
6060
}
6161
)
6262

63-
// waitWatcherStarts waits up to 1s for the keystore watcher to start.
63+
// waitWatcherStart waits up to 1s for the keystore watcher to start.
6464
func waitWatcherStart(ks *KeyStore) bool {
6565
// On systems where file watch is not supported, just return "ok".
6666
if !ks.cache.watcher.enabled() {

consensus/dummy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The dummy consensus engine is responsible for performing verification on the hea
1414

1515
As of Apricot Phase 3, the C-Chain includes a dynamic fee algorithm based off of (EIP-1559)[https://eips.ethereum.org/EIPS/eip-1559]. This introduces a field to the block type called `BaseFee`. The Base Fee sets a minimum gas price for any transaction to be included in the block. For example, a transaction with a gas price of 49 gwei, will be invalid to include in a block with a base fee of 50 gwei.
1616

17-
The dynamic fee algorithm aims to adjust the base fee to handle network congestion. Coreth sets a target utilization on the network, and the dynamic fee algorithm adjusts the base fee accordingly. If the network operates above the target utilization, the dynamic fee algorithm will increase the base fee to make utilizing he network more expensive and bring overall utilization down. If the network operates below the target utilization, the dynamic fee algorithm will decrease the base fee to make it cheaper to use the network.
17+
The dynamic fee algorithm aims to adjust the base fee to handle network congestion. Coreth sets a target utilization on the network, and the dynamic fee algorithm adjusts the base fee accordingly. If the network operates above the target utilization, the dynamic fee algorithm will increase the base fee to make utilizing the network more expensive and bring overall utilization down. If the network operates below the target utilization, the dynamic fee algorithm will decrease the base fee to make it cheaper to use the network.
1818

1919
- EIP-1559 is intended for Ethereum where a block is produced roughly every 10s
2020
- C-Chain typically produces blocks every 2 seconds, but the dynamic fee algorithm needs to handle the case that the network quiesces and there are no blocks for a long period of time

consensus/dummy/consensus.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,17 @@ func (self *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header
206206
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
207207
}
208208
}
209-
210209
// Ensure gas-related header fields are correct
211210
if err := self.verifyHeaderGasFields(config, header, parent); err != nil {
212211
return err
213212
}
213+
214214
// Verify the header's timestamp
215215
if header.Time > uint64(time.Now().Add(allowedFutureBlockTime).Unix()) {
216216
return consensus.ErrFutureBlock
217217
}
218-
// if header.Time <= parent.Time {
218+
// Verify the header's timestamp is not earlier than parent's
219+
// it does include equality(==), so multiple blocks per second is ok
219220
if header.Time < parent.Time {
220221
return errInvalidBlockTime
221222
}
@@ -315,6 +316,7 @@ func (self *DummyEngine) verifyBlockFee(
315316
// Minimum Fee = 10 gwei * 1M gas (minimum fee that would have been accepted for this transaction)
316317
// Fee Premium = 90 gwei
317318
// Total Overpaid = 90 gwei * 1M gas
319+
318320
blockFeeContribution.Mul(txFeePremium, gasUsed.SetUint64(receipt.GasUsed))
319321
totalBlockFee.Add(totalBlockFee, blockFeeContribution)
320322
}

consensus/dummy/dynamic_fees_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ type test struct {
107107

108108
func TestDynamicFees(t *testing.T) {
109109
spacedTimestamps := []uint64{1, 1, 2, 5, 15, 120}
110+
110111
var tests []test = []test{
111112
// Test minimal gas usage
112113
{
@@ -276,7 +277,7 @@ func TestSelectBigWithinBounds(t *testing.T) {
276277
lower, value, upper, expected *big.Int
277278
}
278279

279-
var tests = map[string]test{
280+
tests := map[string]test{
280281
"value within bounds": {
281282
lower: big.NewInt(0),
282283
value: big.NewInt(5),

core/bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
8888
return func(i int, gen *BlockGen) {
8989
toaddr := common.Address{}
9090
data := make([]byte, nbytes)
91-
gas, _ := IntrinsicGas(data, nil, false, params.Rules{})
91+
gas, _ := IntrinsicGas(data, nil, false, params.Rules{}) // Disable Istanbul and EIP-2028 for this test
9292
signer := types.MakeSigner(gen.config, big.NewInt(int64(i)), gen.header.Time)
9393
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, big.NewInt(225000000000), data), signer, benchRootKey)
9494
gen.AddTx(tx)

core/evm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
5454
if !ok {
5555
return newEVMBlockContext(header, chain, author, nil)
5656
}
57-
// Prior to the Durango, the VM enforces the extra data is smaller than or
58-
// equal to this size. After the Durango, the VM pre-verifies the extra
57+
// Prior to Durango, the VM enforces the extra data is smaller than or
58+
// equal to this size. After Durango, the VM pre-verifies the extra
5959
// data past the dynamic fee rollup window is valid.
6060
predicateResults, err := predicate.ParseResults(predicateBytes)
6161
if err != nil {

core/genesis.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func (e *GenesisMismatchError) Error() string {
157157
// +------------------------------------------
158158
// db has no genesis | main-net default | genesis
159159
// db has genesis | from DB | genesis (if compatible)
160+
161+
// The argument [genesis] must be specified and must contain a valid chain config.
162+
// If the genesis block has already been set up, then we verify the hash matches the genesis passed in
163+
// and that the chain config contained in genesis is backwards compatible with what is stored in the database.
160164
//
161165
// The stored chain configuration will be updated if it is compatible (i.e. does not
162166
// specify a fork block below the local head block). In case of a conflict, the

core/genesis_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ func TestSetupGenesis(t *testing.T) {
175175
// regression test for precompile activation after header block
176176
func TestNetworkUpgradeBetweenHeadAndAcceptedBlock(t *testing.T) {
177177
db := rawdb.NewMemoryDatabase()
178-
179178
customg := Genesis{
180179
Config: params.TestApricotPhase1Config,
181180
Alloc: GenesisAlloc{

0 commit comments

Comments
 (0)