Skip to content
Closed
Changes from 6 commits
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
15 changes: 14 additions & 1 deletion consensus/system_contract/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package system_contract

import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -136,6 +137,7 @@ func (s *SystemContract) verifyHeader(chain consensus.ChainHeaderReader, header
}
// Check that the BlockSignature contains signature if block is not requested
if header.Number.Cmp(big.NewInt(0)) != 0 && len(header.BlockSignature) != extraSeal {
log.Info("Morty: missing signature", "hash", header.Hash(), "signature", hex.EncodeToString(header.BlockSignature), "extra", hex.EncodeToString(header.Extra), "number", header.Number)
return errMissingSignature
}
// Ensure that the mix digest is zero
Expand Down Expand Up @@ -211,6 +213,7 @@ func (s *SystemContract) verifyCascadingFields(chain consensus.ChainHeaderReader
defer s.lock.RUnlock()

if signer != s.signerAddressL1 {
log.Info("Morty: ecrecover Unauthorized signer", "Got", signer, "Expected:", s.signerAddressL1)
log.Error("Unauthorized signer", "Got", signer, "Expected:", s.signerAddressL1)
return ErrUnauthorizedSigner
}
Expand Down Expand Up @@ -393,15 +396,25 @@ func SealHash(header *types.Header) (hash common.Hash) {
// ecrecover extracts the Ethereum account address from a signed header.
func ecrecover(header *types.Header) (common.Address, error) {
signature := header.BlockSignature[0:]
// Normalize recovery ID for compatibility with Scroll's reth node.
// Scroll's reth uses alloy signer which produces signatures with recovery ID (V) of 27/28,
// but Ethereum's standard crypto.Ecrecover expects V to be 0/1.
// Convert 27/28 format to 0/1 format by subtracting 27.
if signature[64] >= 27 && signature[64] <= 28 {
signature[64] -= 27
}

log.Info("Morty: ecrecover", "hash", header.Hash(), "signature", hex.EncodeToString(signature))

// Recover the public key and the Ethereum address
pubkey, err := crypto.Ecrecover(SealHash(header).Bytes(), signature)
if err != nil {
log.Info("Morty: failed to ecrecover", "hash", header.Hash(), "signature", hex.EncodeToString(signature), "error", err)
return common.Address{}, err
}
var signer common.Address
copy(signer[:], crypto.Keccak256(pubkey[1:])[12:])

log.Info("Morty: ecrecover", "hash", header.Hash(), "signer", signer.Hex())
return signer, nil
}

Expand Down
Loading