Skip to content

Commit

Permalink
Make CellsPerExtBlob in Go bindings public
Browse files Browse the repository at this point in the history
I believe this affects how clients see the return types. It appears as a slice
instead of an array of a known size. This isn't right.
  • Loading branch information
jtraglia committed Jul 15, 2024
1 parent 7af67a4 commit e689135
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
24 changes: 12 additions & 12 deletions bindings/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const (
// Only used in testing, shouldn't be exposed.
bytesPerFieldElement = C.BYTES_PER_FIELD_ELEMENT

// Used to define return types, but clients should use the NUMBER_OF_COLUMNS
// constant from the consensus specs. These will be the same.
cellsPerExtBlob = C.CELLS_PER_EXT_BLOB
// CellsPerExtBlob is only used to define return types. Clients should
// use the NUMBER_OF_COLUMNS constant from the consensus specs instead.
CellsPerExtBlob = C.CELLS_PER_EXT_BLOB
)

type (
Expand Down Expand Up @@ -411,21 +411,21 @@ ComputeCellsAndKZGProofs is the binding for:
const Blob *blob,
const KZGSettings *s);
*/
func ComputeCellsAndKZGProofs(blob *Blob) ([cellsPerExtBlob]Cell, [cellsPerExtBlob]KZGProof, error) {
func ComputeCellsAndKZGProofs(blob *Blob) ([CellsPerExtBlob]Cell, [CellsPerExtBlob]KZGProof, error) {
if !loaded {
panic("trusted setup isn't loaded")
}

cells := [cellsPerExtBlob]Cell{}
proofs := [cellsPerExtBlob]KZGProof{}
cells := [CellsPerExtBlob]Cell{}
proofs := [CellsPerExtBlob]KZGProof{}
ret := C.compute_cells_and_kzg_proofs(
(*C.Cell)(unsafe.Pointer(&cells)),
(*C.KZGProof)(unsafe.Pointer(&proofs)),
(*C.Blob)(unsafe.Pointer(blob)),
&settings)

if ret != C.C_KZG_OK {
return [cellsPerExtBlob]Cell{}, [cellsPerExtBlob]KZGProof{}, makeErrorFromRet(ret)
return [CellsPerExtBlob]Cell{}, [CellsPerExtBlob]KZGProof{}, makeErrorFromRet(ret)
}
return cells, proofs, nil
}
Expand All @@ -441,16 +441,16 @@ RecoverCellsAndKZGProofs is the binding for:
size_t num_cells,
const KZGSettings *s);
*/
func RecoverCellsAndKZGProofs(cellIndices []uint64, cells []Cell) ([cellsPerExtBlob]Cell, [cellsPerExtBlob]KZGProof, error) {
func RecoverCellsAndKZGProofs(cellIndices []uint64, cells []Cell) ([CellsPerExtBlob]Cell, [CellsPerExtBlob]KZGProof, error) {
if !loaded {
panic("trusted setup isn't loaded")
}
if len(cellIndices) != len(cells) {
return [cellsPerExtBlob]Cell{}, [cellsPerExtBlob]KZGProof{}, ErrBadArgs
return [CellsPerExtBlob]Cell{}, [CellsPerExtBlob]KZGProof{}, ErrBadArgs
}

recoveredCells := [cellsPerExtBlob]Cell{}
recoveredProofs := [cellsPerExtBlob]KZGProof{}
recoveredCells := [CellsPerExtBlob]Cell{}
recoveredProofs := [CellsPerExtBlob]KZGProof{}
ret := C.recover_cells_and_kzg_proofs(
(*C.Cell)(unsafe.Pointer(&recoveredCells)),
(*C.KZGProof)(unsafe.Pointer(&recoveredProofs)),
Expand All @@ -460,7 +460,7 @@ func RecoverCellsAndKZGProofs(cellIndices []uint64, cells []Cell) ([cellsPerExtB
&settings)

if ret != C.C_KZG_OK {
return [cellsPerExtBlob]Cell{}, [cellsPerExtBlob]KZGProof{}, makeErrorFromRet(ret)
return [CellsPerExtBlob]Cell{}, [CellsPerExtBlob]KZGProof{}, makeErrorFromRet(ret)
}
return recoveredCells, recoveredProofs, nil
}
Expand Down
18 changes: 9 additions & 9 deletions bindings/go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func fillBlobRandom(blob *Blob, seed int64) {
}
}

func getPartialCells(cells [cellsPerExtBlob]Cell, i int) ([]uint64, []Cell) {
func getPartialCells(cells [CellsPerExtBlob]Cell, i int) ([]uint64, []Cell) {
cellIndices := []uint64{}
partialCells := []Cell{}
for j := range cells {
Expand All @@ -61,7 +61,7 @@ func getPartialCells(cells [cellsPerExtBlob]Cell, i int) ([]uint64, []Cell) {
return cellIndices, partialCells
}

func getColumns(blobCommitments []Bytes48, cellRows [][cellsPerExtBlob]Cell, proofRows [][cellsPerExtBlob]Bytes48, numCols int) ([]Bytes48, []uint64, []Cell, []Bytes48) {
func getColumns(blobCommitments []Bytes48, cellRows [][CellsPerExtBlob]Cell, proofRows [][CellsPerExtBlob]Bytes48, numCols int) ([]Bytes48, []uint64, []Cell, []Bytes48) {
var cellCommitments []Bytes48
var cellIndices []uint64
var cells []Cell
Expand Down Expand Up @@ -621,7 +621,7 @@ func TestPartialRecover(t *testing.T) {
require.NoError(t, err)

for i := 1; i <= 5; i++ {
mod := divideRoundUp(cellsPerExtBlob, i)
mod := divideRoundUp(CellsPerExtBlob, i)
cellIndices, partialCells := getPartialCells(cells, mod)
recoveredCells, recoveredProofs, err := RecoverCellsAndKZGProofs(cellIndices, partialCells)
require.NoError(t, err)
Expand All @@ -640,8 +640,8 @@ func Benchmark(b *testing.B) {
commitments := [length]Bytes48{}
proofs := [length]Bytes48{}
fields := [length]Bytes32{}
blobCells := [length][cellsPerExtBlob]Cell{}
blobCellProofs := [length][cellsPerExtBlob]Bytes48{}
blobCells := [length][CellsPerExtBlob]Cell{}
blobCellProofs := [length][CellsPerExtBlob]Bytes48{}

for i := 0; i < length; i++ {
var blob Blob
Expand All @@ -654,10 +654,10 @@ func Benchmark(b *testing.B) {
require.NoError(b, err)
proofs[i] = Bytes48(proof)

tProofs := [cellsPerExtBlob]KZGProof{}
tProofs := [CellsPerExtBlob]KZGProof{}
blobCells[i], tProofs, err = ComputeCellsAndKZGProofs(&blobs[i])
require.NoError(b, err)
blobCellProofs[i] = [cellsPerExtBlob]Bytes48{}
blobCellProofs[i] = [CellsPerExtBlob]Bytes48{}
for j, p := range tProofs {
blobCellProofs[i][j] = Bytes48(p)
}
Expand Down Expand Up @@ -775,7 +775,7 @@ func Benchmark(b *testing.B) {
}

for i := 1; i <= 5; i++ {
mod := divideRoundUp(cellsPerExtBlob, i)
mod := divideRoundUp(CellsPerExtBlob, i)
cellIndices, partialCells := getPartialCells(blobCells[0], mod)
b.Run(fmt.Sprintf("RecoverCellsAndKZGProofs(missing=%v)", i), func(b *testing.B) {
for n := 0; n < b.N; n++ {
Expand Down Expand Up @@ -832,7 +832,7 @@ func Benchmark(b *testing.B) {
})
}

for i := 1; i <= cellsPerExtBlob; i *= 2 {
for i := 1; i <= CellsPerExtBlob; i *= 2 {
cellCommitments, cellIndices, cells, cellProofs := getColumns(commitments[:], blobCells[:], blobCellProofs[:], i)
b.Run(fmt.Sprintf("VerifyColumns(count=%v)", i), func(b *testing.B) {
for n := 0; n < b.N; n++ {
Expand Down

0 comments on commit e689135

Please sign in to comment.