Skip to content

Commit

Permalink
fix: txn opts for BLS registration and errors (#531)
Browse files Browse the repository at this point in the history
* chore: add errors to verification

* chore: add errors to verification

* chore: add errors to verification

---------

Co-authored-by: Alok <[email protected]>
  • Loading branch information
aloknerurkar and Alok authored Dec 12, 2024
1 parent 015b6ca commit 046bc77
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions contracts/contracts/core/ProviderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions contracts/contracts/interfaces/IProviderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions p2p/pkg/rpc/provider/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 046bc77

Please sign in to comment.