@coti-io/coti-contracts 1.0.0 → 1.0.3
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/.github/workflows/npm-publish.yml +2 -1
- package/CONTRIBUTING.md +2 -2
- package/LICENSE +1 -1
- package/README.md +18 -35
- package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +112 -0
- package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +152 -0
- package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +11 -1
- package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +8 -0
- package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +33 -4
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.sol +35 -10
- package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +126 -0
- package/contracts/mocks/utils/mpc/TransferTestsContract.sol +3 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol +223 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.sol +265 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol +281 -0
- package/contracts/token/PrivateERC20/PrivateERC20.sol +1 -1
- package/contracts/token/PrivateERC721/IERC721Errors.sol +57 -0
- package/contracts/token/PrivateERC721/PrivateERC721.sol +1 -1
- package/contracts/utils/mpc/MpcCore.sol +40 -0
- package/contracts/utils/mpc/MpcInterface.sol +2 -0
- package/hardhat.config.ts +9 -1
- package/package.json +20 -4
- package/test/onboard/AccountOnboard.test.ts +2 -2
- package/test/token/PrivateERC20/PrivateERC20.test.ts +2 -2
- package/test/utils/accounts.ts +2 -2
- package/test/utils/mpc/Precompile.test.ts +24 -2
- package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +0 -2
- package/typechain-types/contracts/GasTest.ts +91 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +66 -0
- package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +6 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +6 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.ts +36 -6
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract.ts +251 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract.ts +250 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.ts +389 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.ts +306 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract.ts +125 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract.ts +125 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.ts +296 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +7 -0
- package/typechain-types/contracts/token/PrivateERC721/IERC721Errors.ts +69 -0
- package/typechain-types/contracts/token/PrivateERC721/index.ts +1 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +38 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +0 -1
- package/typechain-types/factories/contracts/GasTest__factory.ts +75 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +73 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +11 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +11 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +26 -30
- package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract__factory.ts +294 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +292 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract__factory.ts +720 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +507 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract__factory.ts +150 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +150 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +434 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +7 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +1 -1
- package/typechain-types/factories/contracts/token/PrivateERC721/IERC721Errors__factory.ts +128 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +1 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +1 -1
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +58 -0
- package/typechain-types/hardhat.d.ts +144 -54
- package/typechain-types/index.ts +16 -6
- package/contracts/access/DataPrivacyFramework/README.md +0 -68
- package/contracts/onboard/README.md +0 -65
- package/contracts/token/PrivateERC20/README.md +0 -104
- package/contracts/token/PrivateERC721/README.md +0 -282
- package/contracts/utils/mpc/README.md +0 -82
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# AccountOnboard
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The `AccountOnboard` contract is responsible for onboarding user accounts to the system, leveraging RSA public keys and AES encryption. During onboarding, the user's AES encryption key is emitted in an encrypted form. This contract interacts with a utility contract `MpcCore` to retrieve the user key.
|
|
6
|
-
|
|
7
|
-
## Prerequisites
|
|
8
|
-
|
|
9
|
-
- **Solidity Version**: `^0.8.19`
|
|
10
|
-
- **License**: MIT
|
|
11
|
-
- **Dependencies**:
|
|
12
|
-
- Imports from `../utils/mpc/MpcCore.sol`.
|
|
13
|
-
|
|
14
|
-
## Table of Contents
|
|
15
|
-
- [Events](#events)
|
|
16
|
-
- [AccountOnboarded](#accountonboarded)
|
|
17
|
-
- [Functions](#functions)
|
|
18
|
-
- [onboardAccount](#onboardaccount)
|
|
19
|
-
|
|
20
|
-
## Events
|
|
21
|
-
|
|
22
|
-
### AccountOnboarded
|
|
23
|
-
|
|
24
|
-
This event is triggered when a new account is successfully onboarded. It logs the user's account information, including the sender's address and the AES encryption key in its encrypted form.
|
|
25
|
-
|
|
26
|
-
#### Parameters:
|
|
27
|
-
- **`_from`**: (`address`) The address of the account that initiated the onboarding process.
|
|
28
|
-
- **`userKey`**: (`bytes`) The user's AES encryption key, encrypted using RSA. This key must be decrypted before use.
|
|
29
|
-
|
|
30
|
-
```solidity
|
|
31
|
-
event AccountOnboarded(address indexed _from, bytes userKey);
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Functions
|
|
35
|
-
|
|
36
|
-
### onboardAccount
|
|
37
|
-
|
|
38
|
-
The `onboardAccount` function is responsible for onboarding a new user account. It takes an RSA public key and a signed hash of the key, verifies the credentials, and emits the encrypted AES key.
|
|
39
|
-
|
|
40
|
-
#### Function Definition:
|
|
41
|
-
|
|
42
|
-
```solidity
|
|
43
|
-
function onboardAccount(bytes calldata publicKey, bytes calldata signedEK) public;
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
#### Parameters:
|
|
47
|
-
- **`publicKey`**: (`bytes`) The RSA public key of the user. This is used to verify and generate the AES encryption key.
|
|
48
|
-
- **`signedEK`**: (`bytes`) A signed hash of the RSA public key, used to ensure the authenticity of the public key.
|
|
49
|
-
|
|
50
|
-
#### Logic:
|
|
51
|
-
1. Calls the external `MpcCore.getUserKey()` function to retrieve the user's AES encryption key using the provided RSA public key and its signed hash.
|
|
52
|
-
2. Emits the `AccountOnboarded` event, logging the caller's address and the encrypted AES key.
|
|
53
|
-
|
|
54
|
-
#### Example Usage:
|
|
55
|
-
|
|
56
|
-
```solidity
|
|
57
|
-
function onboardAccount(bytes calldata publicKey, bytes calldata signedEK) public {
|
|
58
|
-
bytes memory accountKey = MpcCore.getUserKey(publicKey, signedEK);
|
|
59
|
-
emit AccountOnboarded(msg.sender, accountKey);
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### External Function Calls:
|
|
64
|
-
- **`MpcCore.getUserKey(publicKey, signedEK)`**:
|
|
65
|
-
- Retrieves the user's AES encryption key, based on the RSA public key and signed hash.
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
# PrivateERC20
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The `PrivateERC20` contract is an abstract implementation of a privacy-enhanced ERC20 token. It introduces mechanisms for handling encrypted addresses and balances, allowing for more secure and private token transfers. This contract builds on top of OpenZeppelin's `Context` and the `IPrivateERC20` interface, and it integrates with the `MpcCore` library for secure multiparty computation (MPC).
|
|
6
|
-
|
|
7
|
-
## Prerequisites
|
|
8
|
-
|
|
9
|
-
- **Solidity Version**: `^0.8.19`
|
|
10
|
-
- **License**: MIT
|
|
11
|
-
- **Dependencies**:
|
|
12
|
-
- OpenZeppelin's `Context` contract
|
|
13
|
-
- Interface `IPrivateERC20`
|
|
14
|
-
- Utility `MpcCore` for cryptographic operations.
|
|
15
|
-
|
|
16
|
-
## Table of Contents
|
|
17
|
-
- [Constants](#constants)
|
|
18
|
-
- [MAX_UINT_64](#max_uint_64)
|
|
19
|
-
- [State Variables](#state-variables)
|
|
20
|
-
- [Account Encryption Address Mapping](#account-encryption-address-mapping)
|
|
21
|
-
- [Balance Mapping](#balance-mapping)
|
|
22
|
-
- [Allowances Mapping](#allowances-mapping)
|
|
23
|
-
- [Total Supply](#total-supply)
|
|
24
|
-
- [Token Name and Symbol](#token-name-and-symbol)
|
|
25
|
-
- [Errors](#errors)
|
|
26
|
-
- [ERC20InvalidSender](#erc20invalidsender)
|
|
27
|
-
- [ERC20InvalidReceiver](#erc20invalidreceiver)
|
|
28
|
-
- [Functions](#functions)
|
|
29
|
-
- To be documented as additional logic is discovered.
|
|
30
|
-
|
|
31
|
-
## Constants
|
|
32
|
-
|
|
33
|
-
### MAX_UINT_64
|
|
34
|
-
|
|
35
|
-
```solidity
|
|
36
|
-
uint64 private constant MAX_UINT_64 = type(uint64).max;
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
The constant `MAX_UINT_64` represents the maximum value of a 64-bit unsigned integer. This is used as a cap for various operations in the contract.
|
|
40
|
-
|
|
41
|
-
## State Variables
|
|
42
|
-
|
|
43
|
-
### Account Encryption Address Mapping
|
|
44
|
-
|
|
45
|
-
```solidity
|
|
46
|
-
mapping(address account => address) private _accountEncryptionAddress;
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
This mapping associates each account (public address) with an encryption address. The encryption address could be used for handling cryptographically secure operations involving private balances and transactions.
|
|
50
|
-
|
|
51
|
-
### Balance Mapping
|
|
52
|
-
|
|
53
|
-
```solidity
|
|
54
|
-
mapping(address account => utUint64) private _balances;
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
The `_balances` mapping keeps track of each account's token balance, but it uses a 64-bit unsigned integer (`utUint64`). This might be intended for scaling or privacy-preserving reasons.
|
|
58
|
-
|
|
59
|
-
### Allowances Mapping
|
|
60
|
-
|
|
61
|
-
```solidity
|
|
62
|
-
mapping(address account => mapping(address spender => Allowance)) private _allowances;
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
The `_allowances` mapping tracks the allowance that one account (`account`) has given to another account (`spender`). This is a standard ERC20 allowance mechanism with the added layer of the `Allowance` structure, which may handle encrypted or privacy-preserving amounts.
|
|
66
|
-
|
|
67
|
-
### Total Supply
|
|
68
|
-
|
|
69
|
-
```solidity
|
|
70
|
-
ctUint64 private _totalSupply;
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
The `_totalSupply` variable keeps track of the total number of tokens in existence. Like the `_balances` mapping, it uses a 64-bit unsigned integer (`ctUint64`).
|
|
74
|
-
|
|
75
|
-
### Token Name and Symbol
|
|
76
|
-
|
|
77
|
-
```solidity
|
|
78
|
-
string private _name;
|
|
79
|
-
string private _symbol;
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
These variables store the name and symbol of the token, following the ERC20 standard.
|
|
83
|
-
|
|
84
|
-
## Errors
|
|
85
|
-
|
|
86
|
-
### ERC20InvalidSender
|
|
87
|
-
|
|
88
|
-
```solidity
|
|
89
|
-
error ERC20InvalidSender(address sender);
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
The `ERC20InvalidSender` error is raised when an invalid sender address attempts to perform a token transfer. It logs the `sender` address that caused the failure.
|
|
93
|
-
|
|
94
|
-
### ERC20InvalidReceiver
|
|
95
|
-
|
|
96
|
-
```solidity
|
|
97
|
-
error ERC20InvalidReceiver(address receiver);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
The `ERC20InvalidReceiver` error is raised when a transfer fails due to an invalid receiver address. It logs the `receiver` address that caused the failure.
|
|
101
|
-
|
|
102
|
-
## Functions
|
|
103
|
-
|
|
104
|
-
Functions in the contract are abstract or unimplemented in this fragment. These likely involve ERC20-style operations, such as `transfer`, `approve`, and `transferFrom`, but with privacy-preserving adjustments, including the handling of encrypted addresses and balances.
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
# PrivateERC721
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
`PrivateERC721` is an abstract implementation of the [ERC721 Non-Fungible Token (NFT) Standard](https://eips.ethereum.org/EIPS/eip-721). It includes essential features of the standard, such as token ownership, approval, transfers, and safe transfers. This contract implements key components of the ERC721 standard while maintaining support for token metadata, but without fully implementing the metadata extension.
|
|
6
|
-
|
|
7
|
-
## Prerequisites
|
|
8
|
-
|
|
9
|
-
- **Solidity Version**: `^0.8.19`
|
|
10
|
-
- **License**: MIT
|
|
11
|
-
- **Dependencies**:
|
|
12
|
-
- OpenZeppelin’s `Context`, `ERC165`, and `IERC721` contracts.
|
|
13
|
-
- `IERC721Receiver` for safe transfer checks.
|
|
14
|
-
- `IERC721Errors` interface for custom errors (related to the draft standard [IERC6093](https://eips.ethereum.org/EIPS/eip-6093)).
|
|
15
|
-
|
|
16
|
-
## Table of Contents
|
|
17
|
-
- [Events](#events)
|
|
18
|
-
- [State Variables](#state-variables)
|
|
19
|
-
- [Constructor](#constructor)
|
|
20
|
-
- [Functions](#functions)
|
|
21
|
-
- [Supports Interface](#supports-interface)
|
|
22
|
-
- [Balance Of](#balance-of)
|
|
23
|
-
- [Owner Of](#owner-of)
|
|
24
|
-
- [Name](#name)
|
|
25
|
-
- [Symbol](#symbol)
|
|
26
|
-
- [Approve](#approve)
|
|
27
|
-
- [Get Approved](#get-approved)
|
|
28
|
-
- [Set Approval For All](#set-approval-for-all)
|
|
29
|
-
- [Is Approved For All](#is-approved-for-all)
|
|
30
|
-
- [Transfer From](#transfer-from)
|
|
31
|
-
- [Safe Transfer From](#safe-transfer-from)
|
|
32
|
-
- [Private/Internal Functions](#privateinternal-functions)
|
|
33
|
-
|
|
34
|
-
## Events
|
|
35
|
-
|
|
36
|
-
## Event: `Transfer`
|
|
37
|
-
|
|
38
|
-
```solidity
|
|
39
|
-
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Description:
|
|
43
|
-
This event is emitted whenever an ERC-721 token is transferred from one address to another. It occurs during both direct token transfers (`transferFrom`) and safe token transfers (`safeTransferFrom`). This event helps external observers, such as dApps and explorers, to track the movement of tokens.
|
|
44
|
-
|
|
45
|
-
### Parameters:
|
|
46
|
-
- **`from`** (`address`): The address of the current owner of the token.
|
|
47
|
-
- **`to`** (`address`): The address that is receiving ownership of the token.
|
|
48
|
-
- **`tokenId`** (`uint256`): The unique identifier (ID) of the token being transferred.
|
|
49
|
-
|
|
50
|
-
### Important Notes:
|
|
51
|
-
- This event is emitted for both `transferFrom` and `safeTransferFrom` operations.
|
|
52
|
-
- If a token is minted, `from` will be the zero address (`address(0)`).
|
|
53
|
-
- If a token is burned, `to` will be the zero address (`address(0)`).
|
|
54
|
-
|
|
55
|
-
## Event: `Approval`
|
|
56
|
-
|
|
57
|
-
```solidity
|
|
58
|
-
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Description:
|
|
62
|
-
The `Approval` event is emitted when an owner grants or revokes permission to another account (the `approved` address) to transfer a specific token. Each ERC-721 token can only have one approved address at a time. The approval is reset when the token is transferred to a new owner.
|
|
63
|
-
|
|
64
|
-
### Parameters:
|
|
65
|
-
- **`owner`** (`address`): The current owner of the token.
|
|
66
|
-
- **`approved`** (`address`): The address that is approved to transfer the token. This can be the zero address (`address(0)`) if no account is approved.
|
|
67
|
-
- **`tokenId`** (`uint256`): The unique identifier (ID) of the token being approved for transfer.
|
|
68
|
-
|
|
69
|
-
### Important Notes:
|
|
70
|
-
- This event is specific to individual tokens, meaning approvals apply to a single `tokenId`.
|
|
71
|
-
- Approving the zero address (`address(0)`) clears the previous approval, effectively revoking approval for that token.
|
|
72
|
-
|
|
73
|
-
## Event: `ApprovalForAll`
|
|
74
|
-
|
|
75
|
-
```solidity
|
|
76
|
-
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Description:
|
|
80
|
-
This event is emitted when an owner enables or disables an operator to manage all of their assets. Operators can transfer or manage any token owned by the `owner`. The event allows for bulk approval of all tokens owned by a single account.
|
|
81
|
-
|
|
82
|
-
### Parameters:
|
|
83
|
-
- **`owner`** (`address`): The address of the token owner.
|
|
84
|
-
- **`operator`** (`address`): The address that is granted or revoked permission to manage all of the owner's tokens.
|
|
85
|
-
- **`approved`** (`bool`): A boolean value indicating whether the operator is approved (`true`) or approval is revoked (`false`).
|
|
86
|
-
|
|
87
|
-
### Important Notes:
|
|
88
|
-
- This event differs from the `Approval` event because it applies to all tokens owned by the `owner`, not a single token.
|
|
89
|
-
- This event is emitted when the `setApprovalForAll` function is called, allowing or revoking an operator’s access to all of the owner's tokens.
|
|
90
|
-
|
|
91
|
-
## State Variables
|
|
92
|
-
|
|
93
|
-
- **_name** (`string`): The name of the token collection.
|
|
94
|
-
- **_symbol** (`string`): The symbol for the token collection.
|
|
95
|
-
- **_owners** (`mapping(uint256 => address)`): Maps a token ID to its owner address.
|
|
96
|
-
- **_balances** (`mapping(address => uint256)`): Maps owner addresses to the number of tokens they own.
|
|
97
|
-
- **_tokenApprovals** (`mapping(uint256 => address)`): Maps a token ID to the approved address for that token.
|
|
98
|
-
- **_operatorApprovals** (`mapping(address => mapping(address => bool))`): Maps an owner to an operator, allowing the operator to manage all tokens owned by that owner.
|
|
99
|
-
|
|
100
|
-
## Constructor
|
|
101
|
-
|
|
102
|
-
```solidity
|
|
103
|
-
constructor(string memory name_, string memory symbol_)
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
The constructor initializes the contract by setting the name and symbol of the token collection. It accepts the following parameters:
|
|
107
|
-
|
|
108
|
-
- **`name_`**: The name of the token collection.
|
|
109
|
-
- **`symbol_`**: The symbol for the token collection.
|
|
110
|
-
|
|
111
|
-
## Functions
|
|
112
|
-
|
|
113
|
-
### Supports Interface
|
|
114
|
-
|
|
115
|
-
```solidity
|
|
116
|
-
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool)
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
Implements the `supportsInterface` function to check if the contract implements a specific interface (e.g., `IERC721`).
|
|
120
|
-
|
|
121
|
-
- **`interfaceId`**: The interface identifier to check.
|
|
122
|
-
- **Returns**: `true` if the contract supports the interface, otherwise `false`.
|
|
123
|
-
|
|
124
|
-
### Balance Of
|
|
125
|
-
|
|
126
|
-
```solidity
|
|
127
|
-
function balanceOf(address owner) public view virtual returns (uint256)
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Returns the number of tokens owned by the given address.
|
|
131
|
-
|
|
132
|
-
- **`owner`**: The address to query.
|
|
133
|
-
- **Returns**: The number of tokens owned by the address.
|
|
134
|
-
- **Reverts**: `ERC721InvalidOwner` if `owner` is the zero address.
|
|
135
|
-
|
|
136
|
-
### Owner Of
|
|
137
|
-
|
|
138
|
-
```solidity
|
|
139
|
-
function ownerOf(uint256 tokenId) public view virtual returns (address)
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Returns the owner of the given `tokenId`.
|
|
143
|
-
|
|
144
|
-
- **`tokenId`**: The ID of the token.
|
|
145
|
-
- **Returns**: The owner address of the `tokenId`.
|
|
146
|
-
- **Reverts**: If the token does not exist.
|
|
147
|
-
|
|
148
|
-
### Name
|
|
149
|
-
|
|
150
|
-
```solidity
|
|
151
|
-
function name() public view virtual returns (string memory)
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
Returns the name of the token collection.
|
|
155
|
-
|
|
156
|
-
### Symbol
|
|
157
|
-
|
|
158
|
-
```solidity
|
|
159
|
-
function symbol() public view virtual returns (string memory)
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
Returns the symbol of the token collection.
|
|
163
|
-
|
|
164
|
-
### Approve
|
|
165
|
-
|
|
166
|
-
```solidity
|
|
167
|
-
function approve(address to, uint256 tokenId) public virtual
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Approves the given address (`to`) to transfer the specified token on behalf of the owner.
|
|
171
|
-
|
|
172
|
-
- **`to`**: The address to be approved.
|
|
173
|
-
- **`tokenId`**: The ID of the token to approve.
|
|
174
|
-
|
|
175
|
-
### Get Approved
|
|
176
|
-
|
|
177
|
-
```solidity
|
|
178
|
-
function getApproved(uint256 tokenId) public view virtual returns (address)
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
Returns the approved address for the given `tokenId`.
|
|
182
|
-
|
|
183
|
-
- **`tokenId`**: The ID of the token to check.
|
|
184
|
-
- **Returns**: The address approved to transfer the `tokenId`.
|
|
185
|
-
|
|
186
|
-
### Set Approval For All
|
|
187
|
-
|
|
188
|
-
```solidity
|
|
189
|
-
function setApprovalForAll(address operator, bool approved) public virtual
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
Enables or disables approval for a third-party `operator` to manage all tokens owned by the sender.
|
|
193
|
-
|
|
194
|
-
- **`operator`**: The address of the operator.
|
|
195
|
-
- **`approved`**: `true` to approve, `false` to revoke approval.
|
|
196
|
-
|
|
197
|
-
### Is Approved For All
|
|
198
|
-
|
|
199
|
-
```solidity
|
|
200
|
-
function isApprovedForAll(address owner, address operator) public view virtual returns (bool)
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
Checks if the `operator` is approved to manage all tokens owned by `owner`.
|
|
204
|
-
|
|
205
|
-
- **`owner`**: The address of the token owner.
|
|
206
|
-
- **`operator`**: The address of the operator.
|
|
207
|
-
- **Returns**: `true` if the operator is approved, otherwise `false`.
|
|
208
|
-
|
|
209
|
-
### Transfer From
|
|
210
|
-
|
|
211
|
-
```solidity
|
|
212
|
-
function transferFrom(address from, address to, uint256 tokenId) public virtual
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
Transfers ownership of the `tokenId` from one address to another.
|
|
216
|
-
|
|
217
|
-
- **`from`**: The current owner of the token.
|
|
218
|
-
- **`to`**: The address receiving the token.
|
|
219
|
-
- **`tokenId`**: The ID of the token.
|
|
220
|
-
- **Reverts**: `ERC721InvalidReceiver` if `to` is the zero address or if the sender is not authorized to transfer the token.
|
|
221
|
-
|
|
222
|
-
### Safe Transfer From
|
|
223
|
-
|
|
224
|
-
```solidity
|
|
225
|
-
function safeTransferFrom(address from, address to, uint256 tokenId) public
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
Safely transfers a `tokenId` from one address to another, ensuring the receiver can handle ERC721 tokens.
|
|
229
|
-
|
|
230
|
-
- **`from`**: The current owner of the token.
|
|
231
|
-
- **`to`**: The address receiving the token.
|
|
232
|
-
- **`tokenId`**: The ID of the token.
|
|
233
|
-
|
|
234
|
-
### Private/Internal Functions
|
|
235
|
-
|
|
236
|
-
#### `_ownerOf`
|
|
237
|
-
|
|
238
|
-
```solidity
|
|
239
|
-
function _ownerOf(uint256 tokenId) internal view virtual returns (address)
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
Internal function that returns the owner of the `tokenId`.
|
|
243
|
-
|
|
244
|
-
#### `_isAuthorized`
|
|
245
|
-
|
|
246
|
-
```solidity
|
|
247
|
-
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool)
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
Checks if `spender` is authorized to manage `owner`'s token or the specific `tokenId`.
|
|
251
|
-
|
|
252
|
-
#### `_approve`
|
|
253
|
-
|
|
254
|
-
```solidity
|
|
255
|
-
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
Approves the address `to` to manage the `tokenId`. Optionally emits the `Approval` event.
|
|
259
|
-
|
|
260
|
-
#### `_mint`
|
|
261
|
-
|
|
262
|
-
```solidity
|
|
263
|
-
function _mint(address to, uint256 tokenId) internal
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
Mints a new token with the given `tokenId` and transfers it to the address `to`.
|
|
267
|
-
|
|
268
|
-
#### `_burn`
|
|
269
|
-
|
|
270
|
-
```solidity
|
|
271
|
-
function _burn(uint256 tokenId) internal
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
Burns (destroys) the token with the given `tokenId`.
|
|
275
|
-
|
|
276
|
-
#### `_checkOnERC721Received`
|
|
277
|
-
|
|
278
|
-
```solidity
|
|
279
|
-
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
Private function to invoke the `IERC721Receiver.onERC721Received` on the target address if it's a contract.
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# MpcCore.sol
|
|
2
|
-
|
|
3
|
-
This Solidity library, `MpcCore`, provides core functionalities for secure multi-party computation (MPC) using the COTI protocol. Below is an overview of its components and functions:
|
|
4
|
-
|
|
5
|
-
## Legend
|
|
6
|
-
|
|
7
|
-
- it = input text. This structure contains text that was encrypted by user and provided a signature to authenticate it.
|
|
8
|
-
- gc = garbled text
|
|
9
|
-
- ct = cipher text
|
|
10
|
-
- ut = user text. This structure contains 2 types of cipher texts: one by the network and one by the user key. Convenient for operations that require some times to decipher one or another.
|
|
11
|
-
|
|
12
|
-
## Types
|
|
13
|
-
The library defines several custom types using `uint256` as the base type:
|
|
14
|
-
- `gtBool`, `gtUint8`, `gtUint16`, `gtUint32`, `gtUint64`
|
|
15
|
-
- `ctBool`, `ctUint8`, `ctUint16`, `ctUint32`, `ctUint64`
|
|
16
|
-
- `lenghts`, use to differentiate the length
|
|
17
|
-
|
|
18
|
-
## Structures
|
|
19
|
-
The library defines multiple structures for handling encrypted and signed data:
|
|
20
|
-
- `itBool`, `itUint8`, `itUint16`, `itUint32`, `itUint64`: Each structure contains a inputtext (`ctBool`, `ctUint8`, etc.) and a signature (`bytes`).
|
|
21
|
-
- `utBool`, `utUint8`, `utUint16`, `utUint32`, `utUint64`: Each structure contains two usertext (`ctBool`, `ctUint8`, etc.) for user and regular data.
|
|
22
|
-
|
|
23
|
-
## Enums
|
|
24
|
-
- `MPC_TYPE`: Enum to represent different MPC data types (`SBOOL_T`, `SUINT8_T`, `SUINT16_T`, `SUINT32_T`, `SUINT64_T`).
|
|
25
|
-
- `ARGS`: Enum to represent different argument types (`BOTH_SECRET`, `LHS_PUBLIC`, `RHS_PUBLIC`).
|
|
26
|
-
|
|
27
|
-
## Functions
|
|
28
|
-
### Enum Combination Functions
|
|
29
|
-
These functions combine enum values into bytes for efficient storage and transfer:
|
|
30
|
-
- `combineEnumsToBytes2(MPC_TYPE mpcType, ARGS argsType)`: Combines an `MPC_TYPE` and `ARGS` into a `bytes2` value.
|
|
31
|
-
- `combineEnumsToBytes3(MPC_TYPE mpcType1, MPC_TYPE mpcType2, ARGS argsType)`: Combines two `MPC_TYPE` values and an `ARGS` value into a `bytes3` value.
|
|
32
|
-
- `combineEnumsToBytes4(MPC_TYPE mpcType1, MPC_TYPE mpcType2, MPC_TYPE mpcType3, ARGS argsType)`: Combines three `MPC_TYPE` values and an `ARGS` value into a `bytes4` value.
|
|
33
|
-
|
|
34
|
-
### Key Management Functions
|
|
35
|
-
- `getUserKey(bytes calldata signedEK, bytes calldata signature)`: Retrieves the user's AES encryption key in encrypted format, by using the provided public key to encrypt it - signature is used to validate the account ownership.
|
|
36
|
-
|
|
37
|
-
This library is designed to be used as part of a secure multi-party computation framework, facilitating the handling and combination of encrypted and signed data types.
|
|
38
|
-
|
|
39
|
-
# MpcInterface.sol
|
|
40
|
-
|
|
41
|
-
This Solidity interface, `ExtendedOperations`, defines a set of functions for performing various operations that are essential for secure multi-party computation (MPC) on the COTI network. Below is an overview of its components and functions:
|
|
42
|
-
|
|
43
|
-
## Functions
|
|
44
|
-
|
|
45
|
-
### Onboarding and Offboarding Functions
|
|
46
|
-
- `OnBoard(bytes1 metaData, uint256 ct)`: Onboards a new EOA. Metadata is used to define what is the data type being used (8 , 16, 32 , 64). This function is not directly called by others in MpcCore.
|
|
47
|
-
- `OffBoard(bytes1 metaData, uint256 ct)`: Offboards an EOA. Metadata is used to define what is the data type being used (8 , 16, 32 , 64). This function is not directly called by others in MpcCore.
|
|
48
|
-
- `OffBoardToUser(bytes1 metaData, uint256 ct, bytes calldata addr)`: Offboards an EOA to a user-specified address. Metadata is used to define what is the data type being used (8 , 16, 32 , 64). This function is not directly called by others in MpcCore.
|
|
49
|
-
- `SetPublic(bytes1 metaData, uint256 ct)`: Sets the data as public with the given metadata and ciphertext.
|
|
50
|
-
|
|
51
|
-
### Randomness Functions
|
|
52
|
-
- `Rand(bytes1 metaData)`: Generates a random value with the given metadata.
|
|
53
|
-
- `RandBoundedBits(bytes1 metaData, uint8 numBits)`: Generates a random value with a specified number of bits.
|
|
54
|
-
|
|
55
|
-
### Arithmetic Functions
|
|
56
|
-
- `Add(bytes3 metaData, uint256 lhs, uint256 rhs)`: Adds two values.
|
|
57
|
-
- `Sub(bytes3 metaData, uint256 lhs, uint256 rhs)`: Subtracts the second value from the first.
|
|
58
|
-
- `Mul(bytes3 metaData, uint256 lhs, uint256 rhs)`: Multiplies two values.
|
|
59
|
-
- `Div(bytes3 metaData, uint256 lhs, uint256 rhs)`: Divides the first value by the second.
|
|
60
|
-
- `Rem(bytes3 metaData, uint256 lhs, uint256 rhs)`: Computes the remainder of the division of two values.
|
|
61
|
-
|
|
62
|
-
### Bitwise Functions
|
|
63
|
-
- `And(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise AND operation.
|
|
64
|
-
- `Or(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise OR operation.
|
|
65
|
-
- `Xor(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise XOR operation.
|
|
66
|
-
- `Shl(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise shift left operation.
|
|
67
|
-
- `Shr(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise shift right operation.
|
|
68
|
-
|
|
69
|
-
### Comparison Functions
|
|
70
|
-
- `Eq(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if two values are equal.
|
|
71
|
-
- `Ne(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if two values are not equal.
|
|
72
|
-
- `Ge(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if the first value is greater than or equal to the second.
|
|
73
|
-
- `Gt(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if the first value is greater than the second.
|
|
74
|
-
- `Le(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if the first value is less than or equal to the second.
|
|
75
|
-
- `Lt(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if the first value is less than the second.
|
|
76
|
-
|
|
77
|
-
### Validation and Transfer Functions
|
|
78
|
-
- `ValidateCiphertext(bytes calldata ciphertext, bytes calldata signature)`: Validates the given ciphertext and signature.
|
|
79
|
-
- If the input is not valid, the call will revert with no return data and no additional gas will be consumed.
|
|
80
|
-
- `TransferWithAllowance(address from, address to, uint256 amount, bytes calldata signature)`: Transfers the specified amount from one address to another with the provided signature.
|
|
81
|
-
|
|
82
|
-
This interface is designed to be implemented by a contract that performs secure multi-party computation, providing essential operations such as arithmetic, bitwise, and comparison functions, as well as onboarding and offboarding participants or data.
|