Standard Staking/Unstaking Signature Structure
To authorize standard staking operations like presaleStaking
or publicStaking
, or their corresponding unstaking actions, the user must generate a cryptographic signature compliant with the EIP-191 standard.
This signature proves the user's intent and authorization to perform a specific staking or unstaking action with a defined amount of staking tokens, according to the parameters provided in the signed message.
Verification Function
The signature is verified using the verifyMessageSignedForStake
function:
function verifyMessageSignedForStake(
address user,
bool isExternalStaking,
bool _isStaking,
uint256 _amountOfStaking,
uint256 _nonce,
bytes memory signature
) internal pure returns (bool)
Signed Message Format
The message is constructed by concatenating the following components as strings, separated by commas (,
):
string.concat(
isExternalStaking ? "c769095c" : "c0f6e7d1",
",",
_isStaking ? "true" : "false",
",",
Strings.toString(_amountOfStaking),
",",
Strings.toString(_nonce)
)
Message Components
1. Staking Context Identifier (Hex String):
- Value: Depends on the context of the staking/unstaking action:
c769095c
: Used for signatures intended for thepublicStaking
function (isExternalStaking
is true).c0f6e7d1
: Used for signatures intended for thepresaleStaking
function (isExternalStaking
is false).
2. Staking Action Flag (String):
- Value: The literal string
"true"
if the user intends to stake (corresponding to the function's_isStaking
parameter being true), or"false"
if the user intends to unstake (_isStaking
being false). - Purpose: Clearly indicates whether the authorized operation is for staking tokens into the contract or unstaking them from the contract.
3. Staking Amount (String):
- Value: The result of
Strings.toString(_amountOfStaking)
. - Purpose: The string representation of the quantity (
uint256
) of staking tokens the user wishes to stake or unstake in this specific operation.
4. Nonce (String):
- Value: The result of
Strings.toString(_nonce)
. - Purpose: The string representation of the user's nonce specific to the relevant staking contract (Presale or Public) for this type of action. This prevents replay attacks for staking/unstaking operations initiated by the user.
Example Usage
Public Staking Example
For a public staking operation with 1000 tokens:
Message: "c769095c,true,1000,42"
Presale Unstaking Example
For a presale unstaking operation with 500 tokens:
Message: "c0f6e7d1,false,500,43"
Strings.toString
converts a number to a string- The
isExternalStaking
parameter determines which function selector to use - Each nonce should be unique to prevent replay attacks