Skip to content

Commit 8a55536

Browse files
feat: add validate ger functions to service and client
1 parent 299d6e3 commit 8a55536

15 files changed

+428
-237
lines changed

aggsender/aggsender_validator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
aggkitcommon "github.com/agglayer/aggkit/common"
1212
"github.com/agglayer/aggkit/grpc"
1313
signertypes "github.com/agglayer/go_signer/signer/types"
14+
"github.com/ethereum/go-ethereum/common"
1415
)
1516

1617
var (
@@ -63,3 +64,8 @@ func (a *AggsenderValidator) Start(ctx context.Context) {
6364
func (a *AggsenderValidator) ValidateCertificate(ctx context.Context, params types.VerifyIncomingRequest) error {
6465
return a.validator.ValidateCertificate(ctx, params)
6566
}
67+
68+
// ValidateGER validates the GlobalExitRoot that needs to be injected.
69+
func (a *AggsenderValidator) ValidateGER(ctx context.Context, ger common.Hash) error {
70+
return a.validator.ValidateGER(ctx, ger)
71+
}

aggsender/mocks/mock_certificate_validate_and_signer.go

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggsender/mocks/mock_certificate_validator.go

Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggsender/mocks/mock_validator_client.go

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggsender/types/interfaces.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func (h *HealthCheckResponse) String() string {
257257

258258
type CertificateValidator interface {
259259
ValidateCertificate(ctx context.Context, params VerifyIncomingRequest) error
260+
ValidateGER(ctx context.Context, ger common.Hash) error
260261
}
261262

262263
// CertificateValidateAndSigner is an interface to attach a certificate validator and signer
@@ -270,10 +271,19 @@ type CertificateValidateAndSigner interface {
270271
certificate *agglayertypes.Certificate,
271272
lastL2BlockInCert uint64,
272273
) ([]byte, error)
274+
// URL returns the URL of the validator service
273275
URL() string
276+
// String returns a string representation of the validator service
274277
String() string
278+
// Address returns the Ethereum address of the validator
275279
Address() common.Address
280+
// Index returns the index of the validator in the signers list
276281
Index() uint32
282+
// ValidateAndSignGER validates the GlobalExitRoot that needs to be injected and signs it if valid.
283+
ValidateAndSignGER(
284+
ctx context.Context,
285+
ger common.Hash,
286+
) ([]byte, error)
277287
}
278288

279289
// ValidatorClient is an interface defining functions that a ValidatorClient should implement
@@ -285,6 +295,10 @@ type ValidatorClient interface {
285295
certificate *agglayertypes.Certificate,
286296
lastL2BlockInCert uint64,
287297
) ([]byte, error)
298+
ValidateGER(
299+
ctx context.Context,
300+
ger common.Hash,
301+
) ([]byte, error)
288302
}
289303

290304
// LocalExitRootQuery is an interface defining functions that a LocalExitRootQuery should implement

aggsender/validator/local_validator.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ func (a *LocalValidator) ValidateAndSignCertificate(
9999
return aggkitcommon.EmptySignature, nil
100100
}
101101

102+
// ValidateAndSignGER validates the GlobalExitRoot that needs to be injected.
103+
// LocalValidator does not sign the GER, it just validates it.
104+
func (a *LocalValidator) ValidateAndSignGER(
105+
ctx context.Context,
106+
ger common.Hash,
107+
) ([]byte, error) {
108+
a.log.Infof("GER validation: %s ....", ger.Hex())
109+
110+
err := a.validator.ValidateGER(ctx, ger)
111+
if err != nil {
112+
a.log.Errorf("GER %s validation failed: %s", ger.Hex(), err.Error())
113+
return nil, fmt.Errorf("GER %s validation failed: %w", ger.Hex(), err)
114+
}
115+
116+
a.log.Infof("GER %s validation passed", ger.Hex())
117+
118+
// local validator does not sign the GER, it just validates it
119+
return aggkitcommon.EmptySignature, nil
120+
}
121+
102122
// getPreviousCertificate retrieves the previous certificate based on the new certificate's height.
103123
func getPreviousCertificate(
104124
storage db.AggSenderStorage,

0 commit comments

Comments
 (0)