@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.
- package/LICENSE +145 -118
- package/README.md +138 -35
- package/contracts/evvm/Evvm.sol +154 -181
- package/contracts/evvm/lib/ErrorsLib.sol +119 -6
- package/contracts/evvm/lib/EvvmStorage.sol +164 -9
- package/contracts/evvm/lib/EvvmStructs.sol +124 -6
- package/contracts/evvm/lib/SignatureUtils.sol +103 -61
- package/contracts/nameService/NameService.sol +165 -155
- package/contracts/nameService/lib/ErrorsLib.sol +142 -8
- package/contracts/nameService/lib/IdentityValidation.sol +21 -0
- package/contracts/nameService/lib/NameServiceStructs.sol +75 -19
- package/contracts/nameService/lib/SignatureUtils.sol +235 -60
- package/contracts/p2pSwap/P2PSwap.sol +201 -160
- package/contracts/staking/Estimator.sol +131 -24
- package/contracts/staking/Staking.sol +98 -113
- package/contracts/staking/lib/ErrorsLib.sol +79 -3
- package/contracts/staking/lib/SignatureUtils.sol +82 -16
- package/contracts/staking/lib/StakingStructs.sol +12 -0
- package/contracts/treasury/Treasury.sol +30 -12
- package/contracts/treasury/lib/ErrorsLib.sol +30 -0
- package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +3 -3
- package/interfaces/IEvvm.sol +9 -4
- package/interfaces/INameService.sol +12 -3
- package/interfaces/IStaking.sol +2 -1
- package/library/Erc191TestBuilder.sol +188 -0
- package/library/EvvmService.sol +55 -0
- package/library/primitives/SignatureRecover.sol +33 -0
- package/library/utils/AdvancedStrings.sol +61 -0
- package/library/utils/SignatureUtil.sol +34 -0
- package/library/utils/nonces/AsyncNonce.sol +42 -0
- package/library/utils/nonces/SyncNonce.sol +44 -0
- package/library/utils/service/EvvmPayments.sol +65 -0
- package/library/utils/service/StakingServiceUtils.sol +44 -0
- 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 {
|
|
6
|
-
|
|
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
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
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
|
|
36
|
-
string memory
|
|
37
|
-
address
|
|
38
|
-
uint256
|
|
39
|
-
uint256
|
|
40
|
-
uint256
|
|
41
|
-
bool
|
|
42
|
-
address
|
|
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
|
-
|
|
51
|
-
?
|
|
52
|
-
: AdvancedStrings.addressToString(
|
|
79
|
+
receiverAddress == address(0)
|
|
80
|
+
? receiverIdentity
|
|
81
|
+
: AdvancedStrings.addressToString(receiverAddress),
|
|
53
82
|
",",
|
|
54
|
-
AdvancedStrings.addressToString(
|
|
83
|
+
AdvancedStrings.addressToString(token),
|
|
55
84
|
",",
|
|
56
|
-
AdvancedStrings.uintToString(
|
|
85
|
+
AdvancedStrings.uintToString(amount),
|
|
57
86
|
",",
|
|
58
|
-
AdvancedStrings.uintToString(
|
|
87
|
+
AdvancedStrings.uintToString(priorityFee),
|
|
59
88
|
",",
|
|
60
|
-
AdvancedStrings.uintToString(
|
|
89
|
+
AdvancedStrings.uintToString(nonce),
|
|
61
90
|
",",
|
|
62
|
-
|
|
91
|
+
AdvancedStrings.boolToString(priorityFlag),
|
|
63
92
|
",",
|
|
64
|
-
AdvancedStrings.addressToString(
|
|
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
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
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
|
|
90
|
-
uint256
|
|
91
|
-
uint256
|
|
92
|
-
uint256
|
|
93
|
-
bool
|
|
94
|
-
address
|
|
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(
|
|
146
|
+
AdvancedStrings.addressToString(token),
|
|
105
147
|
",",
|
|
106
|
-
AdvancedStrings.uintToString(
|
|
148
|
+
AdvancedStrings.uintToString(amount),
|
|
107
149
|
",",
|
|
108
|
-
AdvancedStrings.uintToString(
|
|
150
|
+
AdvancedStrings.uintToString(priorityFee),
|
|
109
151
|
",",
|
|
110
|
-
AdvancedStrings.uintToString(
|
|
152
|
+
AdvancedStrings.uintToString(nonce),
|
|
111
153
|
",",
|
|
112
|
-
|
|
154
|
+
AdvancedStrings.boolToString(priorityFlag),
|
|
113
155
|
",",
|
|
114
|
-
AdvancedStrings.addressToString(
|
|
156
|
+
AdvancedStrings.addressToString(executor)
|
|
115
157
|
),
|
|
116
158
|
signature,
|
|
117
159
|
signer
|