Fulu general spectests (#15682)

* batch test

* removing log

* fixing test eval

* adding recover cells tests

* remaining tests

* exclusion
This commit is contained in:
james-prysm
2025-09-15 10:27:45 -05:00
committed by GitHub
parent a5c7c6da06
commit 76bc30e8ba
7 changed files with 328 additions and 2 deletions

View File

@@ -9,6 +9,8 @@ tests/minimal/bellatrix/light_client/data_collection
tests/minimal/capella/light_client/data_collection
tests/minimal/deneb/light_client/data_collection
tests/minimal/electra/light_client/data_collection
tests/minimal/fulu/light_client/single_merkle_proof
tests/mainnet/fulu/light_client/single_merkle_proof
# SSZ Generic
tests/general/phase0/ssz_generic/basic_vector
@@ -112,4 +114,7 @@ tests/minimal/whisk/ssz_static/SyncCommitteeMessage
tests/minimal/whisk/ssz_static/Validator
tests/minimal/whisk/ssz_static/VoluntaryExit
tests/minimal/whisk/ssz_static/WhiskTracker
tests/minimal/whisk/ssz_static/Withdrawal
tests/minimal/whisk/ssz_static/Withdrawal
# Fulu
tests/general/fulu/kzg/compute_verify_cell_kzg_proof_batch_challenge

View File

@@ -2,16 +2,24 @@ load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = ["deneb__kzg__verify_blob_kzg_proof_batch_test.go"],
srcs = [
"deneb__kzg__verify_blob_kzg_proof_batch_test.go",
"fulu__kzg__compute_cells_and_kzg_proofs_test.go",
"fulu__kzg__compute_cells_test.go",
"fulu__kzg__recover_cells_and_kzg_proofs_test.go",
"fulu__kzg__verify_cell_kzg_proof_batch_test.go",
],
data = ["@consensus_spec_tests//:test_data"],
tags = ["spectest"],
deps = [
"//beacon-chain/blockchain/kzg:go_default_library",
"//config/fieldparams:go_default_library",
"//consensus-types/blocks:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/require:go_default_library",
"//testing/spectest/utils:go_default_library",
"//testing/util:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
],
)

View File

@@ -0,0 +1,67 @@
package general
import (
"path"
"testing"
kzgPrysm "github.com/OffchainLabs/prysm/v6/beacon-chain/blockchain/kzg"
fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams"
"github.com/OffchainLabs/prysm/v6/testing/require"
"github.com/OffchainLabs/prysm/v6/testing/spectest/utils"
"github.com/OffchainLabs/prysm/v6/testing/util"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ghodss/yaml"
)
func TestComputeCellsAndKzgProofs(t *testing.T) {
type input struct {
Blob string `json:"blob"`
}
type data struct {
Input input `json:"input"`
Output [][]string `json:"output"`
}
require.NoError(t, kzgPrysm.Start())
testFolders, testFolderPath := utils.TestFolders(t, "general", "fulu", "kzg/compute_cells_and_kzg_proofs/kzg-mainnet")
if len(testFolders) == 0 {
t.Fatalf("No test folders found for %s/%s/%s", "general", "fulu", "kzg/compute_cells_and_kzg_proofs/kzg-mainnet")
}
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
file, err := util.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
require.NoError(t, err)
test := &data{}
require.NoError(t, yaml.Unmarshal(file, test))
blob, err := hexutil.Decode(test.Input.Blob)
require.NoError(t, err)
if len(blob) != fieldparams.BlobLength {
require.IsNil(t, test.Output)
return
}
b := kzgPrysm.Blob(blob)
cellsAndProofsForBlob, err := kzgPrysm.ComputeCellsAndKZGProofs(&b)
if test.Output != nil {
require.NoError(t, err)
var combined [][]string
cs := cellsAndProofsForBlob.Cells
csRaw := make([]string, 0, len(cs))
for _, c := range cs {
csRaw = append(csRaw, hexutil.Encode(c[:]))
}
ps := cellsAndProofsForBlob.Proofs
psRaw := make([]string, 0, len(ps))
for _, p := range ps {
psRaw = append(psRaw, hexutil.Encode(p[:]))
}
combined = append(combined, csRaw)
combined = append(combined, psRaw)
require.DeepEqual(t, test.Output, combined)
} else {
require.NotNil(t, err)
}
})
}
}

View File

@@ -0,0 +1,60 @@
package general
import (
"path"
"testing"
kzgPrysm "github.com/OffchainLabs/prysm/v6/beacon-chain/blockchain/kzg"
fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams"
"github.com/OffchainLabs/prysm/v6/testing/require"
"github.com/OffchainLabs/prysm/v6/testing/spectest/utils"
"github.com/OffchainLabs/prysm/v6/testing/util"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ghodss/yaml"
)
func TestComputeCells(t *testing.T) {
type input struct {
Blob string `json:"blob"`
}
type data struct {
Input input `json:"input"`
Output []string `json:"output"`
}
require.NoError(t, kzgPrysm.Start())
testFolders, testFolderPath := utils.TestFolders(t, "general", "fulu", "kzg/compute_cells/kzg-mainnet")
if len(testFolders) == 0 {
t.Fatalf("No test folders found for %s/%s/%s", "general", "fulu", "kzg/compute_cells/kzg-mainnet")
}
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
file, err := util.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
require.NoError(t, err)
test := &data{}
require.NoError(t, yaml.Unmarshal(file, test))
blob, err := hexutil.Decode(test.Input.Blob)
require.NoError(t, err)
if len(blob) != fieldparams.BlobLength {
require.IsNil(t, test.Output)
return
}
b := kzgPrysm.Blob(blob)
// Recover the cells and proofs for the corresponding blob
cells, err := kzgPrysm.ComputeCells(&b)
if test.Output != nil {
require.NoError(t, err)
cs := make([]string, 0, len(cells))
for _, c := range cells {
cs = append(cs, hexutil.Encode(c[:]))
}
require.DeepEqual(t, test.Output, cs)
} else {
require.NotNil(t, err)
}
})
}
}

View File

@@ -0,0 +1,94 @@
package general
import (
"path"
"strconv"
"testing"
kzgPrysm "github.com/OffchainLabs/prysm/v6/beacon-chain/blockchain/kzg"
"github.com/OffchainLabs/prysm/v6/testing/require"
"github.com/OffchainLabs/prysm/v6/testing/spectest/utils"
"github.com/OffchainLabs/prysm/v6/testing/util"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ghodss/yaml"
)
func TestRecoverCellsAndKzgProofs(t *testing.T) {
type input struct {
CellIndices []string `json:"cell_indices"`
Cells []string `json:"cells"`
}
type data struct {
Input input `json:"input"`
Output [][]string `json:"output"`
}
require.NoError(t, kzgPrysm.Start())
testFolders, testFolderPath := utils.TestFolders(t, "general", "fulu", "kzg/recover_cells_and_kzg_proofs/kzg-mainnet")
if len(testFolders) == 0 {
t.Fatalf("No test folders found for %s/%s/%s", "general", "fulu", "kzg/recover_cells_and_kzg_proofs/kzg-mainnet")
}
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
file, err := util.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
require.NoError(t, err)
test := &data{}
require.NoError(t, yaml.Unmarshal(file, test))
cellIndicesRaw := test.Input.CellIndices
cellIndices := make([]uint64, 0, len(cellIndicesRaw))
for _, idx := range cellIndicesRaw {
i, err := strconv.ParseUint(idx, 10, 64)
require.NoError(t, err)
cellIndices = append(cellIndices, i)
}
// Check if cell indices are sorted
isSorted := true
for i := 1; i < len(cellIndices); i++ {
if cellIndices[i] <= cellIndices[i-1] {
isSorted = false
break
}
}
// If cell indices are not sorted and test expects failure, return early
if !isSorted && test.Output == nil {
require.IsNil(t, test.Output)
return
}
cellsRaw := test.Input.Cells
cells := make([]kzgPrysm.Cell, 0, len(cellsRaw))
for _, cellRaw := range cellsRaw {
cell, err := hexutil.Decode(cellRaw)
require.NoError(t, err)
if len(cell) != kzgPrysm.BytesPerCell {
require.IsNil(t, test.Output)
return
}
cells = append(cells, kzgPrysm.Cell(cell))
}
// Recover the cells and proofs for the corresponding blob
cellsAndProofsForBlob, err := kzgPrysm.RecoverCellsAndKZGProofs(cellIndices, cells)
if test.Output != nil {
require.NoError(t, err)
var combined [][]string
cs := cellsAndProofsForBlob.Cells
csRaw := make([]string, 0, len(cs))
for _, c := range cs {
csRaw = append(csRaw, hexutil.Encode(c[:]))
}
ps := cellsAndProofsForBlob.Proofs
psRaw := make([]string, 0, len(ps))
for _, p := range ps {
psRaw = append(psRaw, hexutil.Encode(p[:]))
}
combined = append(combined, csRaw)
combined = append(combined, psRaw)
require.DeepEqual(t, test.Output, combined)
} else {
require.NotNil(t, err)
}
})
}
}

