-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BEP-221: CometBFT Light Block Validation #221
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<pre> | ||
BEP: 221 | ||
Title: CometBFT Light Block Validation | ||
Status: Draft | ||
Type: Standards | ||
Created: 2022-04-11 | ||
</pre> | ||
|
||
# BEP-221: CometBFT Light Block Validation. | ||
|
||
- [BEP-221: CometBFT Light Block Validation.](#bep-221--cometbft-light-block-validation) | ||
- [1. Summary](#1-summary) | ||
- [2. Motivation](#2-motivation) | ||
- [3. Specification](#3-specification) | ||
- [4. License](#4-license) | ||
|
||
## 1. Summary | ||
|
||
This BEP introduces a new precompiled contract to validate the [CometBFT](https://docs.cometbft.com/v0.37/introduction/) light blocks. | ||
|
||
## 2. Motivation | ||
|
||
There are some cross-chain requirements between BSC and CometBFT-compatible blockchains, like the `BNB Greenfield` which | ||
is an important part of the BNB ecosystem, thus we need a gas-friendly solution to validate the light blocks from the | ||
CometBFT-compatible blockchains. | ||
|
||
## 3. Specification | ||
|
||
### 3.1 Consensus State | ||
|
||
To validate the light blocks from the CometBFT-compatible blockchains, there should be a light client of the blockchain | ||
on the BSC side, it could be implemented as a smart contract, and this light client should record the necessary | ||
current state which we call it **Consensus State** to validate the future light blocks. The consensus state is defined as: | ||
|
||
```go | ||
type ConsensusState struct { | ||
ChainID string | ||
Height uint64 | ||
NextValidatorSetHash []byte | ||
ValidatorSet *types.ValidatorSet | ||
} | ||
``` | ||
|
||
The consensus state should be encoded as a part of the precompiled contract's input, and after applying the light block, | ||
the updated consensus state should be encoded as a part of the precompiled contract's output. The encoding format should be: | ||
``` | ||
|--ChainID---|--Height---|--NextValidatorSetHash--|--[{validator pubkey, voting power, relayer address, relayer bls pubkey}]--| | ||
|--32 bytes--|--8 bytes--|--32 bytes--------------|--[{32 bytes, 8 bytes, 20 bytes, 48 bytes}]--------------------------------| | ||
``` | ||
|
||
The `validator pubkey` and `voting power` are necessary for recovering the validator in the current validator set. The | ||
`relayer address` and `relayer bls pubkey` are extended to support some cross-chain infrastructure base on [BLS](https://en.wikipedia.org/wiki/BLS_digital_signature), | ||
we can just pad zero bytes if we don't use `relayer address` or `relayer bls pubkey`. | ||
|
||
### 3.2 Light Block | ||
|
||
A light block of CometBFT-compatible blockchain contains a SignedHeader and a ValidatorSet, which can be imported into | ||
the [CometBFT Light Client](https://docs.cometbft.com/v0.37/spec/light-client/) and update the light client's consensus state accordingly. The light block is defined as: | ||
|
||
```go | ||
type LightBlock struct { | ||
*SignedHeader `json:"signed_header"` | ||
ValidatorSet *ValidatorSet `json:"validator_set"` | ||
} | ||
``` | ||
|
||
The light block itself has a **Marshal** method to convert it into a byte array, and it should be a part of the precompiled | ||
contract's input. Within the precompiled contract, use the **Unmarshal** method to recover it. | ||
|
||
### 3.3 Validate Light Block | ||
|
||
The input of the precompiled contract should include the current consensus state and the future light block. The encoding | ||
format should be: | ||
``` | ||
|--consensus state length--|--consensus state--|--light block--| | ||
|--32 bytes----------------|-------------------|---------------| | ||
``` | ||
|
||
Here are the steps to validate the light block within the precompiled contract: | ||
1. Decode the input to get the current consensus state and the light block. | ||
2. Apply the light block into the current consensus state according to [CometBFT Light Client Verification](https://docs.cometbft.com/v0.37/spec/light-client/verification/). | ||
3. Encode the updated consensus state and return it to the caller. | ||
|
||
The output of the precompiled contract should be encoded as follows: | ||
``` | ||
|--validatorSetChanged--|--empty-----|--consensus state length--|--new consensus state--| | ||
|--1 byte---------------|--23 bytes--|--8 bytes-----------------|-----------------------| | ||
``` | ||
|
||
## 4. License | ||
|
||
The content is licensed under [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the
BNB Greenfield
which is an important part of the BNB ecosystem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the part2, please check.