From 046bc775cd932cb9eb04756665a158b9414be205 Mon Sep 17 00:00:00 2001 From: aloknerurkar Date: Thu, 12 Dec 2024 21:47:35 +0530 Subject: [PATCH] fix: txn opts for BLS registration and errors (#531) * chore: add errors to verification * chore: add errors to verification * chore: add errors to verification --------- Co-authored-by: Alok --- contracts/contracts/core/ProviderRegistry.sol | 8 ++++---- contracts/contracts/interfaces/IProviderRegistry.sol | 3 +++ p2p/pkg/rpc/provider/service.go | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/contracts/contracts/core/ProviderRegistry.sol b/contracts/contracts/core/ProviderRegistry.sol index bfc2de042..01c062e67 100644 --- a/contracts/contracts/core/ProviderRegistry.sol +++ b/contracts/contracts/core/ProviderRegistry.sol @@ -245,16 +245,16 @@ contract ProviderRegistry is ) external { address provider = msg.sender; - require(providerRegistered[provider], "Provider not registered"); - require(blsPublicKey.length == 48, "Public key must be 48 bytes"); - require(signature.length == 96, "Signature must be 96 bytes"); + require(providerRegistered[provider], ProviderNotRegistered(provider)); + require(blsPublicKey.length == 48, PublicKeyLengthInvalid(48, blsPublicKey.length)); + require(signature.length == 96, SignatureLengthInvalid(96, signature.length)); bytes32 message = keccak256(abi.encodePacked(provider)); // Verify the BLS signature bool isValid = verifySignature(blsPublicKey, message, signature); - require(isValid, "Invalid BLS signature"); + require(isValid, BLSSignatureInvalid()); // Add the BLS public key to the provider's account eoaToBlsPubkeys[provider].push(blsPublicKey); diff --git a/contracts/contracts/interfaces/IProviderRegistry.sol b/contracts/contracts/interfaces/IProviderRegistry.sol index fc6cc2d9e..e2804081a 100644 --- a/contracts/contracts/interfaces/IProviderRegistry.sol +++ b/contracts/contracts/interfaces/IProviderRegistry.sol @@ -70,6 +70,9 @@ interface IProviderRegistry { error PendingWithdrawalRequest(address sender); error BidderAmountIsZero(address sender); error BidderWithdrawalTransferFailed(address sender, uint256 amount); + error PublicKeyLengthInvalid(uint256 exp, uint256 got); + error SignatureLengthInvalid(uint256 exp, uint256 got); + error BLSSignatureInvalid(); function registerAndStake() external payable; diff --git a/p2p/pkg/rpc/provider/service.go b/p2p/pkg/rpc/provider/service.go index 36035e681..860f27a2a 100644 --- a/p2p/pkg/rpc/provider/service.go +++ b/p2p/pkg/rpc/provider/service.go @@ -280,6 +280,11 @@ func (s *Service) Stake( return nil, status.Errorf(codes.Internal, "decoding bls signature: %v", err) } + opts, err = s.optsGetter(ctx) + if err != nil { + return nil, status.Errorf(codes.Internal, "getting transact opts for adding BLS key: %v", err) + } + s.logger.Info("adding verified bls key", "blsPublicKey", hex.EncodeToString(blsPublicKey), "blsSignature", hex.EncodeToString(blsSignature)) tx, txErr = s.registryContract.AddVerifiedBLSKey(opts, blsPublicKey, blsSignature) if txErr != nil {