@@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/Layr-Labs/eigenda-proxy/common/consts"
12
12
"github.com/Layr-Labs/eigenda/api/grpc/disperser"
13
+ v1_verifier_binding "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDACertVerifierV1"
13
14
edsm_binding "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAServiceManager"
14
15
binding "github.com/Layr-Labs/eigenda/contracts/bindings/IEigenDACertVerifierLegacy"
15
16
"github.com/Layr-Labs/eigensdk-go/logging"
@@ -22,6 +23,13 @@ import (
22
23
"golang.org/x/exp/slices"
23
24
)
24
25
26
+ // SecurityParamReader is an interface used reading quorums and thresholds from either
27
+ // the EigenDAServiceManager or EigenDACertVerifierV1 contracts
28
+ type SecurityParamReader interface {
29
+ QuorumAdversaryThresholdPercentages (opts * bind.CallOpts ) ([]byte , error )
30
+ QuorumNumbersRequired (opts * bind.CallOpts ) ([]uint8 , error )
31
+ }
32
+
25
33
// CertVerifier verifies the DA certificate against on-chain EigenDA contracts
26
34
// to ensure disperser returned fields haven't been tampered with
27
35
type CertVerifier struct {
@@ -34,9 +42,12 @@ type CertVerifier struct {
34
42
// (typically 64 blocks in happy case).
35
43
ethConfirmationDepth uint64
36
44
waitForFinalization bool
37
- manager * edsm_binding.ContractEigenDAServiceManagerCaller
38
- ethClient * ethclient.Client
39
- // The two fields below are fetched from the EigenDAServiceManager contract in the constructor.
45
+ svcManagerCaller * edsm_binding.ContractEigenDAServiceManagerCaller
46
+
47
+ securityParamReader SecurityParamReader
48
+ ethClient * ethclient.Client
49
+ // The two fields below are fetched from the EigenDAServiceManager contract or
50
+ // the EigenDACertVerifierV1 (if configured) in the constructor.
40
51
// They are used to verify the quorums in the received certificates.
41
52
// See getQuorumParametersAtLatestBlock for more details.
42
53
quorumsRequired []uint8
@@ -57,20 +68,36 @@ func NewCertVerifier(cfg *Config, log logging.Logger) (*CertVerifier, error) {
57
68
return nil , fmt .Errorf ("failed to dial ETH RPC node: %s" , err .Error ())
58
69
}
59
70
60
- // construct caller binding
61
- m , err := edsm_binding .NewContractEigenDAServiceManagerCaller (common .HexToAddress (cfg .SvcManagerAddr ), client )
71
+ // construct caller bindings
72
+ svcManagerCaller , err := edsm_binding .NewContractEigenDAServiceManagerCaller (
73
+ common .HexToAddress (cfg .SvcManagerAddr ), client )
62
74
if err != nil {
63
75
return nil , err
64
76
}
65
77
66
- quorumsRequired , quorumAdversaryThresholds , err := getQuorumParametersAtLatestBlock (m )
78
+ // If the user has specified a custom cert verifier, use it.
79
+ var securityParamReader SecurityParamReader = svcManagerCaller
80
+ if cfg .CertVerifierV1Addr != "" {
81
+ log .Infof ("Using custom EigenDACertVerifierV1 contract for cert verification at address: %s" , cfg .CertVerifierV1Addr )
82
+ certVerifierCallerV1 , err := v1_verifier_binding .NewContractEigenDACertVerifierV1Caller (
83
+ common .HexToAddress (cfg .CertVerifierV1Addr ), client ,
84
+ )
85
+ if err != nil {
86
+ return nil , fmt .Errorf ("failed to create EigenDACertVerifierV1 caller: %w" , err )
87
+ }
88
+
89
+ securityParamReader = certVerifierCallerV1
90
+ }
91
+
92
+ quorumsRequired , quorumAdversaryThresholds , err := getQuorumParametersAtLatestBlock (securityParamReader )
67
93
if err != nil {
68
94
return nil , fmt .Errorf ("failed to fetch quorum parameters from EigenDAServiceManager: %w" , err )
69
95
}
70
96
71
97
return & CertVerifier {
72
98
log : log ,
73
- manager : m ,
99
+ svcManagerCaller : svcManagerCaller ,
100
+ securityParamReader : securityParamReader ,
74
101
ethConfirmationDepth : cfg .EthConfirmationDepth ,
75
102
ethClient : client ,
76
103
quorumsRequired : quorumsRequired ,
@@ -198,7 +225,7 @@ func (cv *CertVerifier) retrieveBatchMetadataHash(
198
225
batchID uint32 ,
199
226
blockNumber * big.Int ,
200
227
) ([32 ]byte , error ) {
201
- onchainHash , err := cv .manager .BatchIdToBatchMetadataHash (
228
+ onchainHash , err := cv .svcManagerCaller .BatchIdToBatchMetadataHash (
202
229
& bind.CallOpts {Context : ctx , BlockNumber : blockNumber },
203
230
batchID ,
204
231
)
@@ -228,17 +255,17 @@ func (cv *CertVerifier) retrieveBatchMetadataHash(
228
255
// in the past,
229
256
// which was not ideal. So we decided to make these parameters immutable, and cache them here.
230
257
func getQuorumParametersAtLatestBlock (
231
- manager * edsm_binding. ContractEigenDAServiceManagerCaller ,
258
+ reader SecurityParamReader ,
232
259
) ([]uint8 , map [uint8 ]uint8 , error ) {
233
260
ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
234
261
defer cancel ()
235
- requiredQuorums , err := manager .QuorumNumbersRequired (& bind.CallOpts {Context : ctx })
262
+ requiredQuorums , err := reader .QuorumNumbersRequired (& bind.CallOpts {Context : ctx })
236
263
if err != nil {
237
264
return nil , nil , fmt .Errorf ("failed to fetch QuorumNumbersRequired from EigenDAServiceManager: %w" , err )
238
265
}
239
266
ctx , cancel = context .WithTimeout (context .Background (), 5 * time .Second )
240
267
defer cancel ()
241
- thresholds , err := manager .QuorumAdversaryThresholdPercentages (& bind.CallOpts {Context : ctx })
268
+ thresholds , err := reader .QuorumAdversaryThresholdPercentages (& bind.CallOpts {Context : ctx })
242
269
if err != nil {
243
270
return nil , nil , fmt .Errorf (
244
271
"failed to fetch QuorumAdversaryThresholdPercentages from EigenDAServiceManager: %w" ,
0 commit comments