Public Service Staking Signature Structure
To authorize publicServiceStaking
operations 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 to a specific service address, according to the parameters provided in the signed message.
Verification Function
The signature is verified using the verifyMessageSignedForPublicServiceStake
function:
function verifyMessageSignedForPublicServiceStake(
address user,
address serviceAddress,
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(
"e2ccd470",
",",
AdvancedStrings.addressToString(serviceAddress),
",",
_isStaking ? "true" : "false",
",",
Strings.toString(_amountOfStaking),
",",
Strings.toString(_nonce)
)
Message Components
1. Function Selector (Hex String):
- Value:
e2ccd470
- Used for signatures intended for thepublicServiceStaking
function. - Purpose: Identifies this signature as being specifically for public service staking operations.
2. Service Address (String):
- Value: The result of
AdvancedStrings.addressToString(serviceAddress)
. - Purpose: The lowercase string representation of the service contract address that will receive the staked tokens.
3. 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 to the service or unstaking them.
4. 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.
5. Nonce (String):
- Value: The result of
Strings.toString(_nonce)
. - Purpose: The string representation of the user's nonce for preventing replay attacks in public service staking operations.
Example Usage
Public Service Staking Example
For staking 2000 tokens to service address 0x1234567890abcdef1234567890abcdef12345678
:
Message: "e2ccd470,0x1234567890abcdef1234567890abcdef12345678,true,2000,15"
Public Service Unstaking Example
For unstaking 1500 tokens from service address 0xabcdef1234567890abcdef1234567890abcdef12
:
Message: "e2ccd470,0xabcdef1234567890abcdef1234567890abcdef12,false,1500,16"
AdvancedStrings.addressToString
converts an address to a lowercase stringStrings.toString
converts a number to a string- The service address must be included in the signature to prevent cross-service replay attacks
- Each nonce should be unique to prevent replay attacks