Skip to content

Commit

Permalink
Check that local signer is valid signer
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchalp committed Jan 15, 2025
1 parent 8b0475c commit f438d7b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion consensus/system_contract/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,15 @@ func (s *SystemContract) Seal(chain consensus.ChainHeaderReader, block *types.Bl
s.lock.RUnlock()

// Bail out if we're unauthorized to sign a block
// todo
expectedSigner, err := s.findSignerSlice(number)
if err != nil {
// e.g., "no signer for block"
return fmt.Errorf("cannot seal block %d: %w", number, err)
}

if signer != expectedSigner {
return errors.New("local node is not authorized to sign this block")
}

// Sweet, the protocol permits us to sign the block, wait for our time
delay := time.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple
Expand Down
3 changes: 1 addition & 2 deletions consensus/system_contract/system_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"github.com/scroll-tech/go-ethereum"
"github.com/scroll-tech/go-ethereum/accounts/abi"
"github.com/scroll-tech/go-ethereum/ethclient"
"math/big"
"strings"
"sync"
Expand Down Expand Up @@ -96,7 +95,7 @@ func (s *SystemContract) fetchAllSigners(blockNum *big.Int) ([]SignerAddressL1,
}

// Perform the call via the ethclient interface (need to cast)
output, err := s.client.(*ethclient.Client).CallContract(s.ctx, msg, blockNum)
output, err := s.client.CallContract(s.ctx, msg, blockNum)
if err != nil {
return nil, fmt.Errorf("CallContract error: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions rollup/sync_service/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ type EthClient interface {
TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error)
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
}

0 comments on commit f438d7b

Please sign in to comment.