Skip to content

Commit

Permalink
Adopt CertVerifier naming scheme (Layr-Labs#1157)
Browse files Browse the repository at this point in the history
Signed-off-by: litt3 <[email protected]>
  • Loading branch information
litt3 authored Jan 24, 2025
1 parent ce2ff6d commit 99de530
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 165 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions api/clients/v2/payload_retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/Layr-Labs/eigenda/api/clients/codecs"
"github.com/Layr-Labs/eigenda/api/clients/v2/verification"
"github.com/Layr-Labs/eigenda/common/geth"
contractEigenDABlobVerifier "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDABlobVerifier"
verifiercontract "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDABlobVerifier"
core "github.com/Layr-Labs/eigenda/core/v2"
"github.com/Layr-Labs/eigenda/encoding"
"github.com/Layr-Labs/eigensdk-go/logging"
Expand All @@ -33,7 +33,7 @@ type PayloadRetriever struct {
codec codecs.BlobCodec
relayClient RelayClient
g1Srs []bn254.G1Affine
blobVerifier verification.IBlobVerifier
certVerifier verification.ICertVerifier
}

// BuildPayloadRetriever builds a PayloadRetriever from config structs.
Expand All @@ -54,9 +54,9 @@ func BuildPayloadRetriever(
return nil, fmt.Errorf("new eth client: %w", err)
}

blobVerifier, err := verification.NewBlobVerifier(*ethClient, payloadRetrieverConfig.EigenDABlobVerifierAddr)
certVerifier, err := verification.NewCertVerifier(*ethClient, payloadRetrieverConfig.EigenDACertVerifierAddr)
if err != nil {
return nil, fmt.Errorf("new blob verifier: %w", err)
return nil, fmt.Errorf("new cert verifier: %w", err)
}

codec, err := createCodec(payloadRetrieverConfig)
Expand All @@ -69,7 +69,7 @@ func BuildPayloadRetriever(
rand.New(rand.NewSource(rand.Int63())),
payloadRetrieverConfig,
relayClient,
blobVerifier,
certVerifier,
codec,
g1Srs)
}
Expand All @@ -80,7 +80,7 @@ func NewPayloadRetriever(
random *rand.Rand,
payloadRetrieverConfig *PayloadRetrieverConfig,
relayClient RelayClient,
blobVerifier verification.IBlobVerifier,
certVerifier verification.ICertVerifier,
codec codecs.BlobCodec,
g1Srs []bn254.G1Affine) (*PayloadRetriever, error) {

Expand All @@ -90,7 +90,7 @@ func NewPayloadRetriever(
payloadRetrieverConfig: payloadRetrieverConfig,
codec: codec,
relayClient: relayClient,
blobVerifier: blobVerifier,
certVerifier: certVerifier,
g1Srs: g1Srs,
}, nil
}
Expand All @@ -110,14 +110,14 @@ func (pr *PayloadRetriever) GetPayload(
return nil, fmt.Errorf("verify cert with timeout for blobKey %v: %w", blobKey, err)
}

relayKeys := eigenDACert.BlobVerificationProof.BlobCertificate.RelayKeys
relayKeys := eigenDACert.BlobInclusionInfo.BlobCertificate.RelayKeys
relayKeyCount := len(relayKeys)
if relayKeyCount == 0 {
return nil, errors.New("relay key count is zero")
}

blobCommitments, err := blobCommitmentsBindingToInternal(
&eigenDACert.BlobVerificationProof.BlobCertificate.BlobHeader.Commitment)
&eigenDACert.BlobInclusionInfo.BlobCertificate.BlobHeader.Commitment)

