Skip to content

Commit

Permalink
Headers: use 65-byte signatures instead of R,S values (#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
BedrockSquirrel authored Mar 14, 2024
1 parent 1e781f7 commit 75f610d
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 442 deletions.
20 changes: 8 additions & 12 deletions go/common/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type BatchHeader struct {
BaseFee *big.Int `json:"baseFee"`
Coinbase common.Address `json:"coinbase"`

// The custom Obscuro fields.
// The custom Ten fields.
L1Proof L1BlockHash `json:"l1Proof"` // the L1 block used by the enclave to generate the current batch
R, S *big.Int // signature values
Signature []byte `json:"signature"`
CrossChainMessages []MessageBus.StructsCrossChainMessage `json:"crossChainMessages"`
LatestInboundCrossChainHash common.Hash `json:"inboundCrossChainHash"` // The block hash of the latest block that has been scanned for cross chain messages.
LatestInboundCrossChainHeight *big.Int `json:"inboundCrossChainHeight"` // The block height of the latest block that has been scanned for cross chain messages.
Expand All @@ -63,7 +63,7 @@ type batchHeaderEncoding struct {

// The custom Obscuro fields.
L1Proof L1BlockHash `json:"l1Proof"` // the L1 block used by the enclave to generate the current batch
R, S *hexutil.Big // signature values
Signature []byte `json:"signature"`
CrossChainMessages []MessageBus.StructsCrossChainMessage `json:"crossChainMessages"`
LatestInboundCrossChainHash common.Hash `json:"inboundCrossChainHash"` // The block hash of the latest block that has been scanned for cross chain messages.
LatestInboundCrossChainHeight *hexutil.Big `json:"inboundCrossChainHeight"` // The block height of the latest block that has been scanned for cross chain messages.
Expand All @@ -87,8 +87,7 @@ func (b *BatchHeader) MarshalJSON() ([]byte, error) {
(*hexutil.Big)(b.BaseFee),
&b.Coinbase,
b.L1Proof,
(*hexutil.Big)(b.R),
(*hexutil.Big)(b.S),
b.Signature,
b.CrossChainMessages,
b.LatestInboundCrossChainHash,
(*hexutil.Big)(b.LatestInboundCrossChainHeight),
Expand Down Expand Up @@ -116,8 +115,7 @@ func (b *BatchHeader) UnmarshalJSON(data []byte) error {
b.BaseFee = (*big.Int)(dec.BaseFee)
b.Coinbase = *dec.Coinbase
b.L1Proof = dec.L1Proof
b.R = (*big.Int)(dec.R)
b.S = (*big.Int)(dec.S)
b.Signature = dec.Signature
b.CrossChainMessages = dec.CrossChainMessages
b.LatestInboundCrossChainHash = dec.LatestInboundCrossChainHash
b.LatestInboundCrossChainHeight = (*big.Int)(dec.LatestInboundCrossChainHeight)
Expand All @@ -134,7 +132,7 @@ type RollupHeader struct {
CrossChainMessages []MessageBus.StructsCrossChainMessage `json:"crossChainMessages"`

PayloadHash common.Hash // The hash of the compressed batches. TODO
R, S *big.Int // signature values
Signature []byte // The signature of the sequencer on the payload hash

LastBatchSeqNo uint64
}
Expand Down Expand Up @@ -184,8 +182,7 @@ func (r *RollupHeader) MarshalJSON() ([]byte, error) {
// RLP encoding excluding the signature.
func (b *BatchHeader) Hash() L2BatchHash {
cp := *b
cp.R = nil
cp.S = nil
cp.Signature = nil
hash, err := rlpHash(cp)
if err != nil {
panic("err hashing batch header")
Expand All @@ -197,8 +194,7 @@ func (b *BatchHeader) Hash() L2BatchHash {
// RLP encoding excluding the signature.
func (r *RollupHeader) Hash() L2RollupHash {
cp := *r
cp.R = nil
cp.S = nil
cp.Signature = nil
hash, err := rlpHash(cp)
if err != nil {
panic("err hashing rollup header")
Expand Down
6 changes: 2 additions & 4 deletions go/common/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ func TestBatchHeader_MarshalJSON(t *testing.T) {
Extra: []byte("123"),
BaseFee: gethcommon.Big2,
L1Proof: randomHash(),
R: gethcommon.Big3,
S: gethcommon.Big3,
Signature: gethcommon.Big3.Bytes(),
CrossChainMessages: nil,
LatestInboundCrossChainHash: gethcommon.Hash{},
LatestInboundCrossChainHeight: nil,
Expand All @@ -49,8 +48,7 @@ func TestBatchHeader_MarshalJSON(t *testing.T) {
require.Equal(t, batchHeader.Extra, batchUnmarshalled.Extra)
require.Equal(t, batchHeader.BaseFee, batchUnmarshalled.BaseFee)
require.Equal(t, batchHeader.L1Proof, batchUnmarshalled.L1Proof)
require.Equal(t, batchHeader.R, batchUnmarshalled.R)
require.Equal(t, batchHeader.S, batchUnmarshalled.S)
require.Equal(t, batchHeader.Signature, batchUnmarshalled.Signature)
require.Equal(t, batchHeader.CrossChainMessages, batchUnmarshalled.CrossChainMessages)
require.Equal(t, batchHeader.LatestInboundCrossChainHash, batchUnmarshalled.LatestInboundCrossChainHash)
require.Equal(t, batchHeader.LatestInboundCrossChainHeight, batchUnmarshalled.LatestInboundCrossChainHeight)
Expand Down
16 changes: 4 additions & 12 deletions go/common/rpc/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ func ToBatchHeaderMsg(header *common.BatchHeader) *generated.BatchHeaderMsg {
SequencerOrderNo: header.SequencerOrderNo.Uint64(),
ReceiptHash: header.ReceiptHash.Bytes(),
Extra: header.Extra,
R: header.R.Bytes(),
S: header.S.Bytes(),
Signature: header.Signature,
GasLimit: header.GasLimit,
GasUsed: header.GasUsed,
Time: header.Time,
Expand Down Expand Up @@ -182,8 +181,6 @@ func FromBatchHeaderMsg(header *generated.BatchHeaderMsg) *common.BatchHeader {
return nil
}

r := &big.Int{}
s := &big.Int{}
return &common.BatchHeader{
ParentHash: gethcommon.BytesToHash(header.ParentHash),
L1Proof: gethcommon.BytesToHash(header.Proof),
Expand All @@ -193,8 +190,7 @@ func FromBatchHeaderMsg(header *generated.BatchHeaderMsg) *common.BatchHeader {
SequencerOrderNo: big.NewInt(int64(header.SequencerOrderNo)),
ReceiptHash: gethcommon.BytesToHash(header.ReceiptHash),
Extra: header.Extra,
R: r.SetBytes(header.R),
S: s.SetBytes(header.S),
Signature: header.Signature,
GasLimit: header.GasLimit,
GasUsed: header.GasUsed,
Time: header.Time,
Expand All @@ -221,8 +217,7 @@ func ToRollupHeaderMsg(header *common.RollupHeader) *generated.RollupHeaderMsg {
}
headerMsg := generated.RollupHeaderMsg{
CompressionL1Head: header.CompressionL1Head.Bytes(),
R: header.R.Bytes(),
S: header.S.Bytes(),
Signature: header.Signature,
Coinbase: header.Coinbase.Bytes(),
CrossChainMessages: ToCrossChainMsgs(header.CrossChainMessages),
LastBatchSeqNo: header.LastBatchSeqNo,
Expand Down Expand Up @@ -250,12 +245,9 @@ func FromRollupHeaderMsg(header *generated.RollupHeaderMsg) *common.RollupHeader
return nil
}

r := &big.Int{}
s := &big.Int{}
return &common.RollupHeader{
CompressionL1Head: gethcommon.BytesToHash(header.CompressionL1Head),
R: r.SetBytes(header.R),
S: s.SetBytes(header.S),
Signature: header.Signature,
Coinbase: gethcommon.BytesToAddress(header.Coinbase),
CrossChainMessages: FromCrossChainMsgs(header.CrossChainMessages),
LastBatchSeqNo: header.LastBatchSeqNo,
Expand Down
Loading

0 comments on commit 75f610d

Please sign in to comment.