@evvm/testnet-contracts 2.2.3 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE +145 -118
  2. package/README.md +138 -35
  3. package/contracts/evvm/Evvm.sol +154 -181
  4. package/contracts/evvm/lib/ErrorsLib.sol +119 -6
  5. package/contracts/evvm/lib/EvvmStorage.sol +164 -9
  6. package/contracts/evvm/lib/EvvmStructs.sol +124 -6
  7. package/contracts/evvm/lib/SignatureUtils.sol +103 -61
  8. package/contracts/nameService/NameService.sol +165 -155
  9. package/contracts/nameService/lib/ErrorsLib.sol +142 -8
  10. package/contracts/nameService/lib/IdentityValidation.sol +21 -0
  11. package/contracts/nameService/lib/NameServiceStructs.sol +75 -19
  12. package/contracts/nameService/lib/SignatureUtils.sol +235 -60
  13. package/contracts/p2pSwap/P2PSwap.sol +201 -160
  14. package/contracts/staking/Estimator.sol +131 -24
  15. package/contracts/staking/Staking.sol +98 -113
  16. package/contracts/staking/lib/ErrorsLib.sol +79 -3
  17. package/contracts/staking/lib/SignatureUtils.sol +82 -16
  18. package/contracts/staking/lib/StakingStructs.sol +12 -0
  19. package/contracts/treasury/Treasury.sol +30 -12
  20. package/contracts/treasury/lib/ErrorsLib.sol +30 -0
  21. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +3 -3
  22. package/interfaces/IEvvm.sol +9 -4
  23. package/interfaces/INameService.sol +12 -3
  24. package/interfaces/IStaking.sol +2 -1
  25. package/library/Erc191TestBuilder.sol +188 -0
  26. package/library/EvvmService.sol +55 -0
  27. package/library/primitives/SignatureRecover.sol +33 -0
  28. package/library/utils/AdvancedStrings.sol +61 -0
  29. package/library/utils/SignatureUtil.sol +34 -0
  30. package/library/utils/nonces/AsyncNonce.sol +42 -0
  31. package/library/utils/nonces/SyncNonce.sol +44 -0
  32. package/library/utils/service/EvvmPayments.sol +65 -0
  33. package/library/utils/service/StakingServiceUtils.sol +44 -0
  34. package/package.json +2 -1
@@ -2,44 +2,73 @@
2
2
  // Full license terms available at: https://www.evvm.info/docs/EVVMNoncommercialLicense
3
3
  pragma solidity ^0.8.0;
4
4
 
5
- import {SignatureUtil} from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
6
- import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
5
+ import {
6
+ SignatureUtil
7
+ } from "@evvm/testnet-contracts/library/utils/SignatureUtil.sol";
8
+ import {
9
+ AdvancedStrings
10
+ } from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
7
11
 
