This SIP establishes a general protocol for permitting and approving function calls in the same transaction relying on SRC-5750.
Unlike a few prior art (SRC-2612 for SRC-20, SRC-4494 for SRC-721 that
usually only permit for a single behavior (transfer for SRC-20 and safeTransferFrom for SRC-721) and a single approver in two transactions (first a permit(...) TX, then a transfer-like TX), this SIP provides a way to permit arbitrary behaviors and aggregating multiple approvals from arbitrary number of approvers in the same transaction, allowing for Multi-Sig or Threshold Signing behavior.
Motivation
Support permit(approval) alongside a function call.
Support a second approval from another user.
Support pay-for-by another user
Support multi-sig
Support persons acting in concert by endorsements
Support accumulated voting
Support off-line signatures
Specification
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 and RFC 8174.
Interfaces
The interfaces and structures referenced here are as follows
As specified in SRC-5750 General Extensibility for Method Behaviors, any compliant method that has a bytes extraData parameter as its
last designated parameter for extending behaviors can conform to SRC-5453 as the way to indicate a permit from a certain user.
Any compliant method of this SIP MUST be a SRC-5750 compliant method.
Caller MUST pass in the last parameter bytes extraData conforming to Solidity memory-encoded bytes of GeneralExtensionDataStruct specified in Section Interfaces. The following descriptions are based on when decoding bytes extraData into a GeneralExtensionDataStruct
In the GeneralExtensionDataStruct-decoded extraData, caller MUST set the value of GeneralExtensionDataStruct.src5453MagicWord to be the keccak256("SRC5453-ENDORSEMENT").
Caller MUST set the value of GeneralExtensionDataStruct.src5453Type to be one of the supported values.
When the value of GeneralExtensionDataStruct.src5453Type is set to be SRC5453_TYPE_A, GeneralExtensionDataStruct.endorsementPayload MUST be abi encoded bytes of a SingleEndorsementData.
When the value of GeneralExtensionDataStruct.src5453Type is set to be SRC5453_TYPE_B, GeneralExtensionDataStruct.endorsementPayload MUST be abi encoded bytes of SingleEndorsementData[] (a dynamic array).
Each SingleEndorsementData MUST have a address endorserAddress; and a 65-bytes bytes sig signature.
Each bytes sig MUST be an ECDSA (secp256k1) signature using private key of signer whose corresponding address is endorserAddress signing validityDigest which is the hashTypeDataV4 of SIP-712 of hashStruct of ValidityBound data structure as follows:
_functionStructure MUST be computed as function methodName(type1 param1, type2 param2, ...).
_functionParamPacked MUST be computed as enc(param1) || enco(param2) ...
Upon validating that endorserAddress == ecrecover(validityDigest, signature) or SIP1271(endorserAddress).isValidSignature(validityDigest, signature) == SRC1271.MAGICVALUE, the single endorsement MUST be deemed valid.
Compliant method MAY choose to impose a threshold for a number of endorsements needs to be valid in the same SRC5453_TYPE_B kind of endorsementPayload.
The validSince and validBy are both inclusive. Implementer MAY choose to use blocknumber or timestamp. Implementors SHOULD find a way to indicate whether validSince and validBy is blocknumber or timestamp.
Rationale
We chose to have both SRC5453_TYPE_A(single-endorsement) and SRC5453_TYPE_B(multiple-endorsements, same nonce for entire contract) so we
could balance a wider range of use cases. E.g. the same use cases of SRC-2612 and SRC-4494 can be supported by SRC5453_TYPE_A. And threshold approvals can be done via SRC5453_TYPE_B. More complicated approval types can also be extended by defining new SRC5453_TYPE_?
We chose to include both validSince and validBy to allow maximum flexibility in expiration. This can also be supported natively by the SVM if SRC-5081 is adopted, but SRC-5081 will not be adopted anytime soon, so we choose to add these two numbers in our protocol to allow
smart contract level support.
Backwards Compatibility
The design assumes a bytes calldata extraData to maximize the flexibility of future extensions. This assumption is compatible with SRC-721, SRC-1155 and many other SRC-track SIPs. Those that aren’t, such as SRC-20, can also be updated to support it, such as using a wrapper contract or proxy upgrade.
Reference Implementation
In addition to the specified algorithm for validating endorser signatures, we also present the following reference implementations.
Reference Implementation of ThresholdMultiSigForwarder
Here is a reference implementation of ThresholdMultiSigForwarder that achieves similar behavior of multi-sig threshold approval
remote contract call like a Gnosis-Safe wallet.
A replay attack is a type of attack on cryptography authentication. In a narrow sense, it usually refers to a type of attack that circumvents the cryptographically signature verification by reusing an existing signature for a message being signed again. Any implementations relying on this SIP must realize that all smart endorsements described here are cryptographic signatures that are public and can be obtained by anyone. They must foresee the possibility of a replay of the transactions not only at the exact deployment of the same smart contract, but also other deployments of similar smart contracts, or of a version of the same contract on another chainId, or any other similar attack surfaces. The nonce, validSince, and validBy fields are meant to restrict the surface of attack but might not fully eliminate the risk of all such attacks, e.g. see the Phishing section.
Phishing
It’s worth pointing out a special form of replay attack by phishing. An adversary can design another smart contract in a way that the user may be tricked into signing a smart endorsement for a seemingly legitimate purpose, but the data-to-designed matches the target application
Zainan Victor Zhou (@xinbenlv), "SRC-5453: Endorsement - Permit for Any Functions [LAST CALL]," Sila Improvement Proposals, no. 5453, August 2022. Available: https://sips.sila.org/SIPS/sip-5453.