Skip to content

Commit

Permalink
Merge branch 'zkevm/v0.6.4' into zjg/fork9
Browse files Browse the repository at this point in the history
  • Loading branch information
zjg555543 committed Mar 25, 2024
2 parents c70ad10 + df539db commit cfc60e1
Show file tree
Hide file tree
Showing 65 changed files with 2,462 additions and 267 deletions.
18 changes: 12 additions & 6 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (

ethTxManagerOwner = "aggregator"
monitoredIDFormat = "proof-from-%v-to-%v"

forkId9 = uint64(9)
)

type finalProofMsg struct {
Expand Down Expand Up @@ -182,8 +184,8 @@ func (a *Aggregator) Channel(stream prover.AggregatorService_ChannelServer) erro
log.Info("Establishing stream connection with prover")

// Check if prover supports the required Fork ID
if !prover.SupportsForkID(a.cfg.ForkId) {
err := fmt.Errorf(fmt.Sprintf("prover does not support required fork ID %d", a.cfg.ForkId))
if !prover.SupportsForkID(forkId9) {
err := errors.New("prover does not support required fork ID")
log.Warn(FirstToUpper(err.Error()))
return err
}
Expand Down Expand Up @@ -1032,9 +1034,13 @@ func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.
for _, l2blockRaw := range batchRawData.Blocks {
_, contained := l1InfoTreeData[l2blockRaw.IndexL1InfoTree]
if !contained && l2blockRaw.IndexL1InfoTree != 0 {
l1InfoTreeExitRootStorageEntry, err := a.State.GetL1InfoRootLeafByIndex(ctx, l2blockRaw.IndexL1InfoTree, nil)
if err != nil {
return nil, err
l1InfoTreeExitRootStorageEntry := state.L1InfoTreeExitRootStorageEntry{}
l1InfoTreeExitRootStorageEntry.Timestamp = time.Unix(0, 0)
if l2blockRaw.IndexL1InfoTree <= leaves[len(leaves)-1].L1InfoTreeIndex {
l1InfoTreeExitRootStorageEntry, err = a.State.GetL1InfoRootLeafByIndex(ctx, l2blockRaw.IndexL1InfoTree, nil)
if err != nil {
return nil, err
}
}

// Calculate smt proof
Expand Down Expand Up @@ -1087,7 +1093,7 @@ func (a *Aggregator) buildInputProver(ctx context.Context, batchToVerify *state.
OldAccInputHash: previousBatch.AccInputHash.Bytes(),
OldBatchNum: previousBatch.BatchNumber,
ChainId: a.cfg.ChainID,
ForkId: a.cfg.ForkId,
ForkId: forkId9,
BatchL2Data: batchToVerify.BatchL2Data,
L1InfoRoot: l1InfoRoot.Bytes(),
TimestampLimit: uint64(batchToVerify.Timestamp.Unix()),
Expand Down
1 change: 0 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManagerS
log.Info("trustedSequencerURL ", trustedSequencerURL)
}
zkEVMClient := client.NewClient(trustedSequencerURL)

etherManForL1 := []syncinterfaces.EthermanFullInterface{}
// If synchronizer are using sequential mode, we only need one etherman client
if cfg.Synchronizer.L1SynchronizationMode == synchronizer.ParallelMode {
Expand Down
2 changes: 2 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ SyncInterval = "1s"
SyncChunkSize = 100
TrustedSequencerURL = "" # If it is empty or not specified, then the value is read from the smc
L1SynchronizationMode = "sequential"
L1SyncCheckL2BlockHash = true
L1SyncCheckL2BlockNumberhModulus = 30
[Synchronizer.L1ParallelSynchronization]
MaxClients = 10
MaxPendingNoProcessedBlocks = 25
Expand Down
2 changes: 1 addition & 1 deletion config/environments/cardona/node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Port = 8545
ReadTimeout = "60s"
WriteTimeout = "60s"
MaxRequestsPerIPAndSecond = 5000
SequencerNodeURI = "https://rpc.devnet.zkevm-rpc.com"
SequencerNodeURI = ""
EnableL2SuggestedGasPricePolling = false
[RPC.WebSockets]
Enabled = true
Expand Down
2 changes: 1 addition & 1 deletion config/environments/mainnet/node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Port = 8545
ReadTimeout = "60s"
WriteTimeout = "60s"
MaxRequestsPerIPAndSecond = 5000
SequencerNodeURI = "https://zkevm-rpc.com"
SequencerNodeURI = ""
EnableL2SuggestedGasPricePolling = false
[RPC.WebSockets]
Enabled = true
Expand Down
2 changes: 1 addition & 1 deletion config/environments/testnet/node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Port = 8545
ReadTimeout = "60s"
WriteTimeout = "60s"
MaxRequestsPerIPAndSecond = 5000
SequencerNodeURI = "https://rpc.public.zkevm-test.net/"
SequencerNodeURI = ""
EnableL2SuggestedGasPricePolling = false
[RPC.WebSockets]
Enabled = true
Expand Down
9 changes: 9 additions & 0 deletions db/migrations/state/0017.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +migrate Up
ALTER TABLE state.receipt
ADD COLUMN IF NOT EXISTS im_state_root BYTEA;

UPDATE state.receipt SET im_state_root = post_state WHERE block_num >= (SELECT MIN(block_num) FROM state.l2block WHERE batch_num >= (SELECT from_batch_num FROM state.fork_id WHERE fork_id = 7));

-- +migrate Down
ALTER TABLE state.receipt
DROP COLUMN IF EXISTS im_state_root;
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ services:
xlayer-prover:
container_name: xlayer-prover
restart: unless-stopped
image: hermeznetwork/zkevm-prover:v5.0.3
image: hermeznetwork/zkevm-prover:v6.0.0
depends_on:
xlayer-state-db:
condition: service_healthy
Expand Down
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

83 changes: 57 additions & 26 deletions docs/config-file/node-config-doc.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,16 @@
"description": "TrustedSequencerURL is the rpc url to connect and sync the trusted state",
"default": ""
},
"L1SyncCheckL2BlockHash": {
"type": "boolean",
"description": "L1SyncCheckL2BlockHash if is true when a batch is closed is force to check L2Block hash against trustedNode (only apply for permissionless)",
"default": true
},
"L1SyncCheckL2BlockNumberhModulus": {
"type": "integer",
"description": "L1SyncCheckL2BlockNumberhModulus is the modulus used to choose the l2block to check\na modules 5, for instance, means check all l2block multiples of 5 (10,15,20,...)",
"default": 30
},
"L1SynchronizationMode": {
"type": "string",
"enum": [
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/endpoints_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3311,7 +3311,7 @@ func TestGetTransactionReceipt(t *testing.T) {
receipt.Bloom = ethTypes.CreateBloom(ethTypes.Receipts{receipt})

rpcReceipt := types.Receipt{
Root: stateRoot,
Root: &stateRoot,
CumulativeGasUsed: types.ArgUint64(receipt.CumulativeGasUsed),
LogsBloom: receipt.Bloom,
Logs: receipt.Logs,
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/endpoints_zkevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,7 @@ func TestGetTransactionReceiptByL2Hash(t *testing.T) {
receipt.Bloom = ethTypes.CreateBloom(ethTypes.Receipts{receipt})

rpcReceipt := types.Receipt{
Root: stateRoot,
Root: &stateRoot,
CumulativeGasUsed: types.ArgUint64(receipt.CumulativeGasUsed),
LogsBloom: receipt.Bloom,
Logs: receipt.Logs,
Expand Down
8 changes: 6 additions & 2 deletions jsonrpc/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func NewTransaction(

// Receipt structure
type Receipt struct {
Root common.Hash `json:"root"`
Root *common.Hash `json:"root,omitempty"`
CumulativeGasUsed ArgUint64 `json:"cumulativeGasUsed"`
LogsBloom types.Bloom `json:"logsBloom"`
Logs []*types.Log `json:"logs"`
Expand Down Expand Up @@ -643,7 +643,6 @@ func NewReceipt(tx types.Transaction, r *types.Receipt, l2Hash *common.Hash) (Re
return Receipt{}, err
}
receipt := Receipt{
Root: common.BytesToHash(r.PostState),
CumulativeGasUsed: ArgUint64(r.CumulativeGasUsed),
LogsBloom: r.Bloom,
Logs: logs,
Expand All @@ -659,6 +658,11 @@ func NewReceipt(tx types.Transaction, r *types.Receipt, l2Hash *common.Hash) (Re
Type: ArgUint64(r.Type),
TxL2Hash: l2Hash,
}
if len(r.PostState) > 0 {
root := common.BytesToHash(r.PostState)
receipt.Root = &root
}

if r.EffectiveGasPrice != nil {
egp := ArgBig(*r.EffectiveGasPrice)
receipt.EffectiveGasPrice = &egp
Expand Down
17 changes: 7 additions & 10 deletions l1infotree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,13 @@ func (mt *L1InfoTree) ComputeMerkleProof(gerIndex uint32, leaves [][32]byte) ([]
if len(leaves)%2 == 1 {
leaves = append(leaves, mt.zeroHashes[h])
}
if index%2 == 1 { //If it is odd
siblings = append(siblings, leaves[index-1])
} else { // It is even
if len(leaves) > 1 {
if index >= uint32(len(leaves)) {
// siblings = append(siblings, mt.zeroHashes[h])
siblings = append(siblings, leaves[index-1])
} else {
siblings = append(siblings, leaves[index+1])
}
if index >= uint32(len(leaves)) {
siblings = append(siblings, mt.zeroHashes[h])
} else {
if index%2 == 1 { //If it is odd
siblings = append(siblings, leaves[index-1])
} else { // It is even
siblings = append(siblings, leaves[index+1])
}
}
var (
Expand Down
2 changes: 2 additions & 0 deletions proto/src/proto/executor/v1/executor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -872,4 +872,6 @@ enum ExecutorError {
EXECUTOR_ERROR_INVALID_DATA_STREAM = 115;
// EXECUTOR_ERROR_INVALID_UPDATE_MERKLE_TREE indicates that the provided update merkle tree is invalid, e.g. because the executor is configured not to write to database
EXECUTOR_ERROR_INVALID_UPDATE_MERKLE_TREE = 116;
// EXECUTOR_ERROR_SM_MAIN_INVALID_TX_STATUS_ERROR indicates that a TX has an invalid status-error combination
EXECUTOR_ERROR_SM_MAIN_INVALID_TX_STATUS_ERROR = 117;
}
35 changes: 31 additions & 4 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,19 @@ func (f *finalizer) updateFlushIDs(newPendingFlushID, newStoredFlushID uint64) {

func (f *finalizer) checkL1InfoTreeUpdate(ctx context.Context) {
firstL1InfoRootUpdate := true
skipFirstSleep := true

for {
if skipFirstSleep {
skipFirstSleep = false
} else {
time.Sleep(f.cfg.L1InfoTreeCheckInterval.Duration)
}

lastL1BlockNumber, err := f.etherman.GetLatestBlockNumber(ctx)
if err != nil {
log.Errorf("error getting latest L1 block number, error: %v", err)
continue
}

maxBlockNumber := uint64(0)
Expand All @@ -250,9 +258,30 @@ func (f *finalizer) checkL1InfoTreeUpdate(ctx context.Context) {
}

if firstL1InfoRootUpdate || l1InfoRoot.L1InfoTreeIndex > f.lastL1InfoTree.L1InfoTreeIndex {
firstL1InfoRootUpdate = false
log.Infof("received new L1InfoRoot, l1InfoTreeIndex: %d, l1InfoTreeRoot: %s, l1Block: %d",
l1InfoRoot.L1InfoTreeIndex, l1InfoRoot.L1InfoTreeRoot, l1InfoRoot.BlockNumber)

log.Debugf("received new L1InfoRoot. L1InfoTreeIndex: %d", l1InfoRoot.L1InfoTreeIndex)
// Sanity check l1BlockState (l1InfoRoot.BlockNumber) blockhash matches blockhash on ethereum. We skip it if l1InfoRoot.BlockNumber == 0 (empty tree)
if l1InfoRoot.BlockNumber > 0 {
l1BlockState, err := f.stateIntf.GetBlockByNumber(ctx, l1InfoRoot.BlockNumber, nil)
if err != nil {
log.Errorf("error getting L1 block %d from the state, error: %v", l1InfoRoot.BlockNumber, err)
continue
}

l1BlockEth, err := f.etherman.HeaderByNumber(ctx, new(big.Int).SetUint64(l1InfoRoot.BlockNumber))
if err != nil {
log.Errorf("error getting L1 block %d from ethereum, error: %v", l1InfoRoot.BlockNumber, err)
continue
}
if l1BlockState.BlockHash != l1BlockEth.Hash() {
log.Warnf("skipping use of l1InfoTreeIndex %d, L1 block %d blockhash %s doesn't match blockhash on ethereum %s (L1 reorg?)",
l1InfoRoot.L1InfoTreeIndex, l1InfoRoot.BlockNumber, l1BlockState.BlockHash, l1BlockEth.Hash())
continue
}
}

firstL1InfoRootUpdate = false

f.lastL1InfoTreeMux.Lock()
f.lastL1InfoTree = l1InfoRoot
Expand All @@ -265,8 +294,6 @@ func (f *finalizer) checkL1InfoTreeUpdate(ctx context.Context) {
f.lastL1InfoTreeCond.L.Unlock()
}
}

time.Sleep(f.cfg.L1InfoTreeCheckInterval.Duration)
}
}

Expand Down
2 changes: 2 additions & 0 deletions sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/jackc/pgx/v4"
)

Expand All @@ -34,6 +35,7 @@ type etherman interface {
TrustedSequencer() (common.Address, error)
GetLatestBatchNumber() (uint64, error)
GetLatestBlockNumber(ctx context.Context) (uint64, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
}

// stateInterface gathers the methods required to interact with the state.
Expand Down
33 changes: 33 additions & 0 deletions sequencer/mock_etherman.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions state/batchV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func (s *State) sendBatchRequestToExecutorV2(ctx context.Context, batchRequest *
log.Warn(batchResponseToString)
s.eventLog.LogExecutorErrorV2(ctx, batchResponse.Error, batchRequest)
} else if batchResponse.ErrorRom != executor.RomError_ROM_ERROR_NO_ERROR && executor.IsROMOutOfCountersError(batchResponse.ErrorRom) {
err = executor.RomErr(batchResponse.ErrorRom)
log.Warnf("executor batch %d response, ROM OOC, error: %v", newBatchNum, err)
log.Warn(batchResponseToString)
} else if batchResponse.ErrorRom != executor.RomError_ROM_ERROR_NO_ERROR {
Expand Down
1 change: 1 addition & 0 deletions state/convertersV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (s *State) convertToProcessTransactionResponseV2(responses []*executor.Proc
result.ReturnValue = response.ReturnValue
result.GasLeft = response.GasLeft
result.GasUsed = response.GasUsed
result.CumulativeGasUsed = response.CumulativeGasUsed
result.GasRefunded = response.GasRefunded
result.RomError = executor.RomErr(response.Error)
result.CreateAddress = common.HexToAddress(response.CreateAddress)
Expand Down
6 changes: 6 additions & 0 deletions state/datastream.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (b DSL2BlockStart) Decode(data []byte) DSL2BlockStart {
// DSL2Transaction represents a data stream L2 transaction
type DSL2Transaction struct {
L2BlockNumber uint64 // Not included in the encoded data
ImStateRoot common.Hash // Not included in the encoded data
EffectiveGasPricePercentage uint8 // 1 byte
IsValid uint8 // 1 byte
StateRoot common.Hash // 32 bytes
Expand Down Expand Up @@ -553,6 +554,9 @@ func GenerateDataStreamerFile(ctx context.Context, streamServer *datastreamer.St
}

for _, tx := range l2Block.Txs {
// < ETROG => IM State root is retrieved from the system SC (using cache is available)
// = ETROG => IM State root is retrieved from the receipt.post_state => Do nothing
// > ETROG => IM State root is retrieved from the receipt.im_state_root
if l2Block.ForkID < FORKID_ETROG {
// Populate intermediate state root with information from the system SC (or cache if available)
if imStateRoots == nil || (*imStateRoots)[blockStart.L2BlockNumber] == nil {
Expand All @@ -565,6 +569,8 @@ func GenerateDataStreamerFile(ctx context.Context, streamServer *datastreamer.St
} else {
tx.StateRoot = common.BytesToHash((*imStateRoots)[blockStart.L2BlockNumber])
}
} else if l2Block.ForkID > FORKID_ETROG {
tx.StateRoot = tx.ImStateRoot
}

_, err = streamServer.AddStreamEntry(EntryTypeL2Tx, tx.Encode())
Expand Down
2 changes: 2 additions & 0 deletions state/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
FORKID_ETROG = 7
// FORKID_ELDERBERRY is the fork id 8
FORKID_ELDERBERRY = 8
// FORKID_9 is the fork id 9
FORKID_9 = 9
)

// ForkIDInterval is a fork id interval
Expand Down
2 changes: 1 addition & 1 deletion state/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (s *State) SetGenesis(ctx context.Context, block Block, genesis Genesis, m
storeTxsEGPData := []StoreTxEGPData{}
txsL2Hash := []common.Hash{}

err = s.AddL2Block(ctx, batch.BatchNumber, l2Block, receipts, txsL2Hash, storeTxsEGPData, dbTx)
err = s.AddL2Block(ctx, batch.BatchNumber, l2Block, receipts, txsL2Hash, storeTxsEGPData, []common.Hash{}, dbTx)
if err != nil {
return common.Hash{}, err
}
Expand Down
Loading

0 comments on commit cfc60e1

Please sign in to comment.