Skip to content

Commit

Permalink
fix: added internal _mint and made _totalSupply internal
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Feb 28, 2024
1 parent e599b13 commit fd3ca87
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions contracts/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors {
event Approval(address indexed owner, address indexed spender);
event Mint(address indexed to, uint64 amount);

uint64 private _totalSupply;
uint64 internal _totalSupply;
string private _name;
string private _symbol;
uint8 public constant decimals = 6;

Check warning on line 29 in contracts/EncryptedERC20.sol

View workflow job for this annotation

GitHub Actions / ci

Constant name must be in capitalized SNAKE_CASE

// A mapping from transferId to the AllowedErrorReencryption
// A mapping from transferId to the AllowedErrorReencryption.
mapping(uint256 => AllowedErrorReencryption) internal allowedErrorReencryptions;

Check warning on line 32 in contracts/EncryptedERC20.sol

View workflow job for this annotation

GitHub Actions / ci

Main key parameter in mapping allowedErrorReencryptions is not named

Check warning on line 32 in contracts/EncryptedERC20.sol

View workflow job for this annotation

GitHub Actions / ci

Value parameter in mapping allowedErrorReencryptions is not named

// A mapping from address to an encrypted balance.
Expand All @@ -55,16 +55,21 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors {
return _symbol;
}

// Returns the total supply of the token
// Returns the total supply of the token.
function totalSupply() public view virtual returns (uint64) {
return _totalSupply;
}

// Sets the balance of the owner to the given encrypted balance.
// Increase owner's balance by the given `mintedAmount`.
function mint(uint64 mintedAmount) public virtual onlyOwner {
balances[owner()] = TFHE.add(balances[owner()], mintedAmount); // overflow impossible because of next line
_totalSupply = _totalSupply + mintedAmount;
emit Mint(owner(), mintedAmount);
_mint(mintedAmount);
}

// Increase sender's balance by the given `amount`.
function _mint(uint64 amount) internal virtual {
balances[msg.sender] = TFHE.add(balances[msg.sender], amount); // overflow impossible because of next line
_totalSupply = _totalSupply + amount;
emit Mint(msg.sender, amount);
}

// Transfers an encrypted amount from the message sender address to the `to` address.
Expand Down Expand Up @@ -93,7 +98,7 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors {
}

// Returns the encrypted balance of the caller.
function balanceOfMe() public view returns (euint64) {
function balanceOfMe() public view virtual returns (euint64) {
return balances[msg.sender];
}

Expand All @@ -112,7 +117,7 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors {
}

// Returns the remaining number of tokens that `spender` is allowed to spend
// on behalf of the caller. The returned ciphertext is under the caller public FHE key.
// on behalf of the `owner`. The returned ciphertext is under the caller's `publicKey`.
function allowance(
address owner,
address spender,
Expand Down Expand Up @@ -177,8 +182,9 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors {
euint8 errorCode
) internal virtual {
// Add to the balance of `to` and subract from the balance of `from`.
balances[to] = balances[to] + TFHE.cmux(isTransferable, amount, TFHE.asEuint64(0));
balances[from] = balances[from] - TFHE.cmux(isTransferable, amount, TFHE.asEuint64(0));
euint64 amountTransferred = TFHE.cmux(isTransferable, amount, TFHE.asEuint64(0));
balances[to] = balances[to] + amountTransferred;
balances[from] = balances[from] - amountTransferred;
uint256 transferId = saveError(errorCode);
emit Transfer(transferId, from, to);
AllowedErrorReencryption memory allowedErrorReencryption = AllowedErrorReencryption(
Expand All @@ -188,11 +194,13 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors {
allowedErrorReencryptions[transferId] = allowedErrorReencryption;
}

// Returns the error code corresponding to transferId.
// The returned ciphertext is under the caller's `publicKey`.
function reencryptError(
uint256 transferId,
bytes32 publicKey,
bytes calldata signature
) external view onlySignedPublicKey(publicKey, signature) returns (bytes memory) {
) external view virtual onlySignedPublicKey(publicKey, signature) returns (bytes memory) {
AllowedErrorReencryption memory allowedErrorReencryption = allowedErrorReencryptions[transferId];
euint8 errorCode = allowedErrorReencryption.errorCode;
require(TFHE.isInitialized(errorCode), "Invalid transferId");
Expand Down

0 comments on commit fd3ca87

Please sign in to comment.