-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f72caae
commit fc3467a
Showing
5 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// | ||
// Copyright (C) 2024, Berachain Foundation. All rights reserved. | ||
// Use of this software is governed by the Business Source License included | ||
// in the LICENSE file of this repository and at www.mariadb.com/bsl11. | ||
// | ||
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY | ||
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER | ||
// VERSIONS OF THE LICENSED WORK. | ||
// | ||
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF | ||
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF | ||
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). | ||
// | ||
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON | ||
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, | ||
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND | ||
// TITLE. | ||
|
||
package kzg_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/berachain/beacon-kit/mod/da/pkg/kzg" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDefaultConfig(t *testing.T) { | ||
cfg := kzg.DefaultConfig() | ||
require.Equal( | ||
t, | ||
"./testing/files/kzg-trusted-setup.json", | ||
cfg.TrustedSetupPath, | ||
) | ||
require.Equal( | ||
t, | ||
"crate-crypto/go-kzg-4844", | ||
cfg.Implementation, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// | ||
// Copyright (C) 2024, Berachain Foundation. All rights reserved. | ||
// Use of this software is governed by the Business Source License included | ||
// in the LICENSE file of this repository and at www.mariadb.com/bsl11. | ||
// | ||
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY | ||
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER | ||
// VERSIONS OF THE LICENSED WORK. | ||
// | ||
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF | ||
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF | ||
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). | ||
// | ||
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON | ||
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, | ||
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND | ||
// TITLE. | ||
|
||
package kzg_test | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/berachain/beacon-kit/mod/da/pkg/kzg" | ||
"github.com/berachain/beacon-kit/mod/da/pkg/kzg/ckzg" | ||
"github.com/berachain/beacon-kit/mod/da/pkg/kzg/gokzg" | ||
"github.com/berachain/beacon-kit/mod/da/pkg/types" | ||
"github.com/berachain/beacon-kit/mod/primitives/pkg/eip4844" | ||
gokzg4844 "github.com/crate-crypto/go-kzg-4844" | ||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var baseDir = "../../../../testing/files/" | ||
|
||
func TestNewBlobProofVerifier_KzgImpl(t *testing.T) { | ||
ts, err := loadTrustedSetupFromFile() | ||
require.NoError(t, err) | ||
|
||
verifier, err := kzg.NewBlobProofVerifier(gokzg.Implementation, ts) | ||
require.NoError(t, err) | ||
require.NotNil(t, verifier) | ||
require.Equal(t, gokzg.Implementation, verifier.GetImplementation()) | ||
} | ||
|
||
func TestNewBlobProofVerifier_CkzgImpl(t *testing.T) { | ||
ts, err := loadTrustedSetupFromFile() | ||
require.NoError(t, err) | ||
|
||
verifier, err := kzg.NewBlobProofVerifier(ckzg.Implementation, ts) | ||
require.NoError(t, err) | ||
require.NotNil(t, verifier) | ||
require.Equal(t, ckzg.Implementation, verifier.GetImplementation()) | ||
} | ||
|
||
func TestNewBlobProofVerifier_InvalidImpl(t *testing.T) { | ||
ts, err := loadTrustedSetupFromFile() | ||
require.NoError(t, err) | ||
|
||
invalidImpl := "invalid-implementation" | ||
_, err = kzg.NewBlobProofVerifier(invalidImpl, ts) | ||
require.ErrorIs(t, err, kzg.ErrUnsupportedKzgImplementation) | ||
} | ||
|
||
// loadTrustedSetupFromFile is the helper function. | ||
func loadTrustedSetupFromFile() (*gokzg4844.JSONTrustedSetup, error) { | ||
fileName := "kzg-trusted-setup.json" | ||
fullPath := filepath.Join(baseDir, fileName) | ||
data, err := os.ReadFile(fullPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ts gokzg4844.JSONTrustedSetup | ||
err = json.Unmarshal(data, &ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ts, nil | ||
} | ||
|
||
func TestArgsFromSidecars(t *testing.T) { | ||
fs := afero.NewOsFs() | ||
fullPath := filepath.Join(baseDir, "test_data.json") | ||
file, err := afero.ReadFile(fs, fullPath) | ||
require.NoError(t, err) | ||
|
||
type Data struct { | ||
Input struct { | ||
Blob string `json:"blob"` | ||
Commitment string `json:"commitment"` | ||
Proof string `json:"proof"` | ||
} `json:"input"` | ||
} | ||
var data Data | ||
|
||
err = json.Unmarshal(file, &data) | ||
require.NoError(t, err) | ||
|
||
scs := &types.BlobSidecars{ | ||
Sidecars: []*types.BlobSidecar{ | ||
{ | ||
Blob: eip4844.Blob{data.Input.Blob[0]}, | ||
KzgProof: eip4844.KZGProof{data.Input.Proof[0]}, | ||
KzgCommitment: eip4844.KZGCommitment{data.Input.Commitment[0]}, | ||
}, | ||
}, | ||
} | ||
|
||
args := kzg.ArgsFromSidecars(scs) | ||
|
||
require.Len(t, args.Blobs, 1) | ||
require.Len(t, args.Proofs, 1) | ||
require.Len(t, args.Commitments, 1) | ||
} |