Skip to content

Commit

Permalink
add block validation logic to produceblock
Browse files Browse the repository at this point in the history
  • Loading branch information
nomaxg committed Nov 27, 2023
1 parent 4c67886 commit 883b5fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
50 changes: 25 additions & 25 deletions arbos/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,32 @@ func ProduceBlock(
}

hooks := NoopSequencingHooks()

// Espresso-specific validation
// TODO test: https://github.com/EspressoSystems/espresso-sequencer/issues/772
if chainConfig.Espresso {
jst := message.Header.BlockJustification
if jst == nil {
return nil, nil, errors.New("batch missing espresso justification")

}
hotshotHeader := jst.Header
if *lastHotShotCommitment != hotshotHeader.Commit() {
return nil, nil, errors.New("invalid hotshot header")
}
var roots = []*espresso.NmtRoot{&hotshotHeader.TransactionsRoot}
var proofs = []*espresso.NmtProof{&message.Header.BlockJustification.Proof}
// If the validation function below were not mocked, we would need to serialize the transactions
// in the batch here. To avoid the unnecessary overhead, we provide an empty array instead.
var txs []espresso.Bytes
err := espresso.ValidateBatchTransactions(chainConfig.ChainID.Uint64(), roots, proofs, txs)
if err != nil {
return nil, nil, errors.New("failed to validate namespace proof)")
}
}

return ProduceBlockAdvanced(
message.Header, txes, delayedMessagesRead, lastBlockHeader, lastHotShotCommitment, statedb, chainContext, chainConfig, hooks,
message.Header, txes, delayedMessagesRead, lastBlockHeader, statedb, chainContext, chainConfig, hooks,
)
}

Expand All @@ -170,7 +194,6 @@ func ProduceBlockAdvanced(
txes types.Transactions,
delayedMessagesRead uint64,
lastBlockHeader *types.Header,
lastHotShotCommitment *espresso.Commitment,
statedb *state.StateDB,
chainContext core.ChainContext,
chainConfig *params.ChainConfig,
Expand All @@ -194,29 +217,6 @@ func ProduceBlockAdvanced(
l1Timestamp: l1Header.Timestamp,
}

// Espresso-specific validation
// TODO test: https://github.com/EspressoSystems/espresso-sequencer/issues/772
if chainConfig.Espresso {
jst := l1Header.BlockJustification
if jst == nil {
return nil, nil, errors.New("batch missing espresso justification")

}
hotshotHeader := jst.Header
if *lastHotShotCommitment != hotshotHeader.Commit() {
return nil, nil, errors.New("invalid hotshot header")
}
var roots = []*espresso.NmtRoot{&hotshotHeader.TransactionsRoot}
var proofs = []*espresso.NmtProof{&l1Header.BlockJustification.Proof}
// If the validation function below were not mocked, we would need to serialize the transactions
// in the batch here. To avoid the unnecessary overhead, we provide an empty array instead.
var txs []espresso.Bytes
err := espresso.ValidateBatchTransactions(chainConfig.ChainID.Uint64(), roots, proofs, txs)
if err != nil {
return nil, nil, errors.New("failed to validate namespace proof)")
}
}

header := createNewHeader(lastBlockHeader, l1Info, state, chainConfig)
signer := types.MakeSigner(chainConfig, header.Number, header.Time)
// Note: blockGasLeft will diverge from the actual gas left during execution in the event of invalid txs,
Expand Down
6 changes: 0 additions & 6 deletions execution/gethexec/executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,13 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes.
}

delayedMessagesRead := lastBlockHeader.Nonce.Uint64()
jst := header.BlockJustification
var hotShotHeader espresso.Commitment
if jst != nil {
hotShotHeader = jst.Header.Commit()
}

startTime := time.Now()
block, receipts, err := arbos.ProduceBlockAdvanced(
header,
txes,
delayedMessagesRead,
lastBlockHeader,
&hotShotHeader,
statedb,
s.bc,
s.bc.Config(),
Expand Down

0 comments on commit 883b5fd

Please sign in to comment.