Developer Docs
AppGitHub
  • Welcome!
  • Smart contracts
    • Core
      • Introduction
      • Deep Dive
      • Smart Contract Reference
        • PWN Hub
          • Tags
        • PWN Config
        • PWN Vault
        • Loan Types
          • Simple Loan
        • Proposals
          • Simple Loan Proposal
            • Simple Proposal
            • List Proposal
            • Elastic Proposal
            • Elastic Chainlink Proposal
            • Dutch Proposal
        • PWN Utilized Credit
        • PWN LOAN
        • PWN Revoked Nonce
        • Peripheral Contracts
          • Acceptor Controller
            • World ID
          • State Fingerprint Computer
            • UniV3
            • Chicken Bonds
          • Pool Adapter
            • Aave
            • Compound
            • ERC4626
        • Miscellaneous
          • PWN Fee Calculator
          • PWN Signature Checker
          • PWN Errors
          • PWN Periphery
          • Timelock
    • PWN DAO
      • Governance
        • Optimistic
        • Token
      • Tokens
        • PWN
        • stPWN
        • vePWN
          • Stake
          • Power
          • Metadata
      • Epoch Clock
      • Miscellaneous
        • Errors
        • EpochPowerLib
    • Tools
      • PWN Safe
        • Architecture
        • Security considerations
        • Smart Contract Reference
          • PWN Safe Factory
          • ATR Module
            • Tokenized Asset Manager
            • Recipient Permission Manager
          • Whitelist
          • ATR Guard
            • Operators context
      • Token Bundler
      • PWN Deployer
    • Libraries
      • MultiToken
    • Contract Addresses
  • More documentation
    • PWN Docs
    • FAQ
    • Audits
    • Using PWN without front-end
  • Deprecated
    • PWN Beta
      • Architecture
      • PWN
        • Off-chain signed offer
        • Offer types
      • PWN Vault
      • PWN LOAN
Powered by GitBook
On this page
  • 1. Summary
  • 2. Important links
  • 3. Contract details
  • Errors
Edit on GitHub
  1. Smart contracts
  2. Core
  3. Smart Contract Reference
  4. Miscellaneous

PWN Signature Checker

PreviousPWN Fee CalculatorNextPWN Errors

Last updated 9 months ago

1. Summary

The PWNSignatureChecker library implements the isValidSignatureNow view function. This library is a modification of the Open-Zeppelin library extended by support for compact signatures.

2. Important links

3. Contract details

  • PWNSignatureChecker.sol is written in Solidity version 0.8.16

isValidSignatureNow

Overview

This function takes three arguments supplied by the caller:

  • addresssigner - Address that should be a hash signer or a signature validator, in case of a contract account.

  • bytes32hash - Hash of a signed message that should be validated.

Implementation

function isValidSignatureNow(
    address signer,
    bytes32 hash,
    bytes memory signature
) internal view returns (bool) {
    // Check that signature is valid for contract account
    if (signer.code.length > 0) {
        (bool success, bytes memory result) = signer.staticcall(
            abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
        );
        return
            success &&
            result.length == 32 &&
            abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector);
    }
    // Check that signature is valid for EOA
    else {
        bytes32 r;
        bytes32 s;
        uint8 v;

        // Standard signature data (65 bytes)
        if (signature.length == 65) {
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
        }
        // Compact signature data (64 bytes) - see EIP-2098
        else if (signature.length == 64) {
            bytes32 vs;

            assembly {
                r := mload(add(signature, 0x20))
                vs := mload(add(signature, 0x40))
            }

            s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            v = uint8((uint256(vs) >> 255) + 27);
        } else {
            revert InvalidSignatureLength({ length: signature.length });
        }

        return signer == ECDSA.recover(hash, v, r, s);
    }
}

Errors

error InvalidSignatureLength(uint256 length);
error InvalidSignature(address signer, bytes32 digest);
InvalidSignatureLength

InvalidSignatureLength event is emitted when signature length is not 64 nor 65 bytes.

This event has one parameter:

  • uint256length

InvalidSignature

InvalidSignatureLength event is emitted when the signature is invalid.

This event has one parameter:

  • addresssigner

  • bytes32digest - hash to distinguish different proposals

This function will try to recover a signer of a given signature and check if is the same as the given signer address. For a contract account signer address, the function will check signature validity by calling isValidSignature function defined by .

bytes memorysignature - Signature of a signed hash. Can be empty for a contract account signature validation. The signature can be standard (65 bytes) or compact (64 bytes) defined by .

EIP-1271
EIP-2098
SignatureChecker
EIP-2098
pwn_contracts/PWNSignatureChecker.sol at master · PWNFinance/pwn_contractsGitHub
Logo