Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion op-node/p2p/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ func BuildBlocksValidator(log log.Logger, cfg *rollup.Config) pubsub.ValidatorEx
signatureBytes, payloadBytes := data[:65], data[65:]

// [REJECT] if the signature by the sequencer is not valid
signingHash := BlockSigningHash(cfg, payloadBytes)
signingHash, err := BlockSigningHash(cfg, payloadBytes)
if err != nil {
log.Warn("failed to compute block signing hash", "err", err, "peer", id)
return pubsub.ValidationReject
}

pub, err := crypto.SigToPub(signingHash[:], signatureBytes)
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions op-node/p2p/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ type Signer interface {
io.Closer
}

func SigningHash(domain [32]byte, chainID *big.Int, payloadBytes []byte) common.Hash {
func SigningHash(domain [32]byte, chainID *big.Int, payloadBytes []byte) (common.Hash, error) {
var msgInput [32 + 32 + 32]byte
// domain: first 32 bytes
copy(msgInput[:32], domain[:])
// chain_id: second 32 bytes
if chainID.BitLen() > 256 {
return common.Hash{}, errors.New("chain_id is too large")
}
Comment thread
maurelian marked this conversation as resolved.
Outdated
chainID.FillBytes(msgInput[32:64])
// payload_hash: third 32 bytes, hash of encoded payload
copy(msgInput[32:], crypto.Keccak256(payloadBytes))

return crypto.Keccak256Hash(msgInput[:])
return crypto.Keccak256Hash(msgInput[:]), nil
}

func BlockSigningHash(cfg *rollup.Config, payloadBytes []byte) common.Hash {
func BlockSigningHash(cfg *rollup.Config, payloadBytes []byte) (common.Hash, error) {
return SigningHash(SigningDomainBlocksV1, cfg.L2ChainID, payloadBytes)
}

Expand All @@ -52,7 +55,10 @@ func (s *LocalSigner) Sign(ctx context.Context, domain [32]byte, chainID *big.In
if s.priv == nil {
return nil, errors.New("signer is closed")
}
signingHash := SigningHash(domain, chainID, encodedMsg)
signingHash, err := SigningHash(domain, chainID, encodedMsg)
if err != nil {
return nil, err
}
signature, err := crypto.Sign(signingHash[:], s.priv)
if err != nil {
return nil, err
Expand Down