Skip to content

Commit

Permalink
add data to composite hash & sign it
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj committed Jan 17, 2025
1 parent 1c11c3c commit 74c46bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
29 changes: 25 additions & 4 deletions go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion go/ethadapter/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 74c46bb

Please sign in to comment.