MCPcopy
hub / github.com/bnb-chain/bsc

github.com/bnb-chain/bsc @fusion-audit-4.0 sqlite

repository ↗ · DeepWiki ↗ · release fusion-audit-4.0 ↗
18,368 symbols 90,041 edges 1,233 files 8,890 documented · 48%
README

BNB Smart Chain

The goal of BNB Smart Chain is to bring programmability and interoperability to BNB Beacon Chain. In order to embrace the existing popular community and advanced technology, it will bring huge benefits by staying compatible with all the existing smart contracts on Ethereum and Ethereum tooling. And to achieve that, the easiest solution is to develop based on go-ethereum fork, as we respect the great work of Ethereum very much.

BNB Smart Chain starts its development based on go-ethereum fork. So you may see many toolings, binaries and also docs are based on Ethereum ones, such as the name “geth”.

API Reference Discord

But from that baseline of EVM compatible, BNB Smart Chain introduces a system of 21 validators with Proof of Staked Authority (PoSA) consensus that can support short block time and lower fees. The most bonded validator candidates of staking will become validators and produce blocks. The double-sign detection and other slashing logic guarantee security, stability, and chain finality.

Cross-chain transfer and other communication are possible due to native support of interoperability. Relayers and on-chain contracts are developed to support that. BNB Beacon Chain DEX remains a liquid venue of the exchange of assets on both chains. This dual-chain architecture will be ideal for users to take advantage of the fast trading on one side and build their decentralized apps on the other side. The BNB Smart Chain will be:

  • A self-sovereign blockchain: Provides security and safety with elected validators.
  • EVM-compatible: Supports all the existing Ethereum tooling along with faster finality and cheaper transaction fees.
  • Interoperable: Comes with efficient native dual chain communication; Optimized for scaling high-performance dApps that require fast and smooth user experience.
  • Distributed with on-chain governance: Proof of Staked Authority brings in decentralization and community participants. As the native token, BNB will serve as both the gas of smart contract execution and tokens for staking.

More details in White Paper.

Key features

Proof of Staked Authority

Although Proof-of-Work (PoW) has been approved as a practical mechanism to implement a decentralized network, it is not friendly to the environment and also requires a large size of participants to maintain the security.

Proof-of-Authority(PoA) provides some defense to 51% attack, with improved efficiency and tolerance to certain levels of Byzantine players (malicious or hacked). Meanwhile, the PoA protocol is most criticized for being not as decentralized as PoW, as the validators, i.e. the nodes that take turns to produce blocks, have all the authorities and are prone to corruption and security attacks.

Other blockchains, such as EOS and Cosmos both, introduce different types of Deputy Proof of Stake (DPoS) to allow the token holders to vote and elect the validator set. It increases the decentralization and favors community governance.

To combine DPoS and PoA for consensus, BNB Smart Chain implement a novel consensus engine called Parlia that:

  1. Blocks are produced by a limited set of validators.
  2. Validators take turns to produce blocks in a PoA manner, similar to Ethereum's Clique consensus engine.
  3. Validator set are elected in and out based on a staking based governance on BNB Beacon Chain.
  4. The validator set change is relayed via a cross-chain communication mechanism.
  5. Parlia consensus engine will interact with a set of system contracts to achieve liveness slash, revenue distributing and validator set renewing func.

Light Client of BNB Beacon Chain

To achieve the cross-chain communication from BNB Beacon Chain to BNB Smart Chain, need introduce a on-chain light client verification algorithm. It contains two parts:

  1. Stateless Precompiled contracts to do tendermint header verification and Merkle Proof verification.
  2. Stateful solidity contracts to store validator set and trusted appHash.

Native Token

BNB will run on BNB Smart Chain in the same way as ETH runs on Ethereum so that it remains as native token for BSC. This means, BNB will be used to:

  1. pay gas to deploy or invoke Smart Contract on BSC
  2. perform cross-chain operations, such as transfer token assets across BNB Smart Chain and BNB Beacon Chain.

