From 196085c5c370b8844068ec2e589f6413a77c300a Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 20 Dec 2024 17:33:32 -0800 Subject: [PATCH] refactor: check Address type not string --- core/auth/v2/authenticator.go | 11 +++++++---- core/auth/v2/signer_test.go | 1 - 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/auth/v2/authenticator.go b/core/auth/v2/authenticator.go index ecd8b0ba7..4f507aec8 100644 --- a/core/auth/v2/authenticator.go +++ b/core/auth/v2/authenticator.go @@ -6,6 +6,7 @@ import ( "fmt" core "github.com/Layr-Labs/eigenda/core/v2" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" ) @@ -37,9 +38,10 @@ func (*authenticator) AuthenticateBlobRequest(header *core.BlobHeader) error { } accountId := header.PaymentMetadata.AccountID - pubKey := crypto.PubkeyToAddress(*sigPublicKeyECDSA).Hex() + accountAddr := common.HexToAddress(accountId) + pubKeyAddr := crypto.PubkeyToAddress(*sigPublicKeyECDSA) - if pubKey != accountId { + if accountAddr.Cmp(pubKeyAddr) != 0 { return errors.New("signature doesn't match with provided public key") } @@ -59,9 +61,10 @@ func (*authenticator) AuthenticatePaymentStateRequest(sig []byte, accountId stri return fmt.Errorf("failed to recover public key from signature: %v", err) } - pubKey := crypto.PubkeyToAddress(*sigPublicKeyECDSA).Hex() + accountAddr := common.HexToAddress(accountId) + pubKeyAddr := crypto.PubkeyToAddress(*sigPublicKeyECDSA) - if pubKey != accountId { + if accountAddr.Cmp(pubKeyAddr) != 0 { return errors.New("signature doesn't match with provided public key") } diff --git a/core/auth/v2/signer_test.go b/core/auth/v2/signer_test.go index f49b1cfb0..9c31d1a81 100644 --- a/core/auth/v2/signer_test.go +++ b/core/auth/v2/signer_test.go @@ -8,7 +8,6 @@ import ( func TestGetAccountID(t *testing.T) { // Test case with known private key and expected account ID - // privateKey := "73ae7e3a40b59caacb1cda8fa04f4e7fa5bb2b37101f9f3506290c201f57bf7b" privateKey := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcded" expectedAccountID := "0x1aa8226f6d354380dDE75eE6B634875c4203e522"