mirror of
https://github.com/zama-ai/fhevm-solidity.git
synced 2026-04-17 03:00:47 -04:00
feat() add isInitialized function
This commit is contained in:
@@ -536,6 +536,17 @@ import "./Common.sol";
|
||||
import "./Impl.sol";
|
||||
|
||||
library TFHE {""")
|
||||
|
||||
to_print_is_initialized = """
|
||||
function isInitialized(euint{i} v) internal pure returns (bool) {{
|
||||
return euint{i}.unwrap(v) != 0;
|
||||
}}
|
||||
"""
|
||||
|
||||
f.write(to_print_is_initialized.format(i=8))
|
||||
f.write(to_print_is_initialized.format(i=16))
|
||||
f.write(to_print_is_initialized.format(i=32))
|
||||
|
||||
|
||||
to_print_no_cast = """
|
||||
function {f}(euint{i} a, euint{j} b) internal view returns (euint{k}) {{
|
||||
|
||||
@@ -63,7 +63,7 @@ contract BlindAuction is EIP712WithModifier {
|
||||
function bid(bytes calldata encryptedValue) public onlyBeforeEnd {
|
||||
euint32 value = TFHE.asEuint32(encryptedValue);
|
||||
euint32 existingBid = bids[msg.sender];
|
||||
if (euint32.unwrap(existingBid) != 0) {
|
||||
if (TFHE.isInitialized(existingBid)) {
|
||||
euint32 isHigher = TFHE.lt(existingBid, value);
|
||||
// Update bid with value
|
||||
bids[msg.sender] = TFHE.cmux(isHigher, value, existingBid);
|
||||
@@ -78,7 +78,7 @@ contract BlindAuction is EIP712WithModifier {
|
||||
tokenContract.transferFrom(msg.sender, address(this), value);
|
||||
}
|
||||
euint32 currentBid = bids[msg.sender];
|
||||
if (euint32.unwrap(highestBid) == 0) {
|
||||
if (!TFHE.isInitialized(highestBid)) {
|
||||
highestBid = currentBid;
|
||||
} else {
|
||||
highestBid = TFHE.cmux(
|
||||
|
||||
12
lib/TFHE.sol
12
lib/TFHE.sol
@@ -6,6 +6,18 @@ import "./Common.sol";
|
||||
import "./Impl.sol";
|
||||
|
||||
library TFHE {
|
||||
function isInitialized(euint8 v) internal pure returns (bool) {
|
||||
return euint8.unwrap(v) != 0;
|
||||
}
|
||||
|
||||
function isInitialized(euint16 v) internal pure returns (bool) {
|
||||
return euint16.unwrap(v) != 0;
|
||||
}
|
||||
|
||||
function isInitialized(euint32 v) internal pure returns (bool) {
|
||||
return euint32.unwrap(v) != 0;
|
||||
}
|
||||
|
||||
function add(euint8 a, euint8 b) internal view returns (euint8) {
|
||||
return euint8.wrap(Impl.add(euint8.unwrap(a), euint8.unwrap(b)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user