Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 96545dc

Browse files
Darioush JalaliARR4N
authored andcommitted
Merge branch 'master' into libevm (#812)
2 parents a295e40 + 2e4e6bd commit 96545dc

File tree

167 files changed

+4445
-7310
lines changed

Some content is hidden

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

167 files changed

+4445
-7310
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Coreth and the C-Chain
22

3-
[Avalanche](https://docs.avax.network/intro) is a network composed of multiple blockchains.
3+
[Avalanche](https://www.avax.network/) is a network composed of multiple blockchains.
44
Each blockchain is an instance of a Virtual Machine (VM), much like an object in an object-oriented language is an instance of a class.
55
That is, the VM defines the behavior of the blockchain.
66
Coreth (from core Ethereum) is the [Virtual Machine (VM)](https://docs.avax.network/learn/virtual-machines) that defines the Contract Chain (C-Chain).
@@ -39,7 +39,7 @@ Full documentation for the C-Chain's API can be found [here.](https://docs.avax.
3939

4040
## Compatibility
4141

42-
The C-Chain is compatible with almost all Ethereum tooling, including [Core,](https://docs.avax.network/build/dapp/launch-dapp#through-core) [Metamask,](https://docs.avax.network/build/dapp/launch-dapp#through-metamask) [Remix](https://docs.avax.network/build/tutorials/smart-contracts/deploy-a-smart-contract-on-avalanche-using-remix-and-metamask) and [Truffle.](https://docs.avax.network/build/tutorials/smart-contracts/using-truffle-with-the-avalanche-c-chain)
42+
The C-Chain is compatible with almost all Ethereum tooling, including [Core,](https://docs.avax.network/build/dapp/launch-dapp#through-core) [Metamask,](https://docs.avax.network/build/dapp/launch-dapp#through-metamask) [Remix](https://docs.avax.network/dapps/smart-contract-dev/deploy-with-remix-ide) and [Truffle.](https://docs.avax.network/build/tutorials/smart-contracts/using-truffle-with-the-avalanche-c-chain)
4343

4444
## Differences Between Avalanche C-Chain and Ethereum
4545

RELEASES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Release Notes
22

3+
## Pending Release
4+
- Bump golang version to v1.23.6
5+
- Bump golangci-lint to v1.63 and add linters
6+
37
## [v0.14.1](https://github.com/ava-labs/coreth/releases/tag/v0.14.1)
8+
9+
- Removed deprecated `ExportKey`, `ExportAVAX`, `Export`, `ImportKey`, `ImportAVAX`, `Import` APIs
10+
- IMPORTANT: `eth_getProof` calls for historical state will be rejected by default.
11+
- On archive nodes (`"pruning-enabled": false`): queries for historical proofs for state older than approximately 24 hours preceding the last accepted block will be rejected by default. This can be adjusted with the new option `historical-proof-query-window` which defines the number of blocks before the last accepted block which should be accepted for state proof queries, or set to `0` to accept any block number state query (previous behavior).
12+
- On `pruning` nodes: queries for proofs past the tip buffer (32 blocks) will be rejected. This is in support of moving to a path based storage scheme, which does not support historical state proofs.
413
- Remove API eth_getAssetBalance that was used to query ANT balances (deprecated since v0.10.0)
514
- Remove legacy gossip handler and metrics (deprecated since v0.10.0)
615
- Refactored trie_prefetcher.go to be structurally similar to [upstream](https://github.com/ethereum/go-ethereum/tree/v1.13.14).

consensus/dummy/consensus.go

Lines changed: 60 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ import (
1010
"math/big"
1111
"time"
1212

13+
"github.com/ava-labs/avalanchego/utils/math"
1314
"github.com/ava-labs/avalanchego/utils/timer/mockable"
1415
"github.com/ava-labs/coreth/consensus"
1516
"github.com/ava-labs/coreth/consensus/misc/eip4844"
1617
"github.com/ava-labs/coreth/core/state"
1718
"github.com/ava-labs/coreth/core/types"
1819
"github.com/ava-labs/coreth/params"
20+
"github.com/ava-labs/coreth/utils"
1921
"github.com/ava-labs/libevm/common"
2022
"github.com/ava-labs/libevm/trie"
23+
24+
customheader "github.com/ava-labs/coreth/plugin/evm/header"
2125
)
2226

2327
var (
@@ -26,7 +30,6 @@ var (
2630
errInvalidBlockTime = errors.New("timestamp less than parent's")
2731
errUnclesUnsupported = errors.New("uncles unsupported")
2832
errBlockGasCostNil = errors.New("block gas cost is nil")
29-
errBlockGasCostTooLarge = errors.New("block gas cost is not uint64")
3033
errBaseFeeNil = errors.New("base fee is nil")
3134
errExtDataGasUsedNil = errors.New("extDataGasUsed is nil")
3235
errExtDataGasUsedTooLarge = errors.New("extDataGasUsed is not uint64")
@@ -130,41 +133,29 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
130133
}
131134
} else {
132135
// Verify that the gas limit remains within allowed bounds
133-
diff := int64(parent.GasLimit) - int64(header.GasLimit)
134-
if diff < 0 {
135-
diff *= -1
136-
}
136+
diff := math.AbsDiff(parent.GasLimit, header.GasLimit)
137137
limit := parent.GasLimit / params.GasLimitBoundDivisor
138-
139-
if uint64(diff) >= limit || header.GasLimit < params.MinGasLimit {
138+
if diff >= limit || header.GasLimit < params.MinGasLimit {
140139
return fmt.Errorf("invalid gas limit: have %d, want %d += %d", header.GasLimit, parent.GasLimit, limit)
141140
}
142141
}
143142

144-
if !configExtra.IsApricotPhase3(header.Time) {
145-
// Verify BaseFee is not present before AP3
146-
if header.BaseFee != nil {
147-
return fmt.Errorf("invalid baseFee before fork: have %d, want <nil>", header.BaseFee)
148-
}
149-
} else {
150-
// Verify baseFee and rollupWindow encoding as part of header verification
151-
// starting in AP3
152-
expectedRollupWindowBytes, expectedBaseFee, err := CalcBaseFee(config, parent, header.Time)
153-
if err != nil {
154-
return fmt.Errorf("failed to calculate base fee: %w", err)
155-
}
156-
if len(header.Extra) < len(expectedRollupWindowBytes) || !bytes.Equal(expectedRollupWindowBytes, header.Extra[:len(expectedRollupWindowBytes)]) {
157-
return fmt.Errorf("expected rollup window bytes: %x, found %x", expectedRollupWindowBytes, header.Extra)
158-
}
159-
if header.BaseFee == nil {
160-
return errors.New("expected baseFee to be non-nil")
161-
}
162-
if bfLen := header.BaseFee.BitLen(); bfLen > 256 {
163-
return fmt.Errorf("too large base fee: bitlen %d", bfLen)
164-
}
165-
if header.BaseFee.Cmp(expectedBaseFee) != 0 {
166-
return fmt.Errorf("expected base fee (%d), found (%d)", expectedBaseFee, header.BaseFee)
167-
}
143+
// Verify header.Extra matches the expected value.
144+
expectedExtraPrefix, err := CalcExtraPrefix(config, parent, header.Time)
145+
if err != nil {
146+
return fmt.Errorf("failed to calculate extra prefix: %w", err)
147+
}
148+
if !bytes.HasPrefix(header.Extra, expectedExtraPrefix) {
149+
return fmt.Errorf("expected header.Extra to have prefix: %x, found %x", expectedExtraPrefix, header.Extra)
150+
}
151+
152+
// Verify header.BaseFee matches the expected value.
153+
expectedBaseFee, err := CalcBaseFee(config, parent, header.Time)
154+
if err != nil {
155+
return fmt.Errorf("failed to calculate base fee: %w", err)
156+
}
157+
if !utils.BigEqual(header.BaseFee, expectedBaseFee) {
158+
return fmt.Errorf("expected base fee %d, found %d", expectedBaseFee, header.BaseFee)
168159
}
169160

170161
// Verify BlockGasCost, ExtDataGasUsed not present before AP4
@@ -179,27 +170,15 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
179170
}
180171

181172
// Enforce BlockGasCost constraints
182-
blockGasCostStep := ApricotPhase4BlockGasCostStep
183-
if configExtra.IsApricotPhase5(header.Time) {
184-
blockGasCostStep = ApricotPhase5BlockGasCostStep
185-
}
186-
expectedBlockGasCost := calcBlockGasCost(
187-
ApricotPhase4TargetBlockRate,
188-
ApricotPhase4MinBlockGasCost,
189-
ApricotPhase4MaxBlockGasCost,
190-
blockGasCostStep,
191-
parent.BlockGasCost,
192-
parent.Time, header.Time,
173+
expectedBlockGasCost := customheader.BlockGasCost(
174+
configExtra,
175+
parent,
176+
header.Time,
193177
)
194-
if header.BlockGasCost == nil {
195-
return errBlockGasCostNil
196-
}
197-
if !header.BlockGasCost.IsUint64() {
198-
return errBlockGasCostTooLarge
199-
}
200-
if header.BlockGasCost.Cmp(expectedBlockGasCost) != 0 {
178+
if !utils.BigEqualUint64(header.BlockGasCost, expectedBlockGasCost) {
201179
return fmt.Errorf("invalid block gas cost: have %d, want %d", header.BlockGasCost, expectedBlockGasCost)
202180
}
181+
203182
// ExtDataGasUsed correctness is checked during block validation
204183
// (when the validator has access to the block contents)
205184
if header.ExtDataGasUsed == nil {
@@ -213,26 +192,18 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
213192

214193
// modified from consensus.go
215194
func (eng *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *types.Header, parent *types.Header, uncle bool) error {
216-
config := chain.Config()
217-
configExtra := params.GetExtra(config)
218195
// Ensure that we do not verify an uncle
219196
if uncle {
220197
return errUnclesUnsupported
221198
}
222-
switch {
223-
case configExtra.IsDurango(header.Time):
224-
if len(header.Extra) < params.DynamicFeeExtraDataSize {
225-
return fmt.Errorf("expected extra-data field length >= %d, found %d", params.DynamicFeeExtraDataSize, len(header.Extra))
226-
}
227-
case configExtra.IsApricotPhase3(header.Time):
228-
if len(header.Extra) != params.DynamicFeeExtraDataSize {
229-
return fmt.Errorf("expected extra-data field to be: %d, but found %d", params.DynamicFeeExtraDataSize, len(header.Extra))
230-
}
231-
default:
232-
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
233-
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
234-
}
199+
200+
// Verify the extra data is well-formed.
201+
config := chain.Config()
202+
rules := params.GetExtra(config).GetAvalancheRules(header.Time)
203+
if err := customheader.VerifyExtra(rules, header.Extra); err != nil {
204+
return err
235205
}
206+
236207
// Ensure gas-related header fields are correct
237208
if err := eng.verifyHeaderGasFields(config, header, parent); err != nil {
238209
return err
@@ -252,7 +223,7 @@ func (eng *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *
252223
return consensus.ErrInvalidNumber
253224
}
254225
// Verify the existence / non-existence of excessBlobGas
255-
cancun := chain.Config().IsCancun(header.Number, header.Time)
226+
cancun := config.IsCancun(header.Number, header.Time)
256227
if !cancun {
257228
switch {
258229
case header.ExcessBlobGas != nil:
@@ -394,8 +365,10 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
394365
return err
395366
}
396367
}
368+
397369
configExtra := params.GetExtra(chain.Config())
398-
if configExtra.IsApricotPhase4(block.Time()) {
370+
timestamp := block.Time()
371+
if configExtra.IsApricotPhase4(timestamp) {
399372
// Validate extDataGasUsed and BlockGasCost match expectations
400373
//
401374
// NOTE: This is a duplicate check of what is already performed in
@@ -406,28 +379,22 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
406379
if blockExtDataGasUsed := block.ExtDataGasUsed(); blockExtDataGasUsed == nil || !blockExtDataGasUsed.IsUint64() || blockExtDataGasUsed.Cmp(extDataGasUsed) != 0 {
407380
return fmt.Errorf("invalid extDataGasUsed: have %d, want %d", blockExtDataGasUsed, extDataGasUsed)
408381
}
409-
blockGasCostStep := ApricotPhase4BlockGasCostStep
410-
if configExtra.IsApricotPhase5(block.Time()) {
411-
blockGasCostStep = ApricotPhase5BlockGasCostStep
412-
}
413-
// Calculate the expected blockGasCost for this block.
414-
// Note: this is a deterministic transition that defines an exact block fee for this block.
415-
blockGasCost := calcBlockGasCost(
416-
ApricotPhase4TargetBlockRate,
417-
ApricotPhase4MinBlockGasCost,
418-
ApricotPhase4MaxBlockGasCost,
419-
blockGasCostStep,
420-
parent.BlockGasCost,
421-
parent.Time, block.Time(),
382+
383+
// Verify the BlockGasCost set in the header matches the expected value.
384+
blockGasCost := block.BlockGasCost()
385+
expectedBlockGasCost := customheader.BlockGasCost(
386+
configExtra,
387+
parent,
388+
timestamp,
422389
)
423-
// Verify the BlockGasCost set in the header matches the calculated value.
424-
if blockBlockGasCost := block.BlockGasCost(); blockBlockGasCost == nil || !blockBlockGasCost.IsUint64() || blockBlockGasCost.Cmp(blockGasCost) != 0 {
425-
return fmt.Errorf("invalid blockGasCost: have %d, want %d", blockBlockGasCost, blockGasCost)
390+
if !utils.BigEqualUint64(blockGasCost, expectedBlockGasCost) {
391+
return fmt.Errorf("invalid blockGasCost: have %d, want %d", blockGasCost, expectedBlockGasCost)
426392
}
393+
427394
// Verify the block fee was paid.
428395
if err := eng.verifyBlockFee(
429396
block.BaseFee(),
430-
block.BlockGasCost(),
397+
blockGasCost,
431398
block.Transactions(),
432399
receipts,
433400
contribution,
@@ -453,25 +420,21 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
453420
return nil, err
454421
}
455422
}
456-
chainConfigExtra := params.GetExtra(chain.Config())
457-
if chainConfigExtra.IsApricotPhase4(header.Time) {
423+
424+
configExtra := params.GetExtra(chain.Config())
425+
if configExtra.IsApricotPhase4(header.Time) {
458426
header.ExtDataGasUsed = extDataGasUsed
459427
if header.ExtDataGasUsed == nil {
460428
header.ExtDataGasUsed = new(big.Int).Set(common.Big0)
461429
}
462-
blockGasCostStep := ApricotPhase4BlockGasCostStep
463-
if chainConfigExtra.IsApricotPhase5(header.Time) {
464-
blockGasCostStep = ApricotPhase5BlockGasCostStep
465-
}
466430
// Calculate the required block gas cost for this block.
467-
header.BlockGasCost = calcBlockGasCost(
468-
ApricotPhase4TargetBlockRate,
469-
ApricotPhase4MinBlockGasCost,
470-
ApricotPhase4MaxBlockGasCost,
471-
blockGasCostStep,
472-
parent.BlockGasCost,
473-
parent.Time, header.Time,
431+
blockGasCost := customheader.BlockGasCost(
432+
configExtra,
433+
parent,
434+
header.Time,
474435
)
436+
header.BlockGasCost = new(big.Int).SetUint64(blockGasCost)
437+
475438
// Verify that this block covers the block fee.
476439
if err := eng.verifyBlockFee(
477440
header.BaseFee,
@@ -489,7 +452,7 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
489452
// Header seems complete, assemble into a block and return
490453
return types.NewBlockWithExtData(
491454
header, txs, uncles, receipts, trie.NewStackTrie(nil),
492-
extraData, chainConfigExtra.IsApricotPhase1(header.Time),
455+
extraData, configExtra.IsApricotPhase1(header.Time),
493456
), nil
494457
}
495458

0 commit comments

Comments
 (0)