View File

@@ -0,0 +1,89 @@
package general
import (
"path"
"strconv"
"testing"
kzgPrysm "github.com/OffchainLabs/prysm/v6/beacon-chain/blockchain/kzg"
"github.com/OffchainLabs/prysm/v6/testing/require"
"github.com/OffchainLabs/prysm/v6/testing/spectest/utils"
"github.com/OffchainLabs/prysm/v6/testing/util"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ghodss/yaml"
)
func TestVerifyCellKZGProofBatch(t *testing.T) {
type input struct {
Commitments []string `json:"commitments"`
CellIndices []string `json:"cell_indices"`
Cells []string `json:"cells"`
Proofs []string `json:"proofs"`
}
type data struct {
Input input `json:"input"`
Output bool `json:"output"`
}
require.NoError(t, kzgPrysm.Start())
testFolders, testFolderPath := utils.TestFolders(t, "general", "fulu", "kzg/verify_cell_kzg_proof_batch/kzg-mainnet")
if len(testFolders) == 0 {
t.Fatalf("No test folders found for %s/%s/%s", "general", "fulu", "kzg/verify_cell_kzg_proof_batch/kzg-mainnet")
}
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
file, err := util.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
require.NoError(t, err)
test := &data{}
require.NoError(t, yaml.Unmarshal(file, test))
commitmentsRaw := test.Input.Commitments
commitments := make([]kzgPrysm.Bytes48, 0, len(commitmentsRaw))
for _, commitmentRaw := range commitmentsRaw {
commitment, err := hexutil.Decode(commitmentRaw)
require.NoError(t, err)
if len(commitment) != 48 {
require.Equal(t, false, test.Output)
return
}
commitments = append(commitments, kzgPrysm.Bytes48(commitment))
}
cellIndicesRaw := test.Input.CellIndices
cellIndices := make([]uint64, 0, len(cellIndicesRaw))
for _, idx := range cellIndicesRaw {
i, err := strconv.ParseUint(idx, 10, 64)
require.NoError(t, err)
cellIndices = append(cellIndices, i)
}
cellsRaw := test.Input.Cells
cells := make([]kzgPrysm.Cell, 0, len(cellsRaw))
for _, cellRaw := range cellsRaw {
cell, err := hexutil.Decode(cellRaw)
require.NoError(t, err)
if len(cell) != kzgPrysm.BytesPerCell {
require.Equal(t, false, test.Output)
return
}
cells = append(cells, kzgPrysm.Cell(cell))
}
proofsRaw := test.Input.Proofs
proofs := make([]kzgPrysm.Bytes48, 0, len(proofsRaw))
for _, proofRaw := range proofsRaw {
proof, err := hexutil.Decode(proofRaw)
require.NoError(t, err)
if len(proof) != 48 {
require.Equal(t, false, test.Output)
return
}
proofs = append(proofs, kzgPrysm.Bytes48(proof))
}
ok, err := kzgPrysm.VerifyCellKZGProofBatch(commitments, cellIndices, cells, proofs)
if test.Output {
require.Equal(t, true, ok)
require.NoError(t, err)
} else {
require.Equal(t, false, ok)
}
})
}
}