coreth

module
v0.13.0-rc.0-1709748503 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: GPL-3.0, LGPL-3.0

README

Coreth and the C-Chain

Avalanche is a network composed of multiple blockchains. 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. That is, the VM defines the behavior of the blockchain. Coreth (from core Ethereum) is the Virtual Machine (VM) that defines the Contract Chain (C-Chain). This chain implements the Ethereum Virtual Machine and supports Solidity smart contracts as well as most other Ethereum client functionality.

Building

Coreth is a dependency of AvalancheGo which is used to implement the EVM based Virtual Machine for the Avalanche C-Chain. In order to run with a local version of Coreth, users must update their Coreth dependency within AvalancheGo to point to their local Coreth directory. If Coreth and AvalancheGo are at the standard location within your GOPATH, this will look like the following:

cd $GOPATH/src/github.com/ava-labs/avalanchego
go mod edit -replace github.com/ava-labs/coreth=../coreth

Now that AvalancheGo depends on the local version of Coreth, we can build with the normal build script:

./scripts/build.sh
./build/avalanchego

Note: the C-Chain originally ran in a separate process from the main AvalancheGo process and communicated with it over a local gRPC connection. When this was the case, AvalancheGo's build script would download Coreth, compile it, and place the binary into the avalanchego/build/plugins directory.

API

The C-Chain supports the following API namespaces:

  • eth
  • personal
  • txpool
  • debug

Only the eth namespace is enabled by default. To enable the other namespaces see the instructions for passing the C-Chain config to AvalancheGo here. Full documentation for the C-Chain's API can be found here.

Compatibility

The C-Chain is compatible with almost all Ethereum tooling, including Remix, Metamask and Truffle.

Differences Between Avalanche C-Chain and Ethereum

Atomic Transactions

As a network composed of multiple blockchains, Avalanche uses atomic transactions to move assets between chains. Coreth modifies the Ethereum block format by adding an ExtraData field, which contains the atomic transactions.

Avalanche Native Tokens (ANTs)

The C-Chain supports Avalanche Native Tokens, which are created on the X-Chain using precompiled contracts. These precompiled contracts nativeAssetCall and nativeAssetBalance support the same interface for ANTs as CALL and BALANCE do for AVAX with the added parameter of assetID to specify the asset.

For the full documentation of precompiles for interacting with ANTs and using them in ARC-20s, see here.

Block Timing

Blocks are produced asynchronously in Snowman Consensus, so the timing assumptions that apply to Ethereum do not apply to Coreth. To support block production in an async environment, a block is permitted to have the same timestamp as its parent. Since there is no general assumption that a block will be produced every 10 seconds, smart contracts built on Avalanche should use the block timestamp instead of the block number for their timing assumptions.

A block with a timestamp more than 10 seconds in the future will not be considered valid. However, a block with a timestamp more than 10 seconds in the past will still be considered valid as long as its timestamp is greater than or equal to the timestamp of its parent block.

Difficulty and Random OpCode

Snowman consensus does not use difficulty in any way, so the difficulty of every block is required to be set to 1. This means that the DIFFICULTY opcode should not be used as a source of randomness.

Additionally, with the change from the DIFFICULTY OpCode to the RANDOM OpCode (RANDOM replaces DIFFICULTY directly), there is no planned change to provide a stronger source of randomness. The RANDOM OpCode relies on the Eth2.0 Randomness Beacon, which has no direct parallel within the context of either Coreth or Snowman consensus. Therefore, instead of providing a weaker source of randomness that may be manipulated, the RANDOM OpCode will not be supported. Instead, it will continue the behavior of the DIFFICULTY OpCode of returning the block's difficulty, such that it will always return 1.

Block Format

To support these changes, there have been a number of changes to the C-Chain block format compared to what exists on Ethereum.

Block Body
  • Version: provides version of the ExtData in the block. Currently, this field is always 0.
  • ExtData: extra data field within the block body to store atomic transaction bytes.
Block Header
  • ExtDataHash: the hash of the bytes in the ExtDataHash field
  • BaseFee: Added by EIP-1559 to represent the base fee of the block (present in Ethereum as of EIP-1559)
  • ExtDataGasUsed: amount of gas consumed by the atomic transactions in the block
  • BlockGasCost: surcharge for producing a block faster than the target rate

Directories

Path Synopsis
Package accounts implements high level Ethereum account management.
Package accounts implements high level Ethereum account management.
abi
Package abi implements the Ethereum ABI (Application Binary Interface).
Package abi implements the Ethereum ABI (Application Binary Interface).
abi/bind
Package bind generates Ethereum contract Go bindings.
Package bind generates Ethereum contract Go bindings.
keystore
Package keystore implements encrypted storage of secp256k1 private keys.
Package keystore implements encrypted storage of secp256k1 private keys.
cmd
abigen
(c) 2023, Ava Labs, Inc.
(c) 2023, Ava Labs, Inc.
Package consensus implements different Ethereum consensus engines.
Package consensus implements different Ethereum consensus engines.
Package core implements the Ethereum consensus protocol.
Package core implements the Ethereum consensus protocol.
bloombits
Package bloombits implements bloom filtering on batches of data.
Package bloombits implements bloom filtering on batches of data.
rawdb
Package rawdb contains a collection of low level database accessors.
Package rawdb contains a collection of low level database accessors.
state
Package state provides a caching layer atop the Ethereum state trie.
Package state provides a caching layer atop the Ethereum state trie.
state/snapshot
Package snapshot implements a journalled, dynamic state dump.
Package snapshot implements a journalled, dynamic state dump.
types
Package types contains data types related to Ethereum consensus.
Package types contains data types related to Ethereum consensus.
vm
Package vm implements the Ethereum Virtual Machine.
Package vm implements the Ethereum Virtual Machine.
vm/runtime
Package runtime provides a basic execution model for executing EVM code.
Package runtime provides a basic execution model for executing EVM code.
eth
Package eth implements the Ethereum protocol.
Package eth implements the Ethereum protocol.
filters
Package filters implements an ethereum filtering system for block, transactions and log events.
Package filters implements an ethereum filtering system for block, transactions and log events.
tracers
Package tracers is a manager for transaction tracing engines.
Package tracers is a manager for transaction tracing engines.
tracers/internal/tracetest
(c) 2023, Ava Labs, Inc.
(c) 2023, Ava Labs, Inc.
tracers/js/internal/tracers
Package tracers contains the actual JavaScript tracer assets.
Package tracers contains the actual JavaScript tracer assets.
Package ethclient provides a client for the Ethereum RPC API.
Package ethclient provides a client for the Ethereum RPC API.
corethclient
Package corethclient provides an RPC client for coreth-specific APIs.
Package corethclient provides an RPC client for coreth-specific APIs.
Package ethereum defines interfaces for interacting with Ethereum.
Package ethereum defines interfaces for interacting with Ethereum.
internal
debug
Package debug interfaces Go runtime debugging facilities.
Package debug interfaces Go runtime debugging facilities.
ethapi
Package ethapi implements the general Ethereum API functions.
Package ethapi implements the general Ethereum API functions.
version
Package version implements reading of build version information.
Package version implements reading of build version information.
Go port of Coda Hale's Metrics library
Go port of Coda Hale's Metrics library
Package miner implements Ethereum block creation and mining.
Package miner implements Ethereum block creation and mining.
evm
precompile
contract
Defines the interface for the configuration and execution of a precompile contract
Defines the interface for the configuration and execution of a precompile contract
precompileconfig
Defines the stateless interface for unmarshalling an arbitrary config of a precompile
Defines the stateless interface for unmarshalling an arbitrary config of a precompile
registry
Module to facilitate the registration of precompiles and their configuration.
Module to facilitate the registration of precompiles and their configuration.
Package rpc implements bi-directional JSON-RPC 2.0 on multiple transports.
Package rpc implements bi-directional JSON-RPC 2.0 on multiple transports.
signer
sync
Package trie implements Merkle Patricia Tries.
Package trie implements Merkle Patricia Tries.
aggregator
Package aggregator is a generated GoMock package.
Package aggregator is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL