Skip to content

Commit

Permalink
feat: typos, removed unsafeBurn, modify unsafeMint
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Nov 27, 2024
1 parent 7555d43 commit 4252f11
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pnpm add fhevm-contracts

To write Solidity contracts that use `TFHE` and/or `Gateway`, it is required to set different contract addresses.

Fortunately, [the fhevm repo)](https://github.com/zama-ai/fhevm), one of this repo's dependencies, exports config files
that can be inherited to simplify the process.
Fortunately, [the fhevm repo](https://github.com/zama-ai/fhevm), one of this repo's dependencies, exports config files
that can be inherited to simplify the process. The config should be the first to be imported in the order of the inherited contracts.

#### Using the mock network (for testing)

Expand Down Expand Up @@ -63,7 +63,7 @@ contract MyERC20 is SepoliaZamaFHEVMConfig, EncryptedERC20 {

## Available contracts

As of version 0.2, these Solidity templates include governance-related and token-related contracts.
These Solidity templates include governance-related and token-related contracts.

### Token

Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/Comp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ abstract contract Comp is IComp, EncryptedERC20, EIP712, Ownable2Step {
string memory version_,
uint64 totalSupply_
) EncryptedERC20(name_, symbol_) EIP712(name_, version_) Ownable(owner_) {
_unsafeMint(owner_, TFHE.asEuint64(totalSupply_));
_unsafeMint(owner_, totalSupply_);
_totalSupply = totalSupply_;

/// @dev Define the constant in the storage.
Expand Down
16 changes: 5 additions & 11 deletions contracts/token/ERC20/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,23 @@ abstract contract EncryptedERC20 is IEncryptedERC20 {
}

/**
* @dev It does not incorporate any underflow check. It must be implemented
* @dev It does not incorporate any overflow check. It must be implemented
* by the function calling it.
*/
function _unsafeBurn(address account, euint64 amount) internal virtual {
euint64 newBalanceAccount = TFHE.sub(_balances[account], amount);
_balances[account] = newBalanceAccount;
TFHE.allowThis(newBalanceAccount);
TFHE.allow(newBalanceAccount, account);
emit Transfer(account, address(0));
function _unsafeMint(address account, uint64 amount) internal virtual {
_unsafeMintNoEvent(account, amount);
emit Transfer(address(0), account);
}

/**
* @dev It does not incorporate any overflow check. It must be implemented
* by the function calling it.
*/
function _unsafeMint(address account, euint64 amount) internal virtual {
function _unsafeMintNoEvent(address account, uint64 amount) internal virtual {
euint64 newBalanceAccount = TFHE.add(_balances[account], amount);
_balances[account] = newBalanceAccount;
TFHE.allowThis(newBalanceAccount);
TFHE.allow(newBalanceAccount, account);
emit Transfer(address(0), account);
}

function _transfer(address from, address to, euint64 amount, ebool isTransferable) internal virtual {
Expand All @@ -187,11 +183,9 @@ abstract contract EncryptedERC20 is IEncryptedERC20 {
if (from == address(0)) {
revert SenderAddressNull();
}

if (to == address(0)) {
revert ReceiverAddressNull();
}

/// Add to the balance of `to` and subract from the balance of `from`.
euint64 transferValue = TFHE.select(isTransferable, amount, TFHE.asEuint64(0));
euint64 newBalanceTo = TFHE.add(_balances[to], transferValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract contract EncryptedERC20Mintable is Ownable2Step, EncryptedERC20 {
* @param amount Amount of tokens to mint.
*/
function mint(uint64 amount) public virtual onlyOwner {
_unsafeMint(msg.sender, TFHE.asEuint64(amount));
_unsafeMint(msg.sender, amount);
/// @dev Since _totalSupply is not encrypted and _totalSupply >= balances[msg.sender],
/// the next line contains an overflow check for the encrypted operation above.
_totalSupply = _totalSupply + amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract contract EncryptedERC20WithErrorsMintable is Ownable2Step, EncryptedERC
* @param amount Amount of tokens to mint.
*/
function mint(uint64 amount) public virtual onlyOwner {
_unsafeMint(msg.sender, TFHE.asEuint64(amount));
_unsafeMint(msg.sender, amount);
/// @dev Since _totalSupply is not encrypted and _totalSupply >= balances[msg.sender],
/// the next line contains an overflow check for the encrypted operation above.
_totalSupply = _totalSupply + amount;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@
"@openzeppelin/contracts-upgradeable": "5.0.2",
"extra-bigint": "^1.1.18",
"sqlite3": "^5.1.7"
}
},
"packageManager": "[email protected]+sha1.9217c800d4ab947a7aee520242a7b70d64fc7638"
}

0 comments on commit 4252f11

Please sign in to comment.