Compare commits

...

7 Commits

Author SHA1 Message Date
colin
076cfc1eae refactor(relayer): optimize l1 block schema (#648)
Co-authored-by: georgehao <haohongfan@gmail.com>
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-07-20 17:26:43 +08:00
Xi Lin
25e4b6c19d fix(contracts): OZ-L1-L04 Lost Funds in Messenger Contracts (#637)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-07-20 17:08:02 +08:00
Péter Garamvölgyi
bae38de0d3 fix(contracts): OZ-L1-L05 Outdated OpenZeppelin Library Version (#622)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Co-authored-by: zimpha <zimpha@gmail.com>
2023-07-20 16:54:43 +08:00
Xi Lin
c9f623b12b fix(contracts): OZ-L1-L01 Batch Reverting Can Pause Finalization (#634)
Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-07-20 16:36:37 +08:00
Xi Lin
3491f0ebff fix(contracts): OZ-L1-L08 Batch Events Lack Information (#624)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-07-20 16:24:27 +08:00
Xi Lin
ff4a9e1dd2 fix(contracts): OZ-L1-L07 Lack of Logs on Sensitive Actions (#623)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-07-20 16:10:06 +08:00
Xi Lin
f8ec59f7e1 fix(contracts): OZ-L1-M02 Lack of Upgradeability Storage Gaps (#618)
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
2023-07-20 15:52:48 +08:00
36 changed files with 365 additions and 104 deletions

View File

@@ -52,7 +52,7 @@ type Layer1Relayer struct {
gasPriceDiff uint64
l1MessageOrm *orm.L1Message
l1Block *orm.L1Block
l1BlockOrm *orm.L1Block
}
// NewLayer1Relayer will return a new instance of Layer1RelayerClient
@@ -90,7 +90,7 @@ func NewLayer1Relayer(ctx context.Context, db *gorm.DB, cfg *config.RelayerConfi
l1Relayer := &Layer1Relayer{
ctx: ctx,
l1MessageOrm: orm.NewL1Message(db),
l1Block: orm.NewL1Block(db),
l1BlockOrm: orm.NewL1Block(db),
messageSender: messageSender,
l2MessengerABI: bridgeAbi.L2ScrollMessengerABI,
@@ -159,13 +159,13 @@ func (r *Layer1Relayer) processSavedEvent(msg *orm.L1Message) error {
// ProcessGasPriceOracle imports gas price to layer2
func (r *Layer1Relayer) ProcessGasPriceOracle() {
latestBlockHeight, err := r.l1Block.GetLatestL1BlockHeight(r.ctx)
latestBlockHeight, err := r.l1BlockOrm.GetLatestL1BlockHeight(r.ctx)
if err != nil {
log.Warn("Failed to fetch latest L1 block height from db", "err", err)
return
}
blocks, err := r.l1Block.GetL1Blocks(r.ctx, map[string]interface{}{
blocks, err := r.l1BlockOrm.GetL1Blocks(r.ctx, map[string]interface{}{
"number": latestBlockHeight,
})
if err != nil {
@@ -197,7 +197,7 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
return
}
err = r.l1Block.UpdateL1GasOracleStatusAndOracleTxHash(r.ctx, block.Hash, types.GasOracleImporting, hash.String())
err = r.l1BlockOrm.UpdateL1GasOracleStatusAndOracleTxHash(r.ctx, block.Hash, types.GasOracleImporting, hash.String())
if err != nil {
log.Error("UpdateGasOracleStatusAndOracleTxHash failed", "block.Hash", block.Hash, "block.Height", block.Number, "err", err)
return
@@ -232,14 +232,14 @@ func (r *Layer1Relayer) handleConfirmLoop(ctx context.Context) {
case cfm := <-r.gasOracleSender.ConfirmChan():
if !cfm.IsSuccessful {
// @discuss: maybe make it pending again?
err := r.l1Block.UpdateL1GasOracleStatusAndOracleTxHash(r.ctx, cfm.ID, types.GasOracleFailed, cfm.TxHash.String())
err := r.l1BlockOrm.UpdateL1GasOracleStatusAndOracleTxHash(r.ctx, cfm.ID, types.GasOracleFailed, cfm.TxHash.String())
if err != nil {
log.Warn("UpdateL1GasOracleStatusAndOracleTxHash failed", "err", err)
}
log.Warn("transaction confirmed but failed in layer2", "confirmation", cfm)
} else {
// @todo handle db error
err := r.l1Block.UpdateL1GasOracleStatusAndOracleTxHash(r.ctx, cfm.ID, types.GasOracleImported, cfm.TxHash.String())
err := r.l1BlockOrm.UpdateL1GasOracleStatusAndOracleTxHash(r.ctx, cfm.ID, types.GasOracleImported, cfm.TxHash.String())
if err != nil {
log.Warn("UpdateGasOracleStatusAndOracleTxHash failed", "err", err)
}

View File

@@ -128,8 +128,8 @@ func testL1RelayerGasOracleConfirm(t *testing.T) {
l1BlockOrm := orm.NewL1Block(db)
l1Block := []orm.L1Block{
{Hash: "gas-oracle-1", Number: 0, GasOracleStatus: int16(types.GasOraclePending), BlockStatus: int16(types.L1BlockPending)},
{Hash: "gas-oracle-2", Number: 1, GasOracleStatus: int16(types.GasOraclePending), BlockStatus: int16(types.L1BlockPending)},
{Hash: "gas-oracle-1", Number: 0, GasOracleStatus: int16(types.GasOraclePending)},
{Hash: "gas-oracle-2", Number: 1, GasOracleStatus: int16(types.GasOraclePending)},
}
// Insert test data.
assert.NoError(t, l1BlockOrm.InsertL1Blocks(context.Background(), l1Block))

View File

@@ -495,9 +495,7 @@ func (r *Layer2Relayer) ProcessCommittedBatches() {
r.processingFinalization.Store(txID, hash)
default:
log.Error("encounter unreachable case in ProcessCommittedBatches",
"block_status", status,
)
log.Error("encounter unreachable case in ProcessCommittedBatches", "proving status", status)
}
}

View File

@@ -19,9 +19,9 @@ type BatchProposer struct {
ctx context.Context
db *gorm.DB
batchOrm *orm.Batch
chunkOrm *orm.Chunk
l2Block *orm.L2Block
batchOrm *orm.Batch
chunkOrm *orm.Chunk
l2BlockOrm *orm.L2Block
maxChunkNumPerBatch uint64
maxL1CommitGasPerBatch uint64
@@ -37,7 +37,7 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, db *
db: db,
batchOrm: orm.NewBatch(db),
chunkOrm: orm.NewChunk(db),
l2Block: orm.NewL2Block(db),
l2BlockOrm: orm.NewL2Block(db),
maxChunkNumPerBatch: cfg.MaxChunkNumPerBatch,
maxL1CommitGasPerBatch: cfg.MaxL1CommitGasPerBatch,
maxL1CommitCalldataSizePerBatch: cfg.MaxL1CommitCalldataSizePerBatch,
@@ -157,7 +157,7 @@ func (p *BatchProposer) proposeBatchChunks() ([]*orm.Chunk, error) {
func (p *BatchProposer) dbChunksToBridgeChunks(dbChunks []*orm.Chunk) ([]*types.Chunk, error) {
chunks := make([]*types.Chunk, len(dbChunks))
for i, c := range dbChunks {
wrappedBlocks, err := p.l2Block.GetL2BlocksInRange(p.ctx, c.StartBlockNumber, c.EndBlockNumber)
wrappedBlocks, err := p.l2BlockOrm.GetL2BlocksInRange(p.ctx, c.StartBlockNumber, c.EndBlockNumber)
if err != nil {
log.Error("Failed to fetch wrapped blocks",
"start number", c.StartBlockNumber, "end number", c.EndBlockNumber, "error", err)

View File

@@ -153,7 +153,6 @@ func (w *L1WatcherClient) FetchBlockHeader(blockHeight uint64) error {
Hash: block.Hash().String(),
BaseFee: baseFee,
GasOracleStatus: int16(types.GasOraclePending),
BlockStatus: int16(types.L1BlockPending),
})
}

View File

@@ -19,10 +19,6 @@ type L1Block struct {
Hash string `json:"hash" gorm:"column:hash"`
BaseFee uint64 `json:"base_fee" gorm:"column:base_fee"`
// import
BlockStatus int16 `json:"block_status" gorm:"column:block_status;default:1"`
ImportTxHash string `json:"import_tx_hash" gorm:"column:import_tx_hash;default:NULL"`
// oracle
GasOracleStatus int16 `json:"oracle_status" gorm:"column:oracle_status;default:1"`
OracleTxHash string `json:"oracle_tx_hash" gorm:"column:oracle_tx_hash;default:NULL"`

View File

@@ -5,26 +5,6 @@ import (
"fmt"
)
// L1BlockStatus represents current l1 block processing status
type L1BlockStatus int
const (
// L1BlockUndefined : undefined l1 block status
L1BlockUndefined L1BlockStatus = iota
// L1BlockPending represents the l1 block status is pending
L1BlockPending
// L1BlockImporting represents the l1 block status is importing
L1BlockImporting
// L1BlockImported represents the l1 block status is imported
L1BlockImported
// L1BlockFailed represents the l1 block status is failed
L1BlockFailed
)
// GasOracleStatus represents current gas oracle processing status
type GasOracleStatus int

View File

@@ -5,7 +5,7 @@ import (
"runtime/debug"
)
var tag = "v4.0.24"
var tag = "v4.0.25"
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {

View File

@@ -274,7 +274,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### router
@@ -478,6 +478,22 @@ Emitted when the ERC1155 NFT is transfered to recipient in layer 1.
| _tokenId | uint256 | undefined |
| _amount | uint256 | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### OwnershipTransferred
```solidity

View File

@@ -241,7 +241,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### router
@@ -418,6 +418,22 @@ Emitted when the ERC721 NFT is transfered to recipient in layer 1.
| _to | address | undefined |
| _tokenId | uint256 | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### OwnershipTransferred
```solidity

View File

@@ -320,7 +320,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### requestERC20
@@ -496,6 +496,22 @@ Emitted when ETH is withdrawn from L2 to L1 and transfer to recipient.
| amount | uint256 | undefined |
| data | bytes | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### OwnershipTransferred
```solidity

View File

@@ -89,7 +89,7 @@ Initialize the storage of L1ScrollMessenger.
function isL1MessageDropped(bytes32) external view returns (bool)
```
Mappging from L1 message hash to drop status.
Mapping from L1 message hash to drop status.
@@ -225,7 +225,7 @@ function prevReplayIndex(uint256) external view returns (uint256)
Mapping from queue index to previous replay queue index.
*If a message `x` was replayed 3 times with index `q1`, `q2` and `q3`, the value of `prevReplayIndex` and `replayStates` will be `replayStates[hash(x)].lastIndex = q3`, `replayStates[hash(x)].times = 3`, `prevReplayIndex[q3] = q2`, `prevReplayIndex[q2] = q1` and `prevReplayIndex[q1] = x`.*
*If a message `x` was replayed 3 times with index `q1`, `q2` and `q3`, the value of `prevReplayIndex` and `replayStates` will be `replayStates[hash(x)].lastIndex = q3`, `replayStates[hash(x)].times = 3`, `prevReplayIndex[q3] = q2`, `prevReplayIndex[q2] = q1`, `prevReplayIndex[q1] = x` and `prevReplayIndex[x]=nil`.The index `x` that `prevReplayIndex[x]=nil` is used as the termination of the list. Usually we use `0` to represent `nil`, but we cannot distinguish it with the first message with index zero. So a nonzero offset `1` is added to the value of `prevReplayIndex[x]` to avoid such situation.*
#### Parameters
@@ -268,7 +268,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### replayMessage
@@ -473,6 +473,22 @@ Emitted when a cross domain message is failed to relay.
|---|---|---|
| messageHash `indexed` | bytes32 | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### OwnershipTransferred
```solidity

View File

@@ -277,6 +277,22 @@ Emitted when ERC20 token is withdrawn from L2 to L1 and transfer to recipient.
| amount | uint256 | undefined |
| data | bytes | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### RefundERC20
```solidity

View File

@@ -275,6 +275,22 @@ Emitted when ERC20 token is withdrawn from L2 to L1 and transfer to recipient.
| amount | uint256 | undefined |
| data | bytes | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### RefundERC20
```solidity

View File

@@ -219,7 +219,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### router
@@ -422,6 +422,22 @@ Emitted when the ERC1155 NFT is transfered to recipient in layer 2.
| tokenId | uint256 | undefined |
| amount | uint256 | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### OwnershipTransferred
```solidity

View File

@@ -188,7 +188,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### router
@@ -364,6 +364,22 @@ Emitted when the ERC721 NFT is transfered to recipient in layer 2.
| to | address | undefined |
| tokenId | uint256 | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### OwnershipTransferred
```solidity

View File

@@ -214,7 +214,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### setDefaultERC20Gateway
@@ -437,6 +437,22 @@ Emitted when ETH is deposited from L1 to L2 and transfer to recipient.
| amount | uint256 | undefined |
| data | bytes | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### OwnershipTransferred
```solidity

View File

@@ -257,7 +257,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### retryMessageWithProof
@@ -469,6 +469,22 @@ Emitted when a cross domain message is failed to relay.
|---|---|---|
| messageHash `indexed` | bytes32 | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### OwnershipTransferred
```solidity

View File

@@ -244,6 +244,22 @@ Emitted when ERC20 token is deposited from L1 to L2 and transfer to recipient.
| amount | uint256 | undefined |
| data | bytes | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### WithdrawERC20
```solidity

View File

@@ -260,6 +260,22 @@ Emitted when ERC20 token is deposited from L1 to L2 and transfer to recipient.
| amount | uint256 | undefined |
| data | bytes | undefined |
### Initialized
```solidity
event Initialized(uint8 version)
```
#### Parameters
| Name | Type | Description |
|---|---|---|
| version | uint8 | undefined |
### WithdrawERC20
```solidity

View File

@@ -98,7 +98,7 @@ function renounceOwnership() external nonpayable
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.*
*Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.*
### transferOwnership
@@ -127,7 +127,7 @@ function transferOwnership(address newOwner) external nonpayable
event DeployToken(address indexed _l1Token, address indexed _l2Token)
```
Emitted when a l2 token is deployed.

View File

@@ -55,8 +55,8 @@
"typescript": "^4.5.2"
},
"dependencies": {
"@openzeppelin/contracts": "^4.5.0",
"@openzeppelin/contracts-upgradeable": "^4.5.2"
"@openzeppelin/contracts": "^v4.9.2",
"@openzeppelin/contracts-upgradeable": "^v4.9.2"
},
"lint-staged": {
"*.{js,ts}": "npx eslint --cache --fix",

View File

@@ -21,6 +21,13 @@ import {IMessageDropCallback} from "../../libraries/callbacks/IMessageDropCallba
abstract contract L1ERC20Gateway is IL1ERC20Gateway, IMessageDropCallback, ScrollGatewayBase {
using SafeERC20 for IERC20;
/*************
* Variables *
*************/
/// @dev The storage slots for future usage.
uint256[50] private __gap;
/*****************************
* Public Mutating Functions *
*****************************/

View File

@@ -8,18 +8,21 @@ interface IScrollChain {
**********/
/// @notice Emitted when a new batch is committed.
/// @param batchIndex The index of the batch.
/// @param batchHash The hash of the batch.
event CommitBatch(bytes32 indexed batchHash);
event CommitBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);
/// @notice revert a pending batch.
/// @param batchIndex The index of the batch.
/// @param batchHash The hash of the batch
event RevertBatch(bytes32 indexed batchHash);
event RevertBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);
/// @notice Emitted when a batch is finalized.
/// @param batchIndex The index of the batch.
/// @param batchHash The hash of the batch
/// @param stateRoot The state root in layer 2 after this batch.
/// @param withdrawRoot The merkle root in layer2 after this batch.
event FinalizeBatch(bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot);
event FinalizeBatch(uint256 indexed batchIndex, bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot);
/*************************
* Public View Functions *

View File

@@ -153,8 +153,8 @@ contract ScrollChain is OwnableUpgradeable, IScrollChain {
committedBatches[0] = _batchHash;
finalizedStateRoots[0] = _stateRoot;
emit CommitBatch(_batchHash);
emit FinalizeBatch(_batchHash, _stateRoot, bytes32(0));
emit CommitBatch(0, _batchHash);
emit FinalizeBatch(0, _batchHash, _stateRoot, bytes32(0));
}
/// @inheritdoc IScrollChain
@@ -248,10 +248,12 @@ contract ScrollChain is OwnableUpgradeable, IScrollChain {
bytes32 _batchHash = BatchHeaderV0Codec.computeBatchHash(batchPtr, 89 + _skippedL1MessageBitmap.length);
committedBatches[_batchIndex] = _batchHash;
emit CommitBatch(_batchHash);
emit CommitBatch(_batchIndex, _batchHash);
}
/// @inheritdoc IScrollChain
/// @dev If the owner want to revert a sequence of batches by sending multiple transactions,
/// make sure to revert recent batches first.
function revertBatch(bytes calldata _batchHeader, uint256 _count) external onlyOwner {
require(_count > 0, "count must be nonzero");
@@ -260,19 +262,21 @@ contract ScrollChain is OwnableUpgradeable, IScrollChain {
// check batch hash
uint256 _batchIndex = BatchHeaderV0Codec.batchIndex(memPtr);
require(committedBatches[_batchIndex] == _batchHash, "incorrect batch hash");
// make sure no gap is left when reverting from the ending to the beginning.
require(committedBatches[_batchIndex + _count] == bytes32(0), "reverting must start from the ending");
// check finalization
require(_batchIndex > lastFinalizedBatchIndex, "can only revert unfinalized batch");
while (_count > 0) {
emit RevertBatch(_batchIndex, _batchHash);
committedBatches[_batchIndex] = bytes32(0);
unchecked {
_batchIndex += 1;
_count -= 1;
}
emit RevertBatch(_batchHash);
_batchHash = committedBatches[_batchIndex];
if (_batchHash == bytes32(0)) break;
}
@@ -342,7 +346,7 @@ contract ScrollChain is OwnableUpgradeable, IScrollChain {
}
}
emit FinalizeBatch(_batchHash, _postStateRoot, _withdrawRoot);
emit FinalizeBatch(_batchIndex, _batchHash, _postStateRoot, _withdrawRoot);
}
/************************

View File

@@ -101,16 +101,16 @@ contract L2ScrollMessenger is ScrollMessengerBase, PausableUpgradeable, IL2Scrol
require(_expectedStateRoot != bytes32(0), "Block is not imported");
bytes32 _storageKey;
// `mapping(bytes32 => bool) public isL1MessageSent` is the 155-th slot of contract `L1ScrollMessenger`.
// `mapping(bytes32 => bool) public isL1MessageSent` is the 201-th slot of contract `L1ScrollMessenger`.
// + 1 from `Initializable`
// + 50 from `OwnableUpgradeable`
// + 50 from `ContextUpgradeable`
// + 4 from `ScrollMessengerBase`
// + 50 from `PausableUpgradeable`
// + 50 from `OwnableUpgradeable`
// + 50 from `ScrollMessengerBase`
// + 1-st in `L1ScrollMessenger`
assembly {
mstore(0x00, _msgHash)
mstore(0x20, 155)
mstore(0x20, 201)
_storageKey := keccak256(0x00, 0x40)
}
@@ -138,16 +138,16 @@ contract L2ScrollMessenger is ScrollMessengerBase, PausableUpgradeable, IL2Scrol
require(_expectedStateRoot != bytes32(0), "Block not imported");
bytes32 _storageKey;
// `mapping(bytes32 => bool) public isL2MessageExecuted` is the 156-th slot of contract `L1ScrollMessenger`.
// `mapping(bytes32 => bool) public isL2MessageExecuted` is the 202-th slot of contract `L1ScrollMessenger`.
// + 1 from `Initializable`
// + 50 from `OwnableUpgradeable`
// + 50 from `ContextUpgradeable`
// + 4 from `ScrollMessengerBase`
// + 50 from `PausableUpgradeable`
// + 50 from `OwnableUpgradeable`
// + 50 from `ScrollMessengerBase`
// + 2-nd in `L1ScrollMessenger`
assembly {
mstore(0x00, _msgHash)
mstore(0x20, 156)
mstore(0x20, 202)
_storageKey := keccak256(0x00, 0x40)
}

View File

@@ -7,6 +7,13 @@ import {IL2ERC20Gateway} from "./IL2ERC20Gateway.sol";
// solhint-disable no-empty-blocks
abstract contract L2ERC20Gateway is IL2ERC20Gateway {
/*************
* Variables *
*************/
/// @dev The storage slots for future usage.
uint256[50] private __gap;
/*****************************
* Public Mutating Functions *
*****************************/

View File

@@ -28,10 +28,17 @@ pragma solidity ^0.8.0;
import {IL2ScrollMessenger} from "../L2/IL2ScrollMessenger.sol";
import {OwnableBase} from "./common/OwnableBase.sol";
// solhint-disable no-empty-blocks
// solhint-disable reason-string
/// @title FeeVault
/// @notice The FeeVault contract contains the basic logic for the various different vault contracts
/// used to hold fee revenue generated by the L2 system.
abstract contract FeeVault is OwnableBase {
/**********
* Events *
**********/
/// @notice Emits each time that a withdrawal occurs.
///
/// @param value Amount that was withdrawn (in wei).
@@ -39,6 +46,25 @@ abstract contract FeeVault is OwnableBase {
/// @param from Address that triggered the withdrawal.
event Withdrawal(uint256 value, address to, address from);
/// @notice Emits each time the owner updates the address of `messenger`.
/// @param oldMessenger The address of old messenger.
/// @param newMessenger The address of new messenger.
event UpdateMessenger(address indexed oldMessenger, address indexed newMessenger);
/// @notice Emits each time the owner updates the address of `recipient`.
/// @param oldRecipient The address of old recipient.
/// @param newRecipient The address of new recipient.
event UpdateRecipient(address indexed oldRecipient, address indexed newRecipient);
/// @notice Emits each time the owner updates the value of `minWithdrawAmount`.
/// @param oldMinWithdrawAmount The value of old `minWithdrawAmount`.
/// @param newMinWithdrawAmount The value of new `minWithdrawAmount`.
event UpdateMinWithdrawAmount(uint256 oldMinWithdrawAmount, uint256 newMinWithdrawAmount);
/*************
* Variables *
*************/
/// @notice Minimum balance before a withdrawal can be triggered.
uint256 public minWithdrawAmount;
@@ -51,6 +77,10 @@ abstract contract FeeVault is OwnableBase {
/// @notice Total amount of wei processed by the contract.
uint256 public totalProcessed;
/***************
* Constructor *
***************/
/// @param _owner The owner of the contract.
/// @param _recipient Wallet that will receive the fees on L1.
/// @param _minWithdrawalAmount Minimum balance before a withdrawal can be triggered.
@@ -65,6 +95,10 @@ abstract contract FeeVault is OwnableBase {
recipient = _recipient;
}
/*****************************
* Public Mutating Functions *
*****************************/
/// @notice Allow the contract to receive ETH.
receive() external payable {}
@@ -92,21 +126,34 @@ abstract contract FeeVault is OwnableBase {
);
}
/************************
* Restricted Functions *
************************/
/// @notice Update the address of messenger.
/// @param _messenger The address of messenger to update.
function updateMessenger(address _messenger) external onlyOwner {
messenger = _messenger;
/// @param _newMessenger The address of messenger to update.
function updateMessenger(address _newMessenger) external onlyOwner {
address _oldMessenger = messenger;
messenger = _newMessenger;
emit UpdateMessenger(_oldMessenger, _newMessenger);
}
/// @notice Update the address of recipient.
/// @param _recipient The address of recipient to update.
function updateRecipient(address _recipient) external onlyOwner {
recipient = _recipient;
/// @param _newRecipient The address of recipient to update.
function updateRecipient(address _newRecipient) external onlyOwner {
address _oldRecipient = recipient;
recipient = _newRecipient;
emit UpdateRecipient(_oldRecipient, _newRecipient);
}
/// @notice Update the minimum withdraw amount.
/// @param _minWithdrawAmount The minimum withdraw amount to update.
function updateMinWithdrawAmount(uint256 _minWithdrawAmount) external onlyOwner {
minWithdrawAmount = _minWithdrawAmount;
/// @param _newMinWithdrawAmount The minimum withdraw amount to update.
function updateMinWithdrawAmount(uint256 _newMinWithdrawAmount) external onlyOwner {
uint256 _oldMinWithdrawAmount = minWithdrawAmount;
minWithdrawAmount = _newMinWithdrawAmount;
emit UpdateMinWithdrawAmount(_oldMinWithdrawAmount, _newMinWithdrawAmount);
}
}

View File

@@ -7,6 +7,8 @@ import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Own
import {ScrollConstants} from "./constants/ScrollConstants.sol";
import {IScrollMessenger} from "./IScrollMessenger.sol";
// solhint-disable var-name-mixedcase
abstract contract ScrollMessengerBase is OwnableUpgradeable, IScrollMessenger {
/**********
* Events *
@@ -42,6 +44,9 @@ abstract contract ScrollMessengerBase is OwnableUpgradeable, IScrollMessenger {
/// @dev The status of for non-reentrant check.
uint256 private _lock_status;
/// @dev The storage slots for future usage.
uint256[46] private __gap;
/**********************
* Function Modifiers *
**********************/
@@ -82,8 +87,8 @@ abstract contract ScrollMessengerBase is OwnableUpgradeable, IScrollMessenger {
feeVault = _feeVault;
}
// allow others to send ether to messenger
receive() external payable {}
// make sure only owner can send ether to messenger to avoid possible user fund loss.
receive() external payable onlyOwner {}
/************************
* Restricted Functions *

View File

@@ -32,6 +32,9 @@ abstract contract ScrollGatewayBase is IScrollGateway {
/// @dev The status of for non-reentrant check.
uint256 private _status;
/// @dev The storage slots for future usage.
uint256[46] private __gap;
/**********************
* Function Modifiers *
**********************/

View File

@@ -3,6 +3,9 @@
pragma solidity ^0.8.0;
interface IScrollStandardERC20Factory {
/// @notice Emitted when a l2 token is deployed.
/// @param _l1Token The address of the l1 token.
/// @param _l2Token The address of the l2 token.
event DeployToken(address indexed _l1Token, address indexed _l2Token);
/// @notice Compute the corresponding l2 token address given l1 token address.

View File

@@ -35,7 +35,11 @@ contract ScrollStandardERC20Factory is Ownable, IScrollStandardERC20Factory {
function deployL2Token(address _gateway, address _l1Token) external onlyOwner returns (address) {
bytes32 _salt = _getSalt(_gateway, _l1Token);
return Clones.cloneDeterministic(implementation, _salt);
address _l2Token = Clones.cloneDeterministic(implementation, _salt);
emit DeployToken(_l1Token, _l2Token);
return _l2Token;
}
function _getSalt(address _gateway, address _l1Token) internal pure returns (bytes32) {

View File

@@ -19,8 +19,9 @@ contract ScrollChainTest is DSTestPlus {
event UpdateVerifier(address oldVerifier, address newVerifier);
event UpdateMaxNumL2TxInChunk(uint256 oldMaxNumL2TxInChunk, uint256 newMaxNumL2TxInChunk);
event CommitBatch(bytes32 indexed batchHash);
event FinalizeBatch(bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot);
event CommitBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);
event FinalizeBatch(uint256 indexed batchIndex, bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot);
event RevertBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);
ScrollChain private rollup;
L1MessageQueue internal messageQueue;
@@ -277,12 +278,16 @@ contract ScrollChainTest is DSTestPlus {
chunks = new bytes[](1);
chunks[0] = chunk0;
bitmap = new bytes(32);
hevm.expectEmit(true, true, false, true);
emit CommitBatch(1, bytes32(0x00847173b29b238cf319cde79512b7c213e5a8b4138daa7051914c4592b6dfc7));
rollup.commitBatch(0, batchHeader0, chunks, bitmap);
assertBoolEq(rollup.isBatchFinalized(1), false);
bytes32 batchHash1 = rollup.committedBatches(1);
assertEq(batchHash1, bytes32(0x00847173b29b238cf319cde79512b7c213e5a8b4138daa7051914c4592b6dfc7));
// finalize batch1
hevm.expectEmit(true, true, false, true);
emit FinalizeBatch(1, batchHash1, bytes32(uint256(2)), bytes32(uint256(3)));
rollup.finalizeBatchWithProof(
batchHeader1,
bytes32(uint256(1)),
@@ -395,12 +400,16 @@ contract ScrollChainTest is DSTestPlus {
mstore(add(bitmap, add(0x20, 32)), 170) // bitmap1
}
hevm.expectEmit(true, true, false, true);
emit CommitBatch(2, bytes32(0x2231cf185a5c07931584f970738b4cd2ae4fb39e2d90853b26746c7616ea71b9));
rollup.commitBatch(0, batchHeader1, chunks, bitmap);
assertBoolEq(rollup.isBatchFinalized(2), false);
bytes32 batchHash2 = rollup.committedBatches(2);
assertEq(batchHash2, bytes32(0x2231cf185a5c07931584f970738b4cd2ae4fb39e2d90853b26746c7616ea71b9));
// verify committed batch correctly
hevm.expectEmit(true, true, false, true);
emit FinalizeBatch(2, batchHash2, bytes32(uint256(4)), bytes32(uint256(5)));
rollup.finalizeBatchWithProof(
batchHeader2,
bytes32(uint256(2)),
@@ -485,11 +494,21 @@ contract ScrollChainTest is DSTestPlus {
rollup.revertBatch(batchHeader1, 1);
batchHeader1[0] = bytes1(uint8(0)); // change back
// revert middle batch, revert
hevm.expectRevert("reverting must start from the ending");
rollup.revertBatch(batchHeader1, 1);
// can only revert unfinalized batch, revert
hevm.expectRevert("can only revert unfinalized batch");
rollup.revertBatch(batchHeader0, 1);
rollup.revertBatch(batchHeader0, 3);
// succeed to revert next two pending batches.
hevm.expectEmit(true, true, false, true);
emit RevertBatch(1, rollup.committedBatches(1));
hevm.expectEmit(true, true, false, true);
emit RevertBatch(2, rollup.committedBatches(2));
assertGt(uint256(rollup.committedBatches(1)), 0);
assertGt(uint256(rollup.committedBatches(2)), 0);
rollup.revertBatch(batchHeader1, 2);

View File

@@ -652,15 +652,15 @@
"@types/sinon-chai" "^3.2.3"
"@types/web3" "1.0.19"
"@openzeppelin/contracts-upgradeable@^4.5.2":
version "4.5.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.5.2.tgz#90d9e47bacfd8693bfad0ac8a394645575528d05"
integrity sha512-xgWZYaPlrEOQo3cBj97Ufiuv79SPd8Brh4GcFYhPgb6WvAq4ppz8dWKL6h+jLAK01rUqMRp/TS9AdXgAeNvCLA==
"@openzeppelin/contracts-upgradeable@^v4.9.2":
version "4.9.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.2.tgz#a817c75688f8daede420052fbcb34e52482e769e"
integrity sha512-siviV3PZV/fHfPaoIC51rf1Jb6iElkYWnNYZ0leO23/ukXuvOyoC/ahy8jqiV7g+++9Nuo3n/rk5ajSN/+d/Sg==
"@openzeppelin/contracts@^4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.5.0.tgz#3fd75d57de172b3743cdfc1206883f56430409cc"
integrity sha512-fdkzKPYMjrRiPK6K4y64e6GzULR7R7RwxSigHS8DDp7aWDeoReqsQI+cxHV1UuhAqX69L1lAaWDxenfP+xiqzA==
"@openzeppelin/contracts@^v4.9.2":
version "4.9.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.2.tgz#1cb2d5e4d3360141a17dbc45094a8cad6aac16c1"
integrity sha512-mO+y6JaqXjWeMh9glYVzVu8HYPGknAAnWyxTRhGeckOruyXQMNnlcW6w/Dx9ftLeIQk6N+ZJFuVmTwF7lEIFrg==
"@primitivefi/hardhat-dodoc@^0.2.3":
version "0.2.3"

View File

@@ -8,10 +8,6 @@ create table l1_block
hash VARCHAR NOT NULL,
base_fee BIGINT NOT NULL,
-- import
block_status SMALLINT NOT NULL DEFAULT 1,
import_tx_hash VARCHAR DEFAULT NULL,
-- oracle
oracle_status SMALLINT NOT NULL DEFAULT 1,
oracle_tx_hash VARCHAR DEFAULT NULL,
@@ -22,9 +18,6 @@ create table l1_block
deleted_at TIMESTAMP(0) DEFAULT NULL
);
comment
on column l1_block.block_status is 'undefined, pending, importing, imported, failed';
comment
on column l1_block.oracle_status is 'undefined, pending, importing, imported, failed';

View File

@@ -42,6 +42,7 @@ github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VY
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc=
github.com/ClickHouse/clickhouse-go/v2 v2.2.0 h1:dj00TDKY+xwuTJdbpspCSmTLFyWzRJerTHwaBxut1C0=