if err != nil {
return nil, fmt.Errorf("blob commitments binding to internal: %w", err)
Expand All @@ -142,16 +142,16 @@ func (pr *PayloadRetriever) GetPayload(

err = pr.verifyBlobAgainstCert(blobKey, relayKey, blob, blobCommitments.Commitment, blobCommitments.Length)

// An honest relay should never send a blob which doesn't verify
// An honest relay should never send a blob which doesn't verify against the cert
if err != nil {
pr.log.Warn("verify blob from relay: %w", err)
pr.log.Warn("verify blob from relay against cert: %w", err)
continue
}

payload, err := pr.codec.DecodeBlob(blob)
if err != nil {
pr.log.Error(
`Blob verification was successful, but decode blob failed!
`Cert verification was successful, but decode blob failed!
This is likely a problem with the local blob codec configuration,
but could potentially indicate a maliciously generated blob certificate.
It should not be possible for an honestly generated certificate to verify
Expand Down Expand Up @@ -230,7 +230,7 @@ func (pr *PayloadRetriever) getBlobWithTimeout(
return pr.relayClient.GetBlob(timeoutCtx, relayKey, blobKey)
}

// verifyCertWithTimeout verifies an EigenDACert by making a call to VerifyBlobV2.
// verifyCertWithTimeout verifies an EigenDACert by making a call to VerifyCertV2.
//
// This method times out after the duration configured in payloadRetrieverConfig.ContractCallTimeout
func (pr *PayloadRetriever) verifyCertWithTimeout(
Expand All @@ -240,7 +240,7 @@ func (pr *PayloadRetriever) verifyCertWithTimeout(
timeoutCtx, cancel := context.WithTimeout(ctx, pr.payloadRetrieverConfig.ContractCallTimeout)
defer cancel()

return pr.blobVerifier.VerifyBlobV2(timeoutCtx, eigenDACert)
return pr.certVerifier.VerifyCertV2(timeoutCtx, eigenDACert)
}

// Close is responsible for calling close on all internal clients. This method will do its best to close all internal
Expand Down Expand Up @@ -282,7 +282,7 @@ func createCodec(config *PayloadRetrieverConfig) (codecs.BlobCodec, error) {
// blobCommitmentsBindingToInternal converts a blob commitment from an eigenDA cert into the internal
// encoding.BlobCommitments type
func blobCommitmentsBindingToInternal(
blobCommitmentBinding *contractEigenDABlobVerifier.BlobCommitment,
blobCommitmentBinding *verifiercontract.BlobCommitment,
) (*encoding.BlobCommitments, error) {

blobCommitment, err := encoding.BlobCommitmentsFromProtobuf(
Expand Down
4 changes: 2 additions & 2 deletions api/clients/v2/payload_retriever_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type PayloadRetrieverConfig struct {
// The Ethereum RPC URL to use for querying the Ethereum blockchain.
EthRpcUrl string

// The address of the EigenDABlobVerifier contract
EigenDABlobVerifierAddr string
// The address of the EigenDACertVerifier contract
EigenDACertVerifierAddr string

// PayloadPolynomialForm is the initial form of a Payload after being encoded. The configured form does not imply
// any restrictions on the contents of a payload: it merely dictates how payload data is treated after being
Expand Down
64 changes: 32 additions & 32 deletions api/clients/v2/test/payload_retriever_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type PayloadRetrieverTester struct {
Random *testrandom.TestRandom
PayloadRetriever *clients.PayloadRetriever
MockRelayClient *clientsmock.MockRelayClient
MockBlobVerifier *clientsmock.MockBlobVerifier
MockCertVerifier *clientsmock.MockCertVerifier
Codec *codecs.DefaultBlobCodec
G1Srs []bn254.G1Affine
}
Expand All @@ -52,7 +52,7 @@ func buildPayloadRetrieverTester(t *testing.T) PayloadRetrieverTester {
mockRelayClient := clientsmock.MockRelayClient{}
codec := codecs.NewDefaultBlobCodec()

mockBlobVerifier := clientsmock.MockBlobVerifier{}
mockCertVerifier := clientsmock.MockCertVerifier{}

random := testrandom.NewTestRandom(t)

Expand All @@ -65,7 +65,7 @@ func buildPayloadRetrieverTester(t *testing.T) PayloadRetrieverTester {
random.Rand,
clientConfig,
&mockRelayClient,
&mockBlobVerifier,
&mockCertVerifier,
&codec,
g1Srs)

Expand All @@ -76,7 +76,7 @@ func buildPayloadRetrieverTester(t *testing.T) PayloadRetrieverTester {
Random: random,
PayloadRetriever: client,
MockRelayClient: &mockRelayClient,
MockBlobVerifier: &mockBlobVerifier,
MockCertVerifier: &mockCertVerifier,
Codec: &codec,
G1Srs: g1Srs,
}
Expand Down Expand Up @@ -131,11 +131,11 @@ func buildBlobAndCert(
BlobCertificate: blobCertificate,
}

verificationProof, err := verification.VerificationProofProtoToBinding(inclusionInfo)
convertedInclusionInfo, err := verification.InclusionInfoProtoToBinding(inclusionInfo)
require.NoError(t, err)

return blobKey, blobBytes, &verification.EigenDACert{
BlobVerificationProof: *verificationProof,
BlobInclusionInfo: *convertedInclusionInfo,
}
}

Expand All @@ -147,8 +147,8 @@ func TestGetPayloadSuccess(t *testing.T) {
blobKey, blobBytes, blobCert := buildBlobAndCert(t, tester, relayKeys)

tester.MockRelayClient.On("GetBlob", mock.Anything, relayKeys[0], blobKey).Return(blobBytes, nil).Once()
tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand All @@ -172,8 +172,8 @@ func TestRelayCallTimeout(t *testing.T) {
relayKeys[0] = tester.Random.Uint32()
blobKey, _, blobCert := buildBlobAndCert(t, tester, relayKeys)

tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -248,8 +248,8 @@ func TestRandomRelayRetries(t *testing.T) {
tester.MockRelayClient.On("GetBlob", mock.Anything, mock.MatchedBy(onlineKeyMatcher), blobKey).Return(
blobBytes,
nil)
tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -286,8 +286,8 @@ func TestNoRelayResponse(t *testing.T) {
blobKey, _, blobCert := buildBlobAndCert(t, tester, relayKeys)

tester.MockRelayClient.On("GetBlob", mock.Anything, mock.Anything, blobKey).Return(nil, fmt.Errorf("offline relay"))
tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand All @@ -307,8 +307,8 @@ func TestNoRelayResponse(t *testing.T) {
func TestNoRelays(t *testing.T) {
tester := buildPayloadRetrieverTester(t)

tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -340,8 +340,8 @@ func TestGetBlobReturns0Len(t *testing.T) {
tester.MockRelayClient.On("GetBlob", mock.Anything, mock.Anything, blobKey).Return(
blobBytes,
nil).Once()
tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -369,8 +369,8 @@ func TestGetBlobReturnsDifferentBlob(t *testing.T) {

tester.MockRelayClient.On("GetBlob", mock.Anything, mock.Anything, blobKey1).Return(blobBytes2, nil).Once()
tester.MockRelayClient.On("GetBlob", mock.Anything, mock.Anything, blobKey1).Return(blobBytes1, nil).Once()
tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -402,8 +402,8 @@ func TestGetBlobReturnsInvalidBlob(t *testing.T) {

tester.MockRelayClient.On("GetBlob", mock.Anything, mock.Anything, blobKey).Return(tooLongBytes, nil).Once()
tester.MockRelayClient.On("GetBlob", mock.Anything, mock.Anything, blobKey).Return(blobBytes, nil).Once()
tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand All @@ -422,8 +422,8 @@ func TestGetBlobReturnsInvalidBlob(t *testing.T) {
tester.MockRelayClient.AssertExpectations(t)
}

// TestBlobFailsVerifyBlobV2 tests what happens if cert verification fails
func TestBlobFailsVerifyBlobV2(t *testing.T) {
// TestBlobFailsVerifyCertV2 tests what happens if cert verification fails
func TestBlobFailsVerifyCertV2(t *testing.T) {
tester := buildPayloadRetrieverTester(t)
relayCount := 10
relayKeys := make([]core.RelayKey, relayCount)
Expand All @@ -435,8 +435,8 @@ func TestBlobFailsVerifyBlobV2(t *testing.T) {
tooLongBytes := make([]byte, len(blobBytes)+100)
copy(tooLongBytes[:], blobBytes)

tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -464,11 +464,11 @@ func TestGetBlobReturnsBlobWithInvalidLen(t *testing.T) {

blobKey, blobBytes, blobCert := buildBlobAndCert(t, tester, relayKeys)

blobCert.BlobVerificationProof.BlobCertificate.BlobHeader.Commitment.DataLength--
blobCert.BlobInclusionInfo.BlobCertificate.BlobHeader.Commitment.DataLength--

tester.MockRelayClient.On("GetBlob", mock.Anything, mock.Anything, blobKey).Return(blobBytes, nil).Once()
tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -505,16 +505,16 @@ func TestFailedDecoding(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, maliciousCommitment)

blobCert.BlobVerificationProof.BlobCertificate.BlobHeader.Commitment.Commitment = contractEigenDABlobVerifier.BN254G1Point{
blobCert.BlobInclusionInfo.BlobCertificate.BlobHeader.Commitment.Commitment = contractEigenDABlobVerifier.BN254G1Point{
X: maliciousCommitment.X.BigInt(new(big.Int)),
Y: maliciousCommitment.Y.BigInt(new(big.Int)),
}

tester.MockRelayClient.On("GetBlob", mock.Anything, mock.Anything, blobKey).Return(
blobBytes,
nil).Once()
tester.MockBlobVerifier.On(
"VerifyBlobV2",
tester.MockCertVerifier.On(
"VerifyCertV2",
mock.Anything,
mock.Anything,
mock.Anything,
Expand Down
Loading

0 comments on commit 99de530

Please sign in to comment.