Functions
A
responseCode of 22 means SUCCESS. See HederaResponseCodes.sol for the other values.
An account can also call these functions on its own address, and the Hedera Account Service handles them for that account:
Verify signatures from Solidity
ECDSA accounts: ecrecover
ecrecover works on Hedera as it does on Ethereum. For an account whose EVM address is its EVM Address from Public Key (Keccak-256 of its ECDSA public key), call ecrecover(hash, v, r, s). If the recovered address equals the account’s EVM Address from Public Key, the signature was made with the ECDSA key that address was derived from. No Hedera-specific integration is needed.
ecrecover does not know about key updates. If the account’s key was later changed with CryptoUpdateTransaction, the original key, which may be compromised, still passes an ecrecover check against that address. To check the account’s current key, use isAuthorizedRaw or isAuthorized.
ecrecover cannot verify ED25519 signatures, accounts with key lists or threshold keys, or accounts referenced only by their EVM Address from Account ID (the long-zero form). Use the HIP-632 functions below for those.
isAuthorizedRaw
isAuthorizedRaw(address account, bytes messageHash, bytes signature) returns (bool) checks one signature against an account with a single key. It supports both ECDSA (secp256k1) and ED25519 keys. Unlike ecrecover, it checks the account’s current key: after a key update it accepts signatures from the new key and rejects the old one.
- Returns
trueonly if the signature is valid for the account’s key. A well-formed signature from the wrong key returnsfalse; the call itself still succeeds. - Reverts if the signature length matches neither key type, if an ECDSA
messageHashis not 32 bytes, if the account does not exist, or if an ED25519 account’s key is not a single ED25519 key.
isAuthorized
isAuthorized(address account, bytes message, bytes signatureMap) returns (int64, bool) checks signatures against the account’s full key, so it supports key lists, threshold keys, and mixed ECDSA and ED25519 keys.
- Returns
(responseCode, authorized).authorizedistrueonly if the signatures satisfy the account’s key. - Does not revert for a missing account, an account without a key, or a malformed
SignatureMap. It returns a non-SUCCESSresponse code withauthorizedset tofalse.
Check the result, not the call
Both functions report an invalid signature through their return values. If you call them with a low-levelcall and only check the call’s success flag, every well-formed signature passes, including forged ones. Call them through a typed interface and check the returned values:
Gas
isAuthorizedRaw charges the ecrecover gas cost for an ECDSA signature and a fixed ED25519 verification cost for an ED25519 signature. isAuthorized charges based on the keys in the account’s key structure, with the ED25519 verification cost for each ED25519 key, so accounts with larger key lists cost more to check.
Those amounts apply when the check runs. When isAuthorized returns an error code, or isAuthorizedRaw reverts, the call consumes all the gas forwarded to it. A Solidity call forwards nearly all remaining gas by default, so cap it:
Gas and Fees | Hedera
Gas fee schedule and calculation
account-service