Skip to content

Commit e75f8bf

Browse files
feat: remove old signing
1 parent 2da8c36 commit e75f8bf

File tree

11 files changed

+6
-550
lines changed

11 files changed

+6
-550
lines changed

agglayer/types/types.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -498,50 +498,6 @@ func (c *Certificate) CertificateID() common.Hash {
498498
)
499499
}
500500

501-
// PPHashToSign is the actual hash that needs to be signed by the aggsender
502-
// as expected by the agglayer for the PP flow
503-
func (c *Certificate) PPHashToSign() common.Hash {
504-
globalIndexHashes := make([][]byte, len(c.ImportedBridgeExits))
505-
for i, importedBridgeExit := range c.ImportedBridgeExits {
506-
globalIndexHashes[i] = importedBridgeExit.GlobalIndex.Hash().Bytes()
507-
}
508-
509-
return crypto.Keccak256Hash(
510-
c.NewLocalExitRoot.Bytes(),
511-
crypto.Keccak256Hash(globalIndexHashes...).Bytes(),
512-
)
513-
}
514-
515-
// FEPHashToSign is the actual hash that needs to be signed by the aggsender
516-
// as expected by the agglayer for the FEP flow
517-
func (c *Certificate) FEPHashToSign() common.Hash {
518-
chunks := make([][]byte, 0, len(c.ImportedBridgeExits))
519-
for _, importedBridgeExit := range c.ImportedBridgeExits {
520-
indexBytes := importedBridgeExit.GlobalIndexToLittleEndianBytes()
521-
hashBytes := importedBridgeExit.BridgeExit.Hash().Bytes()
522-
523-
combined := make([]byte, 0, len(indexBytes)+len(hashBytes))
524-
combined = append(combined, indexBytes...) // combine into one slice
525-
combined = append(combined, hashBytes...) // combine into one slice
526-
chunks = append(chunks, combined)
527-
}
528-
529-
importedBridgeExitsHash := crypto.Keccak256(chunks...)
530-
531-
aggchainParams := aggkitcommon.EmptyBytesHash
532-
aggchainDataProof, ok := c.AggchainData.(*AggchainDataProof)
533-
if ok {
534-
aggchainParams = aggchainDataProof.AggchainParams.Bytes()
535-
}
536-
537-
return crypto.Keccak256Hash(
538-
c.NewLocalExitRoot.Bytes(),
539-
importedBridgeExitsHash,
540-
aggkitcommon.Uint64ToLittleEndianBytes(c.Height),
541-
aggchainParams,
542-
)
543-
}
544-
545501
// SignedCertificate is the struct that contains the certificate and the signature of the signer
546502
// NOTE: this is an old and deprecated struct, only to be used for backward compatibility
547503
type SignedCertificate struct {

agglayer/types/types_test.go

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"reflect"
1212
"testing"
1313

14-
"github.com/agglayer/aggkit/bridgesync"
1514
aggkitcommon "github.com/agglayer/aggkit/common"
1615
"github.com/agglayer/aggkit/db"
1716
"github.com/agglayer/aggkit/l1infotreesync"
@@ -549,43 +548,6 @@ func TestCertificate_Hash(t *testing.T) {
549548
require.Equal(t, calculatedHash, expectedHash)
550549
}
551550

552-
func TestCertificate_HashToSign(t *testing.T) {
553-
t.Parallel()
554-
555-
c := &Certificate{
556-
NewLocalExitRoot: common.HexToHash("0xabcd"),
557-
ImportedBridgeExits: []*ImportedBridgeExit{
558-
{
559-
GlobalIndex: &GlobalIndex{
560-
MainnetFlag: true,
561-
RollupIndex: 23,
562-
LeafIndex: 1,
563-
},
564-
},
565-
{
566-
GlobalIndex: &GlobalIndex{
567-
MainnetFlag: false,
568-
RollupIndex: 15,
569-
LeafIndex: 2,
570-
},
571-
},
572-
},
573-
}
574-
575-
globalIndexHashes := make([][]byte, len(c.ImportedBridgeExits))
576-
for i, importedBridgeExit := range c.ImportedBridgeExits {
577-
globalIndexHashes[i] = importedBridgeExit.GlobalIndex.Hash().Bytes()
578-
}
579-
580-
expectedHash := crypto.Keccak256Hash(
581-
c.NewLocalExitRoot[:],
582-
crypto.Keccak256Hash(globalIndexHashes...).Bytes(),
583-
)
584-
585-
certHash := c.PPHashToSign()
586-
require.Equal(t, expectedHash, certHash)
587-
}
588-
589551
func TestClaimFromMainnnet_MarshalJSON(t *testing.T) {
590552
t.Parallel()
591553

@@ -1364,94 +1326,6 @@ func TestAggchainDataMultisigWithProof_MarshalUnmarshalJSON(t *testing.T) {
13641326
}
13651327
}
13661328

1367-
func TestCertificate_FEPHashToSign(t *testing.T) {
1368-
t.Parallel()
1369-
1370-
bridgeExit := &BridgeExit{
1371-
LeafType: LeafTypeAsset,
1372-
TokenInfo: &TokenInfo{
1373-
OriginNetwork: 0,
1374-
OriginTokenAddress: common.HexToAddress("0x1234"),
1375-
},
1376-
DestinationNetwork: 1,
1377-
DestinationAddress: common.HexToAddress("0x1234"),
1378-
Amount: big.NewInt(1000),
1379-
Metadata: []byte{0x01, 0x02, 0x03},
1380-
}
1381-
1382-
testCases := []struct {
1383-
name string
1384-
certificate *Certificate
1385-
expectedHash common.Hash
1386-
}{
1387-
{
1388-
name: "Empty Certificate",
1389-
certificate: &Certificate{},
1390-
expectedHash: crypto.Keccak256Hash(
1391-
common.Hash{}.Bytes(),
1392-
aggkitcommon.EmptyBytesHash,
1393-
aggkitcommon.Uint64ToLittleEndianBytes(0),
1394-
aggkitcommon.EmptyBytesHash,
1395-
),
1396-
},
1397-
{
1398-
name: "With Aggchain Data Proof",
1399-
certificate: &Certificate{
1400-
NewLocalExitRoot: common.HexToHash("0xdef456"),
1401-
Height: 100,
1402-
AggchainData: &AggchainDataProof{
1403-
AggchainParams: common.HexToHash("0x123abc"),
1404-
},
1405-
},
1406-
expectedHash: crypto.Keccak256Hash(
1407-
common.HexToHash("0xdef456").Bytes(),
1408-
aggkitcommon.EmptyBytesHash,
1409-
aggkitcommon.Uint64ToLittleEndianBytes(100),
1410-
common.HexToHash("0x123abc").Bytes(),
1411-
),
1412-
},
1413-
{
1414-
name: "With Imported Bridge Exits",
1415-
certificate: &Certificate{
1416-
NewLocalExitRoot: common.HexToHash("0xdef456"),
1417-
Height: 100,
1418-
ImportedBridgeExits: []*ImportedBridgeExit{
1419-
{
1420-
GlobalIndex: &GlobalIndex{
1421-
MainnetFlag: true,
1422-
RollupIndex: 0,
1423-
LeafIndex: 1,
1424-
},
1425-
BridgeExit: bridgeExit,
1426-
},
1427-
},
1428-
AggchainData: &AggchainDataProof{
1429-
AggchainParams: common.HexToHash("0x123abc"),
1430-
},
1431-
},
1432-
expectedHash: crypto.Keccak256Hash(
1433-
common.HexToHash("0xdef456").Bytes(),
1434-
crypto.Keccak256(aggkitcommon.BigIntToLittleEndianBytes(
1435-
bridgesync.GenerateGlobalIndex(true, 0, 1),
1436-
), bridgeExit.Hash().Bytes()),
1437-
aggkitcommon.Uint64ToLittleEndianBytes(100),
1438-
common.HexToHash("0x123abc").Bytes(),
1439-
),
1440-
},
1441-
}
1442-
1443-
for _, tc := range testCases {
1444-
tc := tc
1445-
1446-
t.Run(tc.name, func(t *testing.T) {
1447-
t.Parallel()
1448-
1449-
hash := tc.certificate.FEPHashToSign()
1450-
require.Equal(t, tc.expectedHash, hash)
1451-
})
1452-
}
1453-
}
1454-
14551329
func TestCertificate_Validate(t *testing.T) {
14561330
t.Run("fails cert nil", func(t *testing.T) {
14571331
var cert *Certificate

aggsender/aggsender_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ func TestSendCertificate_NoClaims(t *testing.T) {
264264
signedCertificate, err := aggSender.sendCertificate(ctx)
265265
require.NoError(t, err)
266266
require.NotNil(t, signedCertificate)
267-
require.NotNil(t, signedCertificate.AggchainData)
268267
require.NotNil(t, signedCertificate.ImportedBridgeExits)
269268
require.Len(t, signedCertificate.BridgeExits, 1)
270269

aggsender/flows/flow_aggchain_prover.go

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,7 @@ func (a *AggchainProverFlow) BuildCertificate(ctx context.Context,
325325
cert.CustomChainData = buildParams.AggchainProof.CustomChainData
326326
}
327327

328-
signedCert, err := a.signCertificate(ctx, cert)
329-
if err != nil {
330-
return nil, fmt.Errorf("aggchainProverFlow - error signing certificate: %w", err)
331-
}
332-
333-
return signedCert, nil
328+
return cert, nil
334329
}
335330

336331
// UpdateAggchainData updates the AggchainData field in certificate with the multisig if needed
@@ -403,48 +398,6 @@ func (a *AggchainProverFlow) getLastProvenBlock(fromBlock uint64, lastCertificat
403398
return fromBlock - 1
404399
}
405400

406-
// signCertificate signs a certificate with the aggsender key
407-
func (a *AggchainProverFlow) signCertificate(
408-
ctx context.Context, cert *agglayertypes.Certificate) (*agglayertypes.Certificate, error) {
409-
aggchainData, ok := cert.AggchainData.(*agglayertypes.AggchainDataProof)
410-
if !ok {
411-
return nil, fmt.Errorf("aggchainProverFlow - signCertificate - AggchainData is not of type AggchainDataProof")
412-
}
413-
414-
hashToSign := cert.FEPHashToSign()
415-
sig, err := a.certificateSigner.SignHash(ctx, hashToSign)
416-
if err != nil {
417-
return nil, err
418-
}
419-
420-
aggchainData.Signature = sig
421-
422-
a.log.Infof("aggchainProverFlow - Signed certificate. Sequencer address: %s. "+
423-
"New local exit root: %s. Aggchain Params: %s. Height: %d Hash signed: %s",
424-
a.certificateSigner.PublicAddress().String(),
425-
cert.NewLocalExitRoot.String(),
426-
aggchainData.AggchainParams.String(),
427-
cert.Height,
428-
hashToSign.String(),
429-
)
430-
431-
return cert, nil
432-
}
433-
434-
// ValidateCertificate validates the certificate for the FEP specific things
435-
func (a *AggchainProverFlow) ValidateCertificate(ctx context.Context, cert *agglayertypes.Certificate) error {
436-
if cert == nil {
437-
return fmt.Errorf("aggchainProverFlow - ValidateCertificate - certificate is nil")
438-
}
439-
440-
_, ok := cert.AggchainData.(*agglayertypes.AggchainDataProof)
441-
if !ok {
442-
return fmt.Errorf("aggchainProverFlow - ValidateCertificate - AggchainData is not of type AggchainDataProof")
443-
}
444-
445-
return nil
446-
}
447-
448401
// Signer returns the signer used to sign the certificate
449402
func (a *AggchainProverFlow) Signer() signertypes.Signer {
450403
return a.certificateSigner

aggsender/flows/flow_aggchain_prover_test.go

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,14 @@ func Test_AggchainProverFlow_BuildCertificate(t *testing.T) {
488488

489489
testCases := []struct {
490490
name string
491-
mockFn func(*mocks.BridgeQuerier, *mocks.LERQuerier, *mocks.Signer)
491+
mockFn func(*mocks.BridgeQuerier, *mocks.LERQuerier)
492492
buildParams *types.CertificateBuildParams
493493
expectedError string
494494
expectedResult *agglayertypes.Certificate
495495
}{
496496
{
497497
name: "error building certificate",
498-
mockFn: func(mockL2BridgeQuerier *mocks.BridgeQuerier, mockLERQuerier *mocks.LERQuerier, mockSigner *mocks.Signer) {
498+
mockFn: func(mockL2BridgeQuerier *mocks.BridgeQuerier, mockLERQuerier *mocks.LERQuerier) {
499499
mockLERQuerier.EXPECT().GetLastLocalExitRoot().Return(types.EmptyLER, nil)
500500
mockL2BridgeQuerier.EXPECT().GetExitRootByIndex(mock.Anything, uint32(0)).Return(common.Hash{}, errors.New("some error"))
501501
},
@@ -510,10 +510,8 @@ func Test_AggchainProverFlow_BuildCertificate(t *testing.T) {
510510
},
511511
{
512512
name: "success building certificate",
513-
mockFn: func(mockL2BridgeQuerier *mocks.BridgeQuerier, mockLERQuerier *mocks.LERQuerier, mockSigner *mocks.Signer) {
513+
mockFn: func(mockL2BridgeQuerier *mocks.BridgeQuerier, mockLERQuerier *mocks.LERQuerier) {
514514
mockL2BridgeQuerier.EXPECT().OriginNetwork().Return(uint32(1))
515-
mockSigner.EXPECT().PublicAddress().Return(common.HexToAddress("0x123"))
516-
mockSigner.EXPECT().SignHash(mock.Anything, mock.Anything).Return([]byte("signature"), nil)
517515
mockLERQuerier.EXPECT().GetLastLocalExitRoot().Return(types.EmptyLER, nil)
518516
},
519517
buildParams: &types.CertificateBuildParams{
@@ -557,7 +555,6 @@ func Test_AggchainProverFlow_BuildCertificate(t *testing.T) {
557555
Context: map[string][]byte{
558556
"key1": []byte("value1"),
559557
},
560-
Signature: []byte("signature"),
561558
},
562559
},
563560
},
@@ -572,7 +569,7 @@ func Test_AggchainProverFlow_BuildCertificate(t *testing.T) {
572569
mockL2BridgeQuerier := mocks.NewBridgeQuerier(t)
573570
mockLERQuerier := mocks.NewLERQuerier(t)
574571
if tc.mockFn != nil {
575-
tc.mockFn(mockL2BridgeQuerier, mockLERQuerier, mockSigner)
572+
tc.mockFn(mockL2BridgeQuerier, mockLERQuerier)
576573
}
577574
flowBase := NewBaseFlow(
578575
logger,
@@ -781,73 +778,6 @@ func Test_AggchainProverFlow_CheckInitialStatus(t *testing.T) {
781778
}
782779
}
783780

784-
func Test_AggchainProverFlow_ValidateCertificate(t *testing.T) {
785-
t.Parallel()
786-
787-
ctx := t.Context()
788-
789-
testCases := []struct {
790-
name string
791-
certificate *agglayertypes.Certificate
792-
expectedError string
793-
}{
794-
{
795-
name: "certificate is nil",
796-
certificate: nil,
797-
expectedError: "aggchainProverFlow - ValidateCertificate - certificate is nil",
798-
},
799-
{
800-
name: "AggchainData is not of type AggchainDataProof",
801-
certificate: &agglayertypes.Certificate{
802-
AggchainData: &agglayertypes.AggchainDataSignature{},
803-
},
804-
expectedError: "aggchainProverFlow - ValidateCertificate - AggchainData is not of type AggchainDataProof",
805-
},
806-
{
807-
name: "AggchainData is nil",
808-
certificate: &agglayertypes.Certificate{
809-
AggchainData: nil,
810-
},
811-
expectedError: "aggchainProverFlow - ValidateCertificate - AggchainData is not of type AggchainDataProof",
812-
},
813-
{
814-
name: "success - valid certificate with AggchainDataProof",
815-
certificate: &agglayertypes.Certificate{
816-
AggchainData: &agglayertypes.AggchainDataProof{
817-
Proof: []byte("some-proof"),
818-
Version: "0.1",
819-
Vkey: []byte("some-vkey"),
820-
AggchainParams: common.HexToHash("0x123"),
821-
Context: map[string][]byte{
822-
"key1": []byte("value1"),
823-
},
824-
Signature: []byte("signature"),
825-
},
826-
},
827-
expectedError: "",
828-
},
829-
}
830-
831-
for _, tc := range testCases {
832-
tc := tc
833-
t.Run(tc.name, func(t *testing.T) {
834-
t.Parallel()
835-
836-
logger := log.WithFields("flowManager", "Test_AggchainProverFlow_ValidateCertificate")
837-
flow := &AggchainProverFlow{
838-
log: logger,
839-
}
840-
841-
err := flow.ValidateCertificate(ctx, tc.certificate)
842-
if tc.expectedError != "" {
843-
require.ErrorContains(t, err, tc.expectedError)
844-
} else {
845-
require.NoError(t, err)
846-
}
847-
})
848-
}
849-
}
850-
851781
func Test_AggchainProverFlow_GenerateBuildParams(t *testing.T) {
852782
t.Parallel()
853783

0 commit comments

Comments
 (0)