Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove square size from qgb commitment creation #1047

Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 8 additions & 23 deletions rpc/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand All @@ -283,33 +282,22 @@ type DataRootTuple struct {
// "type":"bytes32"
// },
// {
// "internalType":"uint256",
// "name":"squareSize",
// "type":"uint256"
// },
// {
// "internalType":"structDataRootTuple",
// "name":"_tuple",
// "type":"tuple"
// }
// ]
// }
//
// 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading