From 74c46bbce2972a0bd82657c49f1b3a4280922271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Fri, 17 Jan 2025 14:39:09 +0100 Subject: [PATCH] add data to composite hash & sign it --- go/enclave/nodetype/sequencer.go | 29 +++++++++++++++++++++++++---- go/ethadapter/blob.go | 6 +++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/go/enclave/nodetype/sequencer.go b/go/enclave/nodetype/sequencer.go index 24ba59b50..b7b38cbce 100644 --- a/go/enclave/nodetype/sequencer.go +++ b/go/enclave/nodetype/sequencer.go @@ -328,13 +328,34 @@ func (s *sequencer) CreateRollup(ctx context.Context, lastBatchNo uint64) (*comm return nil, fmt.Errorf("failed to encode rollup to blobs: %w", err) } - // Store the blob data + // Calculate blob hash + blobHash, err := ethadapter.ComputeBlobHash(blobs[0]) + if err != nil { + return nil, fmt.Errorf("failed to compute blob hash: %w", err) + } + + // Store blob data and required fields extRollup.BlobData = blobs + extRollup.Header.BlobHash = blobHash + extRollup.Header.MessageRoot = gethcommon.Hash{} // TODO: Implement message root + extRollup.Header.BlockNumber = currentL1Head.Number.Uint64() + extRollup.Header.CompressionL1Head = currentL1Head.Hash() + + // Create composite hash matching the contract expectation + compositeHash := gethcrypto.Keccak256Hash( + blobHash.Bytes(), + extRollup.Header.MessageRoot.Bytes(), + currentL1Head.Hash().Bytes(), + big.NewInt(int64(currentL1Head.Number.Uint64())).Bytes(), + big.NewInt(int64(extRollup.Header.LastBatchSeqNo)).Bytes(), + ) - // Sign the rollup - if err := s.signRollup(extRollup); err != nil { - return nil, fmt.Errorf("failed to sign created rollup: %w", err) + // Sign the composite hash + signature, err := s.enclaveKeyService.Sign(compositeHash) + if err != nil { + return nil, fmt.Errorf("failed to sign rollup: %w", err) } + extRollup.Header.Signature = signature return extRollup, nil } diff --git a/go/ethadapter/blob.go b/go/ethadapter/blob.go index b27d9a914..886b20e9a 100644 --- a/go/ethadapter/blob.go +++ b/go/ethadapter/blob.go @@ -162,5 +162,9 @@ func ComputeBlobHash(blob *kzg4844.Blob) (gethcommon.Hash, error) { return gethcommon.Hash{}, err } - return KZGToVersionedHash(commitment), nil + // Create versioned hash matching EIP-4844 specification + var hash gethcommon.Hash + hash[0] = 0x01 // Version byte + copy(hash[1:], commitment[:]) + return hash, nil }