Skip to content

Commit

Permalink
Merge pull request #2105 from OffchainLabs/delayed-sequencer-hash
Browse files Browse the repository at this point in the history
In delayed sequencer, check accumulator against safe block hash
  • Loading branch information
PlasmaPower authored Feb 2, 2024
2 parents dddc111 + 050ff38 commit 17468a8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
41 changes: 36 additions & 5 deletions arbnode/delayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"bytes"
"context"
"errors"
"fmt"
"math/big"
"sort"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
Expand All @@ -28,13 +30,15 @@ var messageDeliveredID common.Hash
var inboxMessageDeliveredID common.Hash
var inboxMessageFromOriginID common.Hash
var l2MessageFromOriginCallABI abi.Method
var delayedInboxAccsCallABI abi.Method

func init() {
parsedIBridgeABI, err := bridgegen.IBridgeMetaData.GetAbi()
if err != nil {
panic(err)
}
messageDeliveredID = parsedIBridgeABI.Events["MessageDelivered"].ID
delayedInboxAccsCallABI = parsedIBridgeABI.Methods["delayedInboxAccs"]

parsedIMessageProviderABI, err := bridgegen.IDelayedMessageProviderMetaData.GetAbi()
if err != nil {
Expand Down Expand Up @@ -95,12 +99,39 @@ func (b *DelayedBridge) GetMessageCount(ctx context.Context, blockNumber *big.In
return bigRes.Uint64(), nil
}

func (b *DelayedBridge) GetAccumulator(ctx context.Context, sequenceNumber uint64, blockNumber *big.Int) (common.Hash, error) {
opts := &bind.CallOpts{
Context: ctx,
BlockNumber: blockNumber,
// Uses blockHash if nonzero, otherwise uses blockNumber
func (b *DelayedBridge) GetAccumulator(ctx context.Context, sequenceNumber uint64, blockNumber *big.Int, blockHash common.Hash) (common.Hash, error) {
calldata := append([]byte{}, delayedInboxAccsCallABI.ID...)
inputs, err := delayedInboxAccsCallABI.Inputs.Pack(arbmath.UintToBig(sequenceNumber))
if err != nil {
return common.Hash{}, err
}
calldata = append(calldata, inputs...)
msg := ethereum.CallMsg{
To: &b.address,
Data: calldata,
}
var result hexutil.Bytes
if blockHash != (common.Hash{}) {
result, err = b.client.CallContractAtHash(ctx, msg, blockHash)
} else {
result, err = b.client.CallContract(ctx, msg, blockNumber)
}
if err != nil {
return common.Hash{}, err
}
values, err := delayedInboxAccsCallABI.Outputs.Unpack(result)
if err != nil {
return common.Hash{}, err
}
if len(values) != 1 {
return common.Hash{}, fmt.Errorf("expected 1 return value from %v, got %v", delayedInboxAccsCallABI.Name, len(values))
}
hash, ok := values[0].([32]byte)
if !ok {
return common.Hash{}, fmt.Errorf("expected [32]uint8 return value from %v, got %T", delayedInboxAccsCallABI.Name, values[0])
}
return b.con.DelayedInboxAccs(opts, new(big.Int).SetUint64(sequenceNumber))
return hash, nil
}

type DelayedInboxMessage struct {
Expand Down
10 changes: 7 additions & 3 deletions arbnode/delayed_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,20 @@ func (d *DelayedSequencer) sequenceWithoutLockout(ctx context.Context, lastBlock
}

var finalized uint64
var finalizedHash common.Hash
if config.UseMergeFinality && headerreader.HeaderIndicatesFinalitySupport(lastBlockHeader) {
var header *types.Header
var err error
if config.RequireFullFinality {
finalized, err = d.l1Reader.LatestFinalizedBlockNr(ctx)
header, err = d.l1Reader.LatestFinalizedBlockHeader(ctx)
} else {
finalized, err = d.l1Reader.LatestSafeBlockNr(ctx)
header, err = d.l1Reader.LatestSafeBlockHeader(ctx)
}
if err != nil {
return err
}
finalized = header.Number.Uint64()
finalizedHash = header.Hash()
} else {
currentNum := lastBlockHeader.Number.Int64()
if currentNum < config.FinalizeDistance {
Expand Down Expand Up @@ -167,7 +171,7 @@ func (d *DelayedSequencer) sequenceWithoutLockout(ctx context.Context, lastBlock

// Sequence the delayed messages, if any
if len(messages) > 0 {
delayedBridgeAcc, err := d.bridge.GetAccumulator(ctx, pos-1, new(big.Int).SetUint64(finalized))
delayedBridgeAcc, err := d.bridge.GetAccumulator(ctx, pos-1, new(big.Int).SetUint64(finalized), finalizedHash)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion arbnode/inbox_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (r *InboxReader) run(ctx context.Context, hadError bool) error {
}
if checkingDelayedCount > 0 {
checkingDelayedSeqNum := checkingDelayedCount - 1
l1DelayedAcc, err := r.delayedBridge.GetAccumulator(ctx, checkingDelayedSeqNum, currentHeight)
l1DelayedAcc, err := r.delayedBridge.GetAccumulator(ctx, checkingDelayedSeqNum, currentHeight, common.Hash{})
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions arbutil/wait_for_l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type L1Interface interface {
ethereum.TransactionReader
TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
BlockNumber(ctx context.Context) (uint64, error)
CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
ChainID(ctx context.Context) (*big.Int, error)
Client() rpc.ClientInterface
Expand Down

0 comments on commit 17468a8

Please sign in to comment.