2023-10-16 05:30:33 +00:00
|
|
|
package verify
|
|
|
|
|
|
|
|
import (
|
2023-11-21 18:44:38 +00:00
|
|
|
"fmt"
|
2023-10-16 05:30:33 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
2023-11-21 18:44:38 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
2023-10-16 05:30:33 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBlobAlignsWithBlock(t *testing.T) {
|
|
|
|
tests := []struct {
|
2023-11-21 18:44:38 +00:00
|
|
|
name string
|
|
|
|
blockAndBlob func(t *testing.T) (blocks.ROBlock, []blocks.ROBlob)
|
|
|
|
err error
|
2023-10-16 05:30:33 +00:00
|
|
|
}{
|
|
|
|
{
|
2023-11-21 18:44:38 +00:00
|
|
|
name: "happy path",
|
|
|
|
blockAndBlob: func(t *testing.T) (blocks.ROBlock, []blocks.ROBlob) {
|
|
|
|
return util.GenerateTestDenebBlockWithSidecar(t, [32]byte{}, 0, 1)
|
|
|
|
},
|
2023-10-16 05:30:33 +00:00
|
|
|
},
|
|
|
|
{
|
2023-11-21 18:44:38 +00:00
|
|
|
name: "mismatched roots",
|
|
|
|
blockAndBlob: func(t *testing.T) (blocks.ROBlock, []blocks.ROBlob) {
|
|
|
|
blk, blobs := util.GenerateTestDenebBlockWithSidecar(t, [32]byte{}, 0, 1)
|
|
|
|
tweaked := blobs[0].BlobSidecar
|
|
|
|
tweaked.SignedBlockHeader.Header.Slot = tweaked.SignedBlockHeader.Header.Slot + 1
|
|
|
|
tampered, err := blocks.NewROBlob(tweaked)
|
2023-10-16 05:30:33 +00:00
|
|
|
require.NoError(t, err)
|
2023-11-21 18:44:38 +00:00
|
|
|
return blk, []blocks.ROBlob{tampered}
|
|
|
|
},
|
|
|
|
err: ErrBlobBlockMisaligned,
|
2023-10-16 05:30:33 +00:00
|
|
|
},
|
|
|
|
{
|
2023-11-21 18:44:38 +00:00
|
|
|
name: "mismatched roots - fake",
|
|
|
|
blockAndBlob: func(t *testing.T) (blocks.ROBlock, []blocks.ROBlob) {
|
|
|
|
blk, blobs := util.GenerateTestDenebBlockWithSidecar(t, [32]byte{}, 0, 1)
|
|
|
|
copied := blobs[0].BlobSidecar
|
|
|
|
// exact same header, mess with the root
|
|
|
|
fake, err := blocks.NewROBlobWithRoot(copied, bytesutil.ToBytes32([]byte("derp")))
|
2023-10-16 05:30:33 +00:00
|
|
|
require.NoError(t, err)
|
2023-11-21 18:44:38 +00:00
|
|
|
return blk, []blocks.ROBlob{fake}
|
|
|
|
},
|
|
|
|
err: ErrBlobBlockMisaligned,
|
2023-10-16 05:30:33 +00:00
|
|
|
},
|
|
|
|
{
|
2023-11-21 18:44:38 +00:00
|
|
|
name: "before deneb",
|
|
|
|
blockAndBlob: func(t *testing.T) (blocks.ROBlock, []blocks.ROBlob) {
|
|
|
|
cb := util.NewBeaconBlockCapella()
|
|
|
|
blk, err := blocks.NewSignedBeaconBlock(cb)
|
2023-10-16 05:30:33 +00:00
|
|
|
require.NoError(t, err)
|
2023-11-21 18:44:38 +00:00
|
|
|
rob, err := blocks.NewROBlock(blk)
|
2023-10-16 05:30:33 +00:00
|
|
|
require.NoError(t, err)
|
2023-11-21 18:44:38 +00:00
|
|
|
return rob, []blocks.ROBlob{blocks.ROBlob{}}
|
|
|
|
},
|
2023-10-16 05:30:33 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
2023-11-21 18:44:38 +00:00
|
|
|
block, blobs := tt.blockAndBlob(t)
|
|
|
|
for i := range blobs {
|
|
|
|
t.Run(tt.name+fmt.Sprintf(" blob %d", i), func(t *testing.T) {
|
|
|
|
err := BlobAlignsWithBlock(blobs[i], block)
|
|
|
|
if tt.err == nil {
|
|
|
|
require.NoError(t, err)
|
|
|
|
} else {
|
|
|
|
require.ErrorIs(t, err, tt.err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-10-16 05:30:33 +00:00
|
|
|
}
|
|
|
|
}
|