Building the source

Many of the below are the same as or similar to go-ethereum.

For prerequisites and detailed build instructions please read the Installation Instructions.

Building geth requires both a Go (version 1.21 or later) and a C compiler (GCC 5 or higher). You can install them using your favourite package manager. Once the dependencies are installed, run

make geth

or, to build the full suite of utilities:

make all

If you get such error when running the node with self built binary:

Caught SIGILL in blst_cgo_init, consult <blst>/bindinds/go/README.md.

please try to add the following environment variables and build again:

export CGO_CFLAGS="-O -D__BLST_PORTABLE__" 
export CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"

Executables

The bsc project comes with several wrappers/executables found in the cmd directory.

Command Description
geth Main BNB Smart Chain client binary. It is the entry point into the BSC network (main-, test- or private net), capable of running as a full node (default), archive node (retaining all historical state) or a light node (retrieving data live). It has the same and more RPC and other interface as go-ethereum and can be used by other processes as a gateway into the BSC network via JSON RPC endpoints exposed on top of HTTP, WebSocket and/or IPC transports. geth --help and the CLI page for command line options.
clef Stand-alone signing tool, which can be used as a backend signer for geth.
devp2p Utilities to interact with nodes on the networking layer, without running a full blockchain.
abigen Source code generator to convert Ethereum contract definitions into easy to use, compile-time type-safe Go packages. It operates on plain Ethereum contract ABIs with expanded functionality if the contract bytecode is also available. However, it also accepts Solidity source files, making development much more streamlined. Please see our Native DApps page for details.
bootnode Stripped down version of our Ethereum client implementation that only takes part in the network node discovery protocol, but does not run any of the higher level application protocols. It can be used as a lightweight bootstrap node to aid in finding peers in private networks.
evm Developer utility version of the EVM (Ethereum Virtual Machine) that is capable of running bytecode snippets within a configurable environment and execution mode. Its purpose is to allow isolated, fine-grained debugging of EVM opcodes (e.g. evm --code 60ff60ff --debug run).
rlpdump Developer utility tool to convert binary RLP (Recursive Length Prefix) dumps (data encoding used by the Ethereum protocol both network as well as consensus wise) to user-friendlier hierarchical representation (e.g. rlpdump --hex CE0183FFFFFFC4C304050583616263).

Running geth

Going through all the possible command line flags is out of scope here (please consult our CLI Wiki page), but we've enumerated a few common parameter combos to get you up to speed quickly on how you can run your own geth instance.

Hardware Requirements

The hardware must meet certain requirements to run a full node on mainnet: - VPS running recent versions of Mac OS X, Linux, or Windows. - IMPORTANT 3 TB(Dec 2023) of free disk space, solid-state drive(SSD), gp3, 8k IOPS, 500 MB/S throughput, read latency <1ms. (if node is started with snap sync, it will need NVMe SSD) - 16 cores of CPU and 64 GB of memory (RAM) - Suggest m5zn.6xlarge or r7iz.4xlarge instance type on AWS, c2-standard-16 on Google cloud. - A broadband Internet connection with upload/download speeds of 5 MB/S

The requirement for testnet: - VPS running recent versions of Mac OS X, Linux, or Windows. - 500G of storage for testnet. - 4 cores of CPU and 16 gigabytes of memory (RAM).

Steps to Run a Fullnode

1. Download the pre-build binaries

# Linux
wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep geth_linux |cut -d\" -f4)
mv geth_linux geth
chmod -v u+x geth

# MacOS
wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep geth_mac |cut -d\" -f4)
mv geth_macos geth
chmod -v u+x geth

2. Download the config files

//== mainnet
wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep mainnet |cut -d\" -f4)
unzip mainnet.zip

//== testnet
wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep testnet |cut -d\" -f4)
unzip testnet.zip

3. Download snapshot

Download latest chaindata snapshot from here. Follow the guide to structure your files.

Note: If you encounter difficulties downloading the chaindata snapshot and prefer to synchronize from the genesis block on the Chapel testnet, remember to include the additional flag --chapel when initially launching Geth.

4. Start a full node

```shell ./geth --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --history.transactions 0

It is recommand to run fullnode with --tries-verify-mode none if you want high performance and care little about state consistency

It will run with Hash-Base Storage Scheme by default

./geth --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --history.transactions 0 --tries-verify-mode none

It

Extension points exported contracts — how you extend this code

Subscription (Interface)
TODO: move subscription to package event Subscription represents an event subscription where events are delivered on a d [6 …
interfaces.go
Encoder (Interface)
Encoder is implemented by types that require custom encoding rules or want to encode private fields. [17 implementers]
rlp/encode.go
KeccakState (Interface)
KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of d [10 …
crypto/crypto.go
GaugeFloat64 (Interface)
GaugeFloat64s hold a float64 value that can be set arbitrarily. [6 implementers]
metrics/gauge_float64.go
Stoppable (Interface)
Stoppable defines the metrics which has to be stopped. [44 implementers]
metrics/registry.go
AccountIterator (Interface)
AccountIterator is an iterator to step over all the accounts in a snapshot, which may or may not be composed of multiple [10 …
core/state/snapshot/iterator.go
ContractRef (Interface)
ContractRef is a reference to the contract's backing object [9 implementers]
core/vm/contract.go
UIClientAPI (Interface)
UIClientAPI specifies what method a UI needs to implement to be able to be used as a UI for the signer [7 implementers]
signer/core/api.go

Core symbols most depended-on inside this repo

Errorf
called by 3234
internal/utesting/utesting.go
Fatalf
called by 2016
internal/utesting/utesting.go
New
called by 1346
log/logger.go
Fatal
called by 1295
internal/utesting/utesting.go
Hash
called by 1172
core/state/database.go
String
called by 699
p2p/nat/nat.go
Lock
called by 636
accounts/keystore/keystore.go
Bytes
called by 629
core/types/bloom9.go

Shape

Method 8,792
Function 7,287
Struct 1,695
TypeAlias 237
Interface 204
FuncType 80
Class 73

Languages

Go90%
TypeScript9%
Java1%
Python1%

Modules by API surface

graphql/internal/graphiql/graphiql.min.js1,151 symbols
graphql/internal/graphiql/react-dom.production.min.js332 symbols
accounts/usbwallet/trezor/messages-management.pb.go300 symbols
internal/jsre/deps/web3.js163 symbols
eth/downloader/downloader_test.go147 symbols
internal/ethapi/api.go144 symbols
accounts/usbwallet/trezor/messages-common.pb.go143 symbols
graphql/graphql.go137 symbols
accounts/usbwallet/trezor/messages-ethereum.pb.go134 symbols
core/blockchain_sethead_test.go118 symbols
core/blockchain_repair_test.go115 symbols
core/blockchain_test.go111 symbols

Dependencies from manifests, versioned

github.com/Azure/azure-sdk-for-go/sdk/azcorev0.21.1 · 1×
github.com/Azure/azure-sdk-for-go/sdk/internalv0.8.3 · 1×
github.com/Azure/azure-sdk-for-go/sdk/storage/azblobv0.3.0 · 1×
github.com/BurntSushi/tomlv1.3.2 · 1×
github.com/DataDog/zstdv1.5.2 · 1×
github.com/VictoriaMetrics/fastcachev1.12.1 · 1×
github.com/aristanetworks/goaristav0.0.0-2020080513081 · 1×
github.com/aws/aws-sdk-go-v2v1.17.8 · 1×
github.com/aws/aws-sdk-go-v2/configv1.1.1 · 1×
github.com/aws/aws-sdk-go-v2/credentialsv1.1.1 · 1×
github.com/aws/aws-sdk-go-v2/feature/ec2/imdsv1.0.2 · 1×

For agents

$ claude mcp add bsc \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact