Skip to content

Commit 55a09df

Browse files
authored
Don't let the sequencer include deposits (#57)
1 parent 54537dc commit 55a09df

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

op-enclave/enclave/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ func (c *Client) SetSignerKey(ctx context.Context, encrypted hexutil.Bytes) erro
5050
return c.callContext(ctx, nil, "setSignerKey", encrypted)
5151
}
5252

53-
func (c *Client) ExecuteStateless(ctx context.Context, config *PerChainConfig, l1Origin *types.Header, l1Receipts types.Receipts, previousBlockTxs []hexutil.Bytes, blockHeader *types.Header, blockTxs []hexutil.Bytes, witness *stateless.ExecutionWitness, messageAccount *eth.AccountResult, prevMessageAccountHash common.Hash) (*Proposal, error) {
53+
func (c *Client) ExecuteStateless(ctx context.Context, config *PerChainConfig, l1Origin *types.Header, l1Receipts types.Receipts, previousBlockTxs []hexutil.Bytes, blockHeader *types.Header, sequencedTxs []hexutil.Bytes, witness *stateless.ExecutionWitness, messageAccount *eth.AccountResult, prevMessageAccountHash common.Hash) (*Proposal, error) {
5454
var result Proposal
55-
return &result, c.callContext(ctx, &result, "executeStateless", config, l1Origin, l1Receipts, previousBlockTxs, blockHeader, blockTxs, witness, messageAccount, prevMessageAccountHash)
55+
return &result, c.callContext(ctx, &result, "executeStateless", config, l1Origin, l1Receipts, previousBlockTxs, blockHeader, sequencedTxs, witness, messageAccount, prevMessageAccountHash)
5656
}
5757

5858
func (c *Client) Aggregate(ctx context.Context, configHash common.Hash, prevOutputRoot common.Hash, proposals []*Proposal) (*Proposal, error) {

op-enclave/enclave/rpc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type RPC interface {
2626
l1Receipts types.Receipts,
2727
previousBlockTxs []hexutil.Bytes,
2828
blockHeader *types.Header,
29-
blockTxs []hexutil.Bytes,
29+
sequencedTxs []hexutil.Bytes,
3030
witness *stateless.ExecutionWitness,
3131
messageAccount *eth.AccountResult,
3232
prevMessageAccountHash common.Hash,

op-enclave/enclave/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (s *Server) ExecuteStateless(
243243
l1Receipts types.Receipts,
244244
previousBlockTxs []hexutil.Bytes,
245245
blockHeader *types.Header,
246-
blockTxs []hexutil.Bytes,
246+
sequencedTxs []hexutil.Bytes,
247247
witness *stateless.ExecutionWitness,
248248
messageAccount *eth.AccountResult,
249249
prevMessageAccountHash common.Hash,
@@ -267,7 +267,7 @@ func (s *Server) ExecuteStateless(
267267
previousBlockHeader := w.Headers[0]
268268

269269
err = ExecuteStateless(ctx, config.ChainConfig, config.ToRollupConfig(),
270-
l1Origin, l1Receipts, previousBlockTxs, blockHeader, blockTxs, w, messageAccount)
270+
l1Origin, l1Receipts, previousBlockTxs, blockHeader, sequencedTxs, w, messageAccount)
271271
if err != nil {
272272
return nil, err
273273
}

op-enclave/enclave/stateless.go

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package enclave
22

33
import (
4-
"bytes"
54
"context"
65
"errors"
76
"fmt"
@@ -26,7 +25,7 @@ func ExecuteStateless(
2625
l1Receipts types.Receipts,
2726
previousBlockTxs []hexutil.Bytes,
2827
blockHeader *types.Header,
29-
blockTxs []hexutil.Bytes,
28+
sequencedTxs []hexutil.Bytes,
3029
witness *stateless.Witness,
3130
messageAccount *eth.AccountResult,
3231
) error {
@@ -42,6 +41,11 @@ func ExecuteStateless(
4241
return errors.New("invalid parent hash")
4342
}
4443

44+
// block must only contain deposit transactions if it is outside the sequencer drift
45+
if len(sequencedTxs) > 0 && blockHeader.Time > l1Origin.Time+maxSequencerDriftFjord {
46+
return errors.New("l1 origin is too old")
47+
}
48+
4549
unmarshalTxs := func(rlp []hexutil.Bytes) (types.Transactions, error) {
4650
txs := make(types.Transactions, len(rlp))
4751
for i, tx := range rlp {
@@ -56,10 +60,6 @@ func ExecuteStateless(
5660
if err != nil {
5761
return err
5862
}
59-
txs, err := unmarshalTxs(blockTxs)
60-
if err != nil {
61-
return err
62-
}
6363

6464
previousTxHash := types.DeriveSha(previousTxs, trie.NewStackTrie(nil))
6565
if previousTxHash != previousBlockHeader.TxHash {
@@ -90,25 +90,23 @@ func ExecuteStateless(
9090
return fmt.Errorf("failed to prepare payload attributes: %w", err)
9191
}
9292

93-
if txs.Len() < len(payload.Transactions) {
94-
return errors.New("invalid transaction count")
93+
// sequencer cannot include manual deposit transactions; otherwise it could mint funds arbitrarily
94+
txs, err := unmarshalTxs(sequencedTxs)
95+
if err != nil {
96+
return err
9597
}
96-
97-
for i, payloadTx := range payload.Transactions {
98-
tx := txs[i]
99-
if !tx.IsDepositTx() {
100-
return errors.New("invalid transaction type")
101-
}
102-
if !bytes.Equal(blockTxs[i], payloadTx) {
103-
return errors.New("invalid deposit transaction")
98+
for _, tx := range txs {
99+
if tx.IsDepositTx() {
100+
return errors.New("sequenced txs cannot include deposits")
104101
}
105102
}
106103

107-
// block must only contain deposit transactions if it is outside the sequencer drift
108-
if txs.Len() > len(payload.Transactions) &&
109-
blockHeader.Time > l1Origin.Time+maxSequencerDriftFjord {
110-
return errors.New("L1 origin is too old")
104+
// now add the deposits from L1 (and any from fork upgrades)
105+
payloadTxs, err := unmarshalTxs(payload.Transactions)
106+
if err != nil {
107+
return fmt.Errorf("failed to parse payload transactions: %w", err)
111108
}
109+
txs = append(payloadTxs, txs...)
112110

113111
expectedRoot := blockHeader.Root
114112
expectedReceiptHash := blockHeader.ReceiptHash

op-proposer/proposer/prover.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,25 @@ func (o *Prover) Generate(ctx context.Context, block *types.Block) (*Proposal, e
118118
return nil, &multierror.Error{Errors: errors}
119119
}
120120

121-
marshalTxs := func(txs types.Transactions) ([]hexutil.Bytes, error) {
122-
rlp := make([]hexutil.Bytes, len(txs))
123-
var err error
124-
for i, tx := range txs {
125-
if rlp[i], err = tx.MarshalBinary(); err != nil {
121+
marshalTxs := func(txs types.Transactions, includeDeposits bool) ([]hexutil.Bytes, error) {
122+
var rlps []hexutil.Bytes
123+
for _, tx := range txs {
124+
if !includeDeposits && tx.IsDepositTx() {
125+
continue
126+
}
127+
rlp, err := tx.MarshalBinary()
128+
if err != nil {
126129
return nil, fmt.Errorf("failed to marshal transaction: %w", err)
127130
}
131+
rlps = append(rlps, rlp)
128132
}
129-
return rlp, nil
133+
return rlps, nil
130134
}
131-
previousTxs, err := marshalTxs(previousBlock.value.Transactions())
135+
previousTxs, err := marshalTxs(previousBlock.value.Transactions(), true)
132136
if err != nil {
133137
return nil, err
134138
}
135-
txs, err := marshalTxs(block.Transactions())
139+
sequencedTxs, err := marshalTxs(block.Transactions(), false)
136140
if err != nil {
137141
return nil, err
138142
}
@@ -144,7 +148,7 @@ func (o *Prover) Generate(ctx context.Context, block *types.Block) (*Proposal, e
144148
l1Receipts.value,
145149
previousTxs,
146150
block.Header(),
147-
txs,
151+
sequencedTxs,
148152
witness.value,
149153
messageAccount.value,
150154
prevMessageAccount.value.StorageHash,

0 commit comments

Comments
 (0)