12
+ /**
13
+ * @title SignatureUtils
14
+ * @author Mate labs
15
+ * @notice Library for EIP-191 signature verification exclusively for Evvm.sol payment functions
16
+ * @dev This library provides signature verification utilities for the Evvm.sol contract,
17
+ * specifically for payment operations (pay and dispersePay). It constructs the message
18
+ * format expected by users and validates their signatures.
19
+ *
20
+ * Signature Verification:
21
+ * - Uses EIP-191 standard for message signing and verification
22
+ * - Constructs deterministic message strings from payment parameters
23
+ * - Integrates with SignatureUtil for cryptographic verification
24
+ * - Prevents replay attacks through nonce inclusion
25
+ * - Supports cross-chain safety through EvvmID inclusion
26
+ *
27
+ * Message Format:
28
+ * - pay: "receiver,token,amount,priorityFee,nonce,priorityFlag,executor"
29
+ * - dispersePay: "hashOfRecipients,token,amount,priorityFee,nonce,priorityFlag,executor"
30
+ *
31
+ * @custom:scope Exclusive to Evvm.sol payment functions
32
+ * @custom:standard EIP-191 (https://eips.ethereum.org/EIPS/eip-191)
33
+ * @custom:security All signatures include EvvmID to prevent cross-chain replay attacks
34
+ */
8
35
  library SignatureUtils {
9
- /**
10
- * @dev using EIP-191 (https://eips.ethereum.org/EIPS/eip-191) can be used to sign and
11
- * verify messages, the next functions are used to verify the messages signed
12
- * by the users
13
- */
14
36
 
15
37
  /**
16
- * @notice This function is used to verify the message signed for the payment
17
- * @param signer user who signed the message
18
- * @param _receiverAddress address of the receiver
19
- * @param _receiverIdentity identity of the receiver
38
+ * @notice Verifies EIP-191 signature for single payment operations
39
+ * @dev Constructs the expected message from payment parameters and verifies
40
+ * the signature matches the signer. Used in pay() and payMultiple() functions.
20
41
  *
21
- * @notice if the _receiverAddress is 0x0 the function will use the _receiverIdentity
42
+ * Message Construction:
43
+ * - If receiverAddress is address(0): uses receiverIdentity string
44
+ * - Otherwise: converts receiverAddress to string
45
+ * - Concatenates all parameters with comma separators
46
+ * - Includes EvvmID for cross-chain replay protection
22
47
  *
23
- * @param _token address of the token to send
24
- * @param _amount amount to send
25
- * @param _priorityFee priorityFee to send to the staking holder
26
- * @param _nonce nonce of the transaction
27
- * @param _priorityFlag if the transaction is priority or not
28
- * @param _executor the executor of the transaction
29
- * @param signature signature of the user who wants to send the message
30
- * @return true if the signature is valid
48
+ * @param evvmID Unique identifier of the EVVM instance for cross-chain safety
49
+ * @param signer Address that signed the message (payment sender)
50
+ * @param receiverAddress Direct recipient address (used if receiverIdentity is empty)
51
+ * @param receiverIdentity Username/identity to resolve (takes priority over address)
52
+ * @param token Address of the token to transfer
53
+ * @param amount Amount of tokens to transfer
54
+ * @param priorityFee Fee paid to the staker/fisher processing the transaction
55
+ * @param nonce Transaction nonce for replay protection
56
+ * @param priorityFlag False for sync nonce (sequential), true for async nonce (flexible)
57
+ * @param executor Address authorized to execute this transaction (address(0) = anyone)
58
+ * @param signature EIP-191 signature from the signer
59
+ * @return bool True if the signature is valid and matches the signer
31
60
  */
32
61
  function verifyMessageSignedForPay(
33
62
  uint256 evvmID,
34
63
  address signer,
35
- address _receiverAddress,
36
- string memory _receiverIdentity,
37
- address _token,
38
- uint256 _amount,
39
- uint256 _priorityFee,
40
- uint256 _nonce,
41
- bool _priorityFlag,
42
- address _executor,
64
+ address receiverAddress,
65
+ string memory receiverIdentity,
66
+ address token,
67
+ uint256 amount,
68
+ uint256 priorityFee,
69
+ uint256 nonce,
70
+ bool priorityFlag,
71
+ address executor,
43
72
  bytes memory signature
44
73
  ) internal pure returns (bool) {
45
74
  return
@@ -47,21 +76,21 @@ library SignatureUtils {
47
76
  evvmID,
48
77
  "pay",
49
78
  string.concat(
50
- _receiverAddress == address(0)
51
- ? _receiverIdentity
52
- : AdvancedStrings.addressToString(_receiverAddress),
79
+ receiverAddress == address(0)
80
+ ? receiverIdentity
81
+ : AdvancedStrings.addressToString(receiverAddress),
53
82
  ",",
54
- AdvancedStrings.addressToString(_token),
83
+ AdvancedStrings.addressToString(token),
55
84
  ",",
56
- AdvancedStrings.uintToString(_amount),
85
+ AdvancedStrings.uintToString(amount),
57
86
  ",",
58
- AdvancedStrings.uintToString(_priorityFee),
87
+ AdvancedStrings.uintToString(priorityFee),
59
88
  ",",
60
- AdvancedStrings.uintToString(_nonce),
89
+ AdvancedStrings.uintToString(nonce),
61
90
  ",",
62
- _priorityFlag ? "true" : "false",
91
+ AdvancedStrings.boolToString(priorityFlag),
63
92
  ",",
64
- AdvancedStrings.addressToString(_executor)
93
+ AdvancedStrings.addressToString(executor)
65
94
  ),
66
95
  signature,
67
96
  signer
@@ -69,29 +98,42 @@ library SignatureUtils {
69
98
  }
70
99
 
71
100
  /**
72
- * @notice This function is used to verify the message signed for the dispersePay
73
- * @param signer user who signed the message
74
- * @param hashList hash of the list of the transactions, the hash is calculated
75
- * using sha256(abi.encode(toData))
76
- * @param _token token address to send
77
- * @param _amount amount to send
78
- * @param _priorityFee priorityFee to send to the fisher who wants to send the message
79
- * @param _nonce nonce of the transaction
80
- * @param _priorityFlag if the transaction is priority or not
81
- * @param _executor the executor of the transaction
82
- * @param signature signature of the user who wants to send the message
83
- * @return true if the signature is valid
101
+ * @notice Verifies EIP-191 signature for multi-recipient disperse payment operations
102
+ * @dev Constructs the expected message from disperse parameters and verifies
103
+ * the signature matches the signer. Used in dispersePay() function.
104
+ *
105
+ * Message Construction:
106
+ * - Uses sha256 hash of recipient array instead of full data (gas optimization)
107
+ * - Concatenates hash and all other parameters with comma separators
108
+ * - Includes EvvmID for cross-chain replay protection
109
+ *
110
+ * Hash Calculation:
111
+ * - Client must calculate: sha256(abi.encode(toData))
112
+ * - toData is DispersePayMetadata[] array with recipients and amounts
113
+ * - Ensures tamper-proof verification of all recipients
114
+ *
115
+ * @param evvmID Unique identifier of the EVVM instance for cross-chain safety
116
+ * @param signer Address that signed the message (payment sender)
117
+ * @param hashList SHA256 hash of the recipient data array: sha256(abi.encode(toData))
118
+ * @param token Address of the token to distribute
119
+ * @param amount Total amount being distributed (must equal sum of individual amounts)
120
+ * @param priorityFee Fee paid to the staker/fisher processing the distribution
121
+ * @param nonce Transaction nonce for replay protection
122
+ * @param priorityFlag False for sync nonce (sequential), true for async nonce (flexible)
123
+ * @param executor Address authorized to execute this distribution (address(0) = anyone)
124
+ * @param signature EIP-191 signature from the signer
125
+ * @return bool True if the signature is valid and matches the signer
84
126
  */
85
127
  function verifyMessageSignedForDispersePay(
86
128
  uint256 evvmID,
87
129
  address signer,
88
130
  bytes32 hashList,
89
- address _token,
90
- uint256 _amount,
91
- uint256 _priorityFee,
92
- uint256 _nonce,
93
- bool _priorityFlag,
94
- address _executor,
131
+ address token,
132
+ uint256 amount,
133
+ uint256 priorityFee,
134
+ uint256 nonce,
135
+ bool priorityFlag,
136
+ address executor,
95
137
  bytes memory signature
96
138
  ) internal pure returns (bool) {
97
139
  return
@@ -101,17 +143,17 @@ library SignatureUtils {
101
143
  string.concat(
102
144
  AdvancedStrings.bytes32ToString(hashList),
103
145
  ",",
104
- AdvancedStrings.addressToString(_token),
146
+ AdvancedStrings.addressToString(token),
105
147
  ",",
106
- AdvancedStrings.uintToString(_amount),
148
+ AdvancedStrings.uintToString(amount),
107
149
  ",",
108
- AdvancedStrings.uintToString(_priorityFee),
150
+ AdvancedStrings.uintToString(priorityFee),
109
151
  ",",
110
- AdvancedStrings.uintToString(_nonce),
152
+ AdvancedStrings.uintToString(nonce),
111
153
  ",",
112
- _priorityFlag ? "true" : "false",
154
+ AdvancedStrings.boolToString(priorityFlag),
113
155
  ",",
114
- AdvancedStrings.addressToString(_executor)
156
+ AdvancedStrings.addressToString(executor)
115
157
  ),
116
158
  signature,
117
159
  signer