Skip to content

Commit

Permalink
BEP-336: update BlobGasPrice (bnb-chain#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzckck authored Apr 8, 2024
1 parent aed6ce5 commit 9edceaf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions BEPs/BEP-336.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
- [5.10 Execution layer validation](#510-execution-layer-validation)
- [5.11 Networking](#511-networking)
- [TransactionPayload](#transactionpayload)
- [BlockWithExtraData](#blockwithextradata)
- [BlockPayload and P2P Message](#blockpayload-and-p2p-message)
- [6. Rationale](#6-rationale)
- [6.1 Why Not Integrate The Sidecar Protocol On BSC](#61-why-not-integrate-the-sidecar-protocol-on-bsc)
- [6.2 Why Minimum/Maximum Blob Gas Price](#62-why-minimummaximum-blob-gas-price)
- [7. Backwards Compatibility](#7-backwards-compatibility)
- [8. Security Considerations](#8-security-considerations)
- [9. License](#9-license)
Expand Down Expand Up @@ -72,8 +71,6 @@ BSC has same target to reduce the L2 rollup cost. This BEP will propose an idea
| `MAX_BLOB_GAS_PER_BLOCK` | `786432` |
| `TARGET_BLOB_GAS_PER_BLOCK` | `393216` |
| `MIN_BLOB_GASPRICE` | `1` |
| `MIN_BLOB_GASPRICE_BSC` | `3000000000` |
| `MAX_BLOB_GASPRICE_BSC` | `50000000000` |
| `BLOB_GASPRICE_UPDATE_FRACTION` | `3338477` |
| `GAS_PER_BLOB` | `2**17` |
| `HASH_OPCODE_BYTE` | `Bytes1(0x49)` |
Expand Down Expand Up @@ -189,8 +186,8 @@ For the first post-fork block, both `parent.blob_gas_used` and `parent.excess_bl
### 5.7 Gas accounting

We introduce blob gas as a new type of gas. It is independent of normal gas and follows its own targeting rule, similar to EIP-1559.
We use the `excess_blob_gas` header field to store persistent data needed to compute the blob gas price. For now, only blobs are priced in blob gas. Unlike Ethereum, BSC will have additional minimum/maximum gas price check to keep the blob gas price within a stable and reasonable range.
![BlobGasPrice](./assets/BEP-336/blobgasprice.png)
We use the `excess_blob_gas` header field to store persistent data needed to compute the blob gas price. For now, only blobs are priced in blob gas.
![BlobGasPrice](./assets/BEP-336/blob_gasprice.png)

```python
def calc_data_fee(header: Header, tx: Transaction) -> int:
Expand All @@ -200,16 +197,11 @@ def get_total_blob_gas(tx: Transaction) -> int:
return GAS_PER_BLOB * len(tx.blob_versioned_hashes)

def get_blob_gasprice(header: Header) -> int:
dynamicPrice = fake_exponential(
return fake_exponential(
MIN_BLOB_GASPRICE,
header.excess_blob_gas,
BLOB_GASPRICE_UPDATE_FRACTION
)
if dynamicPrice < MIN_BLOB_GASPRICE_BSC
return MIN_BLOB_GASPRICE_BSC
if dynamicPrice > MAX_BLOB_GASPRICE_BSC
return MAX_BLOB_GASPRICE_BSC
return dynamicPrice
```

The block validity conditions are modified to include blob gas checks (see the [Execution layer validation](#execution-layer-validation) section below).
Expand Down Expand Up @@ -259,8 +251,9 @@ The precompile MUST reject non-canonical field elements (i.e. provided field ele
### 5.10 Execution layer validation

As there is no consensus layer on BSC, the execution layer will be tasked with persistence and propagation of the blobs for data availability. Blobs will be kept for at least for `MIN_BLOCKS_FOR_BLOB_REQUESTS` blocks, which is ~18.2 days on BSC, same as Ethereum.
And on the execution layer, the block validity conditions are extended as follows:
![BlobExpire](./assets/BEP-336/blob_expire.png)

And on the execution layer, the block validity conditions are extended as follows:
```python
def validate_block(block: Block) -> None:
...
Expand Down Expand Up @@ -333,16 +326,20 @@ For body retrieval responses (`BlockBodies`), the standard EIP-2718 blob transac
Nodes MUST NOT automatically broadcast blob transactions to their peers.
Instead, those transactions are only announced using `NewPooledTransactionHashes` messages, and can then be manually requested via `GetPooledTransactions`.

#### BlockWithExtraData
#### BlockPayload and P2P Message

Unlike Ethereum, Blobs will be broadcasted with block as a unit for BSC, the broadcast message will be rlp encoded as:
Unlike Ethereum, block & blobs are broadcasted as a unit for BSC. But from network message perspective, it can be one single message(approach 1) or several interactive messages(approach 2):

**Approach 1**: Broadcast block and blobs in a single message, the broadcast message will be rlp encoded as:
```
rlp([block_body, sidecars])
```
Each of these elements are defined as follows:
- `block_body`: it is the standard block body definition.
- `sidecars`: a array of sidecar, each sidecar contains `blobs`, `commitments`, `proofs` of a blob transaction.

**Approach 2**: Broadcast block and blobs separately to reduce the network traffic, e.g. broadcast the block first, but if the receiver does not have the corresponding sidecars, it needs to request the missing sidecars through a query message.

## 6. Rationale

BSC shares the same rational of [Ethereum EIP-4844](https://eips.ethereum.org/EIPS/eip-4844), but with several extra points.
Expand All @@ -352,15 +349,6 @@ BSC shares the same rational of [Ethereum EIP-4844](https://eips.ethereum.org/EI
For Ethereum, Blob sync is implemented on the consensus layer with a module called: sidecar. Unlike Ethereum, BSC does not have the consensus layer, it could be quite complicated to implement it on BSC, as it will involve mechanisms like: backfilling, sidecar sync protocol, sidecar persistent… So it would be better to implement it in a simpler way, just sync blobs with blocks directly. It would be much more reliable for blob availability, since we make it mandatory that blocks and blobs are propagated as a unit; When there is a block, its unexpired blobs must exist as well.
Sidecar is also designed to support the future Danksharding DAS, it could be a challenge for BSC to support Danksharding in the future. But as Danksharding would not be delivered in near future, BSC still have plenty of time to support it.

### 6.2 Why Minimum/Maximum Blob Gas Price

BSC will use dynamic blob gas price, same as Ethereum to guarantee quality of service and also avoid DDOS attack. But the network traffic pattern on BSC could be quite different from Ethereum, network traffic is unstable on BSC. If BSC simply uses the dynamic blob gas price as Ethereum, the gas price could be super low for most of the time and super high when there is a burst traffic on opBNB.

Assuming BNB token price 400$, the current opBNB rollup cost with 117 KB(120000B) calldata is ~2.3$. To keep the blob gas price within a reasonable range, BSC will apply minimum/maximum gas price policy:
- MIN_BLOB_GASPRICE_BSC 3 Gwei: ~0.15$ per blob
- MAX_BLOB_GASPRICE_BSC 50 Gwei: ~2.6$ per blob
The 50 Gwei MAX_BLOB_GASPRICE_BSC is to make sure the maximum blob cost will be similar to the cost of calldata.

## 7. Backwards Compatibility

This part will be same as [Ethereum EIP-4844](https://eips.ethereum.org/EIPS/eip-4844).
Expand Down
Binary file added BEPs/assets/BEP-336/blob_expire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BEPs/assets/BEP-336/blob_gasprice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed BEPs/assets/BEP-336/blobgasprice.png
Binary file not shown.
Binary file removed BEPs/assets/BEP-336/blobtxlife.png
Binary file not shown.

0 comments on commit 9edceaf

Please sign in to comment.