• Stars
    star
    180
  • Rank 213,097 (Top 5 %)
  • Language
    Go
  • License
    Other
  • Created almost 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code and wrapper to extract Ethereum blockchain functionalities without network/consensus, for building custom blockchain services.

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

More Repositories

1

avalanchego

Go implementation of an Avalanche node.
Go
2,109
star
2

avalanche-faucet

Avalanche Faucet for Fuji Network and Subnets.
TypeScript
467
star
3

avalanchejs

The Avalanche Platform JavaScript Library
TypeScript
319
star
4

avalanche-smart-contract-quickstart

The easiest way to build smart contracts on Avalanche.
Solidity
250
star
5

subnet-evm

Launch your own EVM as an Avalanche Subnet
Go
239
star
6

avalanche-wallet

The Avalanche web wallet
Vue
229
star
7

hypersdk

Opinionated Framework for Building Hyper-Scalable Blockchains on Avalanche
Go
193
star
8

mastering-avalanche

Mastering Avalanche 1st Edition - The Internet of Finance
176
star
9

avalanche-docs

Protocol documentation for the Avalanche network.
MDX
161
star
10

firewood

Compaction-Less Database Optimized for Efficiently Storing Recent Merkleized Blockchain State
Rust
109
star
11

avalanche-cli

Go
100
star
12

spacesvm

Go
85
star
13

avalanche-explorer

The Vue frontend for the Avalanche blockchain.
Vue
82
star
14

avalanche-network-runner

Tool to run and interact with an Avalanche network locally
Go
81
star
15

avash

Avash - The Avalanche Shell Client
Go
72
star
16

ortelius

State archival and indexer for the Avalanche network. Used in the Avalanche Explorer.
Go
59
star
17

subnet-cli

Go
58
star
18

avalanche-rs

Avalanche APIs/VM SDK in Rust
Rust
45
star
19

avalanche-wallet-sdk

A Typescript library to create and manage wallets on the Avalanche network.
TypeScript
39
star
20

avalanche-ops

operation toolkit for Avalanche nodes
Rust
38
star
21

wrapped-assets

Smart Contract for Wrapped AVAX
Solidity
38
star
22

ecosystem-projects

JavaScript
33
star
23

avalanche-types-rs

Avalanche primitive types in Rust (experimental)
Rust
32
star
24

avalanche-faucet-legacy

A frontend Vue application for the Avalanche Faucet
TypeScript
30
star
25

avalanche-rosetta

Rosetta server for Avalanche (C-Chain and P-Chain)
Go
30
star
26

xsvm

Example Virtual Machine supporting Subnet Messaging on the Avalanche Network
Go
29
star
27

ava-sim

Go
28
star
28

avalanche-bridge-resources

Token List for the Avalanche Bridge
Solidity
26
star
29

teleporter

EVM cross-chain messaging protocol built on top of Avalanche Warp Messaging
Solidity
23
star
30

timestampvm

timestampvm implementation as rpc-plugin
Go
23
star
31

bridge-tokens

Python
23
star
32

precompile-evm

A new repository for Subnet-EVM Stateful Precompiles
Shell
20
star
33

blobvm

Go
19
star
34

timestampvm-rs

Timestamp VM in Rust
Rust
18
star
35

avax-js-cli-tools

A collection of helpful scripts for the Avalanche network.
JavaScript
17
star
36

spacesvm-js

TypeScript
17
star
37

avalanche-interchain-token-transfer

Cross-chain token transfer built on top of Teleporter
Solidity
13
star
38

indexvm

The Context Layer of the Decentralized Web
Go
11
star
39

avalanche-monitoring

Monitoring tooling for Avalanche nodes
Shell
10
star
40

avalanche-quicksign

A very simple webpage that signs a string with a private key and prompts the user to email it. Used to verify users on the test net.
Vue
10
star
41

mnemonic-shamir-secret-sharing-cli

C++
10
star
42

ledger-avalanche

Rust
9
star
43

audits

Security audits for the Avalanche platform
9
star
44

awm-relayer

Service for relaying Avalanche Warp Messages between Subnets
Go
9
star
45

apm

Plugin manager for Avalanche
Go
8
star
46

avalanche-dapp-sdks

Working example of a dapp working with core extension
TypeScript
8
star
47

avalanche-network-runner-sdk-rs

avalanche-network-runner-sdk-rs
Rust
8
star
48

avalanchetipbot

Avalanche Tip Bot for telegram, twitter and discord.
JavaScript
7
star
49

core-mobile

TypeScript
7
star
50

chainsafe-scripts

Scripts for chainsafe analysis
Python
6
star
51

avalanche-evm-gasless-transaction

Rust
6
star
52

public-facing-docs

Repo of public docs
6
star
53

spacesvm-rs

Spaces VM in Rust
Rust
6
star
54

avalanche-network-runner-sdk

Go
5
star
55

avalanche-network-runner-postman-collection

A postman colllection to interact with the Avalanche Network Runner
4
star
56

avalanche-plugins-core

Core plugins for Avalanche
4
star
57

vue-components

A collection of Vue based components used across our application frontends.
Vue
4
star
58

firewood-mit

Rust
4
star
59

avalanche-ledger-go

Shell
3
star
60

avalanchego-kurtosis

Run AvalancheGo tests in the Kurtosis framework
Go
3
star
61

open-defi-hackathon

3
star
62

gnosis-subnet

Helper repo for deploying gnosis safe contracts on Avalanche subnets
Shell
3
star
63

cargo-workspace-version

Cargo plugin to check and/or update all local package versions in a workspace
Rust
3
star
64

spacesvm-postman-collection

Postman collection for the SpacesVM
2
star
65

avalanchejs-docs

Documentation for AvalancheJS
2
star
66

subnet-assets

JavaScript
2
star
67

ip-manager

IP manager
Rust
2
star
68

avalanche-telemetry

Avalanche node telemetry agent (supports CloudWatch, DataDog)
Rust
2
star
69

qevm

Rust
2
star
70

public-avalanche-sdks

Public SDKs for interfacing with Avalanche
TypeScript
2
star
71

avalanche-tooling-sdk-go

Go
2
star
72

avalanche-installer

Avalanche installer
Rust
1
star
73

btcb-por-workshop

Demo contracts for interacting with the BTC.b Proof-of-Reserves on Fuji Testnet
Shell
1
star
74

avalanchego-operator

Go
1
star
75

avalanche-hackathon

Solidity
1
star
76

homebrew-avalanchego

Homebrew formula for distribution of public avalanche binaries to MacOS
Ruby
1
star