ExocoreNetwork / exocore

Omnichain Restaking
8 stars 10 forks source link

Self-delegation Precompile use Staker as 20-length bytes address while contracts uses 32-length bytes address #162

Closed cloud8little closed 2 months ago

cloud8little commented 3 months ago

In the AssociateOperatorWithStakerand DissociateOperatorFromStakerof delegation precompile contract, staker address is processed with evm address format, which is 20-length address.

  // TODO: In the future, the check should be the same as it is in delegation if using LayerZero to route the
  // message for non-EVM client chains, such as Solana.
  if len(staker) != common.AddressLength {
    return nil, fmt.Errorf(exocmn.ErrInvalidEVMAddr, staker)
  }

but in exocore-contracts, it uses the common 32-length address.

 function associateOperatorWithEVMStaker(uint32 clientChainId, string calldata operator)
        external
        whenNotPaused
        isValidBech32Address(operator)
    {
        bytes memory staker = abi.encodePacked(bytes32(bytes20(msg.sender)));
        bool success = DELEGATION_CONTRACT.associateOperatorWithStaker(clientChainId, staker, bytes(operator));
        if (!success) {
            revert Errors.AssociateOperatorFailed(clientChainId, msg.sender, operator);
        }
    }

    /**
     * @notice Dissociate an Exocore operator from an EVM staker(msg.sender),  and this requires that the staker has
     * already been associated to operator.
     * @param clientChainId The id of client chain
     */
    function dissociateOperatorFromEVMStaker(uint32 clientChainId) external whenNotPaused {
        bytes memory staker = abi.encodePacked(bytes32(bytes20(msg.sender)));
        bool success = DELEGATION_CONTRACT.dissociateOperatorFromStaker(clientChainId, staker);
        if (!success) {
            revert Errors.DissociateOperatorFailed(clientChainId, msg.sender);
        }
    }

calling the contract with error:

ERR internal error when calling delegation precompile error err="the address is an invalid EVM address, addr:n^��6S�FE[QtA\x19B� �\x12\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" module="delegation precompile"

cloud8little commented 2 months ago

Resolved in https://github.com/ExocoreNetwork/exocore/pull/164