Skip to content

Commit

Permalink
chore: replace cmux by select
Browse files Browse the repository at this point in the history
  • Loading branch information
jatZama committed Apr 5, 2024
1 parent c3ce9ab commit d37d4a2
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion contracts/DAO/Comp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ contract Comp is EncryptedERC20, Ownable2Step {
require(from != address(0), "Comp::_transferTokens: cannot transfer from the zero address");
require(to != address(0), "Comp::_transferTokens: cannot transfer to the zero address");
// Add to the balance of `to` and subract from the balance of `from`.
euint64 amountTransferred = TFHE.cmux(isTransferable, amount, TFHE.asEuint64(0));
euint64 amountTransferred = TFHE.select(isTransferable, amount, TFHE.asEuint64(0));
balances[to] = balances[to] + amountTransferred;
balances[from] = balances[from] - amountTransferred;
uint256 transferId = saveError(errorCode);
Expand Down
4 changes: 2 additions & 2 deletions contracts/DAO/GovernorZama.sol
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ contract GovernorZama is Reencrypt {
require(receipt.hasVoted == false, "GovernorAlpha::_castVote: voter already voted");
euint64 votes = comp.getPriorVotes(voter, proposal.startBlock);

proposal.forVotes = TFHE.cmux(support, proposal.forVotes + votes, proposal.forVotes);
proposal.againstVotes = TFHE.cmux(support, proposal.againstVotes, proposal.againstVotes + votes);
proposal.forVotes = TFHE.select(support, proposal.forVotes + votes, proposal.forVotes);
proposal.againstVotes = TFHE.select(support, proposal.againstVotes, proposal.againstVotes + votes);

receipt.hasVoted = true;
receipt.support = support;
Expand Down
4 changes: 2 additions & 2 deletions contracts/token/ERC20/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ abstract contract EncryptedERC20 is Reencrypt, EncryptedErrors {
// makes sure the owner has enough tokens
ebool canTransfer = TFHE.le(amount, balances[owner]);
ebool isTransferable = TFHE.and(canTransfer, allowedTransfer);
_approve(owner, spender, TFHE.cmux(isTransferable, currentAllowance - amount, currentAllowance));
_approve(owner, spender, TFHE.select(isTransferable, currentAllowance - amount, currentAllowance));
ebool isNotTransferableButIsApproved = TFHE.and(TFHE.not(canTransfer), allowedTransfer);
errorCode = changeErrorIf(
isNotTransferableButIsApproved, // should indeed check that spender is approved to not leak information
Expand All @@ -173,7 +173,7 @@ abstract contract EncryptedERC20 is Reencrypt, EncryptedErrors {
euint8 errorCode
) internal virtual {
// Add to the balance of `to` and subract from the balance of `from`.
euint64 amountTransferred = TFHE.cmux(isTransferable, amount, TFHE.asEuint64(0));
euint64 amountTransferred = TFHE.select(isTransferable, amount, TFHE.asEuint64(0));
balances[to] = balances[to] + amountTransferred;
balances[from] = balances[from] - amountTransferred;
uint256 transferId = saveError(errorCode);
Expand Down
8 changes: 4 additions & 4 deletions contracts/utils/EncryptedErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ abstract contract EncryptedErrors {
function defineErrorIf(ebool condition, uint8 indexCode) internal view returns (euint8) {
require(indexCode != 0, "indexCode must be greater than 0");
require(indexCode <= totalNumErrors, "indexCode must be a valid error code");
euint8 errorCode = TFHE.cmux(condition, errorCodes[indexCode], errorCodes[0]);
euint8 errorCode = TFHE.select(condition, errorCodes[indexCode], errorCodes[0]);
return errorCode;
}

Expand All @@ -95,7 +95,7 @@ abstract contract EncryptedErrors {
function defineErrorIfNot(ebool condition, uint8 indexCode) internal view returns (euint8) {
require(indexCode != 0, "indexCode must be greater than 0");
require(indexCode <= totalNumErrors, "indexCode must be a valid error code");
euint8 errorCode = TFHE.cmux(condition, errorCodes[0], errorCodes[indexCode]);
euint8 errorCode = TFHE.select(condition, errorCodes[0], errorCodes[indexCode]);
return errorCode;
}

Expand All @@ -109,7 +109,7 @@ abstract contract EncryptedErrors {
*/
function changeErrorIf(ebool condition, uint8 indexCode, euint8 errorCode) internal view returns (euint8) {
require(indexCode <= totalNumErrors, "indexCode must be a valid error code");
return TFHE.cmux(condition, errorCodes[indexCode], errorCode);
return TFHE.select(condition, errorCodes[indexCode], errorCode);
}

/**
Expand All @@ -122,7 +122,7 @@ abstract contract EncryptedErrors {
*/
function changeErrorIfNot(ebool condition, uint8 indexCode, euint8 errorCode) internal view returns (euint8) {
require(indexCode <= totalNumErrors, "indexCode must be a valid error code");
return TFHE.cmux(condition, errorCode, errorCodes[indexCode]);
return TFHE.select(condition, errorCode, errorCodes[indexCode]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.10.0",
"ethers": "^6.11.1",
"fhevm": "0.4.0-3",
"fhevm": "0.4.0-5",
"fhevmjs": "0.4.0-7",
"fs-extra": "^10.1.0",
"hardhat": "^2.21.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d37d4a2

Please sign in to comment.