Skip to content

Commit

Permalink
update the pre-compiled bls key registration interface parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Feb 21, 2025
1 parent 4d83208 commit 16b8823
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
10 changes: 6 additions & 4 deletions precompiles/avs/IAVSManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,16 @@ interface IAVSManager {
/// @param sender The external address for calling this method.
/// @param avsAddress The address of AVS.
/// @param pubKey the public keys of the operator
/// @param pubkeyRegistrationSignature the public keys of the operator
/// @param pubkeyRegistrationMessageHash the public keys of the operator
/// @param pubKeyRegistrationSignature the public keys of the operator
/// @param pubKeyRegistrationMessageHash the public keys of the operator
/// @param msg is the message which signed using a private key
function registerBLSPublicKey(
address sender,
address avsAddress,
bytes calldata pubKey,
bytes calldata pubkeyRegistrationSignature,
bytes calldata pubkeyRegistrationMessageHash
bytes calldata pubKeyRegistrationSignature,
bytes calldata pubKeyRegistrationMessageHash,
string msg
) external returns (bool success);

/// @dev operatorSubmitTask , this function enables a operator submit a task result.
Expand Down
9 changes: 7 additions & 2 deletions precompiles/avs/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,19 @@ func (p Precompile) RegisterBLSPublicKey(
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParamOrType, 3, "[]byte", pubKeyRegistrationSignature)
}
blsParams.PubkeyRegistrationSignature = pubKeyRegistrationSignature
blsParams.PubKeyRegistrationSignature = pubKeyRegistrationSignature

pubKeyRegistrationMessageHash, ok := args[4].([]byte)
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParamOrType, 4, "[]byte", pubKeyRegistrationMessageHash)
}
blsParams.PubkeyRegistrationMessageHash = pubKeyRegistrationMessageHash
blsParams.PubKeyRegistrationMessageHash = pubKeyRegistrationMessageHash

msg, ok := args[5].(string)
if !ok {
return nil, fmt.Errorf(exocmn.ErrContractInputParamOrType, 5, "string", msg)
}
blsParams.Message = msg
err := p.avsKeeper.RegisterBLSPublicKey(ctx, blsParams)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions x/avs/keeper/avs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ func (suite *AVSTestSuite) TestRegisterBLSPublicKey() {
OperatorAddress: operatorAddress,
AvsAddress: testutiltx.GenerateAddress(),
PubKey: publicKey.Marshal(),
PubkeyRegistrationSignature: sig.Marshal(),
PubkeyRegistrationMessageHash: expectedHash.Bytes(),
PubKeyRegistrationSignature: sig.Marshal(),
PubKeyRegistrationMessageHash: expectedHash.Bytes(),
Message: expectedMessage,
}

err = suite.App.AVSManagerKeeper.RegisterBLSPublicKey(suite.Ctx, params)
suite.NoError(err)

Expand Down
6 changes: 3 additions & 3 deletions x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ func (k Keeper) RegisterBLSPublicKey(ctx sdk.Context, params *types.BlsParams) e
return fmt.Errorf("invalid message format: %s", params.Message)
}
// check msg hash
msgHash := params.PubkeyRegistrationMessageHash
msgHash := params.PubKeyRegistrationMessageHash

expectedHash := crypto.Keccak256Hash([]byte(expectedMessage))
if !bytes.Equal(msgHash, expectedHash.Bytes()) {
return fmt.Errorf("the input hash failed to validate: %s", params.Message)
}

sig := params.PubkeyRegistrationSignature
sig := params.PubKeyRegistrationSignature
pubKey, _ := bls.PublicKeyFromBytes(params.PubKey)
valid, err := blst.VerifySignature(sig, [32]byte(msgHash), pubKey)
if err != nil || !valid {
Expand All @@ -323,7 +323,7 @@ func (k Keeper) RegisterBLSPublicKey(ctx sdk.Context, params *types.BlsParams) e
// if operator are using multiple servers for different AVSs .
// In case one server is compromised, signing can continue as expected on the AVSs for which there has been no compromise.
if k.IsExistPubKey(ctx, blsInfo) {
return errorsmod.Wrap(types.ErrAlreadyExists, fmt.Sprintf("the bls key is already exists:%s", bls.PubKey))
return errorsmod.Wrap(types.ErrAlreadyExists, fmt.Sprintf("the bls key is already exists:%s", blsInfo.PubKey))
}
return k.SetOperatorPubKey(ctx, blsInfo)
}
Expand Down
4 changes: 2 additions & 2 deletions x/avs/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type BlsParams struct {
OperatorAddress sdk.AccAddress
AvsAddress common.Address
PubKey []byte
PubkeyRegistrationSignature []byte
PubkeyRegistrationMessageHash []byte
PubKeyRegistrationSignature []byte
PubKeyRegistrationMessageHash []byte
Message string
}

Expand Down

0 comments on commit 16b8823

Please sign in to comment.