From 9dd1ac18bc2450d550ec6bbd53692a1e4932effb Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Wed, 26 Jul 2023 15:22:30 +0200 Subject: [PATCH] feat: remove square size from qgb commitment creation (#1047) ## Description Closes https://github.com/celestiaorg/celestia-core/issues/1040 After merging this one, I will cherry-pick this change for main. Then, I will open a separate PR for main to remove the square size and the data hash from the `Data` struct. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments --- rpc/core/blocks.go | 31 ++++++++----------------------- rpc/core/blocks_test.go | 11 +++-------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/rpc/core/blocks.go b/rpc/core/blocks.go index d2198f53fe..1c91638f55 100644 --- a/rpc/core/blocks.go +++ b/rpc/core/blocks.go @@ -261,12 +261,11 @@ func To32PaddedHexBytes(number uint64) ([]byte, error) { // The commitments will be signed by orchestrators and submitted to an EVM chain via a relayer. // For more information: https://github.com/celestiaorg/quantum-gravity-bridge/blob/master/src/DataRootTuple.sol type DataRootTuple struct { - height uint64 - dataRoot [32]byte - squareSize uint64 + height uint64 + dataRoot [32]byte } -// EncodeDataRootTuple takes a height, a data root and the square size, and returns the equivalent of +// EncodeDataRootTuple takes a height and a data root, and returns the equivalent of // `abi.encode(...)` in Ethereum. // The encoded type is a DataRootTuple, which has the following ABI: // @@ -283,11 +282,6 @@ type DataRootTuple struct { // "type":"bytes32" // }, // { -// "internalType":"uint256", -// "name":"squareSize", -// "type":"uint256" -// }, -// { // "internalType":"structDataRootTuple", // "name":"_tuple", // "type":"tuple" @@ -295,21 +289,15 @@ type DataRootTuple struct { // ] // } // -// padding the hex representation of the height padded to 32 bytes concatenated to the data root concatenated -// to the hex representation of the square size padded to 32 bytes. +// padding the hex representation of the height padded to 32 bytes concatenated to the data root. // For more information, refer to: // https://github.com/celestiaorg/quantum-gravity-bridge/blob/master/src/DataRootTuple.sol -func EncodeDataRootTuple(height uint64, dataRoot [32]byte, squareSize uint64) ([]byte, error) { +func EncodeDataRootTuple(height uint64, dataRoot [32]byte) ([]byte, error) { paddedHeight, err := To32PaddedHexBytes(height) if err != nil { return nil, err } - dataSlice := dataRoot[:] - paddedSquareSize, err := To32PaddedHexBytes(squareSize) - if err != nil { - return nil, err - } - return append(paddedHeight, append(dataSlice, paddedSquareSize...)...), nil + return append(paddedHeight, dataRoot[:]...), nil } // validateDataCommitmentRange runs basic checks on the asc sorted list of @@ -348,7 +336,6 @@ func hashDataRootTuples(tuples []DataRootTuple) ([]byte, error) { encodedTuple, err := EncodeDataRootTuple( tuple.height, tuple.dataRoot, - tuple.squareSize, ) if err != nil { return nil, err @@ -384,7 +371,6 @@ func proveDataRootTuples(tuples []DataRootTuple, height int64) (*merkle.Proof, e encodedTuple, err := EncodeDataRootTuple( tuple.height, tuple.dataRoot, - tuple.squareSize, ) if err != nil { return nil, err @@ -525,9 +511,8 @@ func fetchDataRootTuples(start, end uint64) ([]DataRootTuple, error) { return nil, fmt.Errorf("couldn't load block %d", height) } tuples = append(tuples, DataRootTuple{ - height: uint64(block.Height), - dataRoot: *(*[32]byte)(block.DataHash), - squareSize: block.SquareSize, + height: uint64(block.Height), + dataRoot: *(*[32]byte)(block.DataHash), }) } return tuples, nil diff --git a/rpc/core/blocks_test.go b/rpc/core/blocks_test.go index 5745102951..d6b6924a48 100644 --- a/rpc/core/blocks_test.go +++ b/rpc/core/blocks_test.go @@ -126,26 +126,23 @@ func TestBlockResults(t *testing.T) { func TestEncodeDataRootTuple(t *testing.T) { height := uint64(2) dataRoot, err := hex.DecodeString("82dc1607d84557d3579ce602a45f5872e821c36dbda7ec926dfa17ebc8d5c013") - squareSize := uint64(64) require.NoError(t, err) expectedEncoding, err := hex.DecodeString( // hex representation of height padded to 32 bytes "0000000000000000000000000000000000000000000000000000000000000002" + // data root - "82dc1607d84557d3579ce602a45f5872e821c36dbda7ec926dfa17ebc8d5c013" + - // original square size - "0000000000000000000000000000000000000000000000000000000000000040", + "82dc1607d84557d3579ce602a45f5872e821c36dbda7ec926dfa17ebc8d5c013", ) require.NoError(t, err) require.NotNil(t, expectedEncoding) - actualEncoding, err := EncodeDataRootTuple(height, *(*[32]byte)(dataRoot), squareSize) + actualEncoding, err := EncodeDataRootTuple(height, *(*[32]byte)(dataRoot)) require.NoError(t, err) require.NotNil(t, actualEncoding) // Check that the length of packed data is correct - assert.Equal(t, len(actualEncoding), 96) + assert.Equal(t, len(actualEncoding), 64) assert.Equal(t, expectedEncoding, actualEncoding) } @@ -191,7 +188,6 @@ func TestDataCommitmentResults(t *testing.T) { encodedTuple, err := EncodeDataRootTuple( uint64(blocks[tc.beginQuery+i].Height), *(*[32]byte)(blocks[tc.beginQuery+i].DataHash), - blocks[tc.beginQuery+i].SquareSize, ) require.NoError(t, err) dataRootEncodedTuples[i] = encodedTuple @@ -266,7 +262,6 @@ func TestDataRootInclusionProofResults(t *testing.T) { encodedTuple, err := EncodeDataRootTuple( uint64(blocks[tc.firstQuery+i].Height), *(*[32]byte)(blocks[tc.firstQuery+i].DataHash), - blocks[tc.firstQuery+i].SquareSize, ) require.NoError(t, err) dataRootEncodedTuples[i] = encodedTuple