ERC20 permit functión parametres v, r, s. Where do we get them from?

In the new version v5 of ERC20 we have the function permit to allowance accounts without spending gas, that is to say, with signature of the account:

  function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        if (block.timestamp > deadline) {
            revert ERC2612ExpiredSignature(deadline);
        }

        bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        if (signer != owner) {
            revert ERC2612InvalidSigner(signer, owner);
        }

        _approve(owner, spender, value);
    }

But in the parameters I am asked for some values that are returned with the splitSignature signature in solidity:
https://solidity-by-example.org/signature/

How am I supposed to capture these values to pass them to you as a parameter?

The account signature will have to be done from the contract and not from a front end in order to call the splitSignature function and capture those values requested in the parameters?

Hey @Cainuriel. In fact, the signature is just the values r,s concatenated (and v depends on the chain), so you can either pick them up from the signature string, or use the ethers v6's Signature class:

const { Signature } = require('ethers');

const signature = Signature.from('0x96f68bacfedd996d40a3eb4db679314545ce3d24f07b7db007528f8507f1f8654dd988fba90bf798173fa6b28222c3afb402ff5bbeac5dcc24bd204ae0778b911c');

signature.r; // 0x96f68bacfedd996d40a3eb4db679314545ce3d24f07b7db007528f8507f1f865
signature.s; // 0x4dd988fba90bf798173fa6b28222c3afb402ff5bbeac5dcc24bd204ae0778b91
signature.v // 27 | 28 

Thanks @ernestognw

Since I see that you know ethers.js version 6 well, would you be so kind to answer me this question?

1 Like