Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 413388f

Browse files
authored
refactor: updates to HTTPZ (#739)
* refactor: updates to HTTPZ * docs: fix broken link
1 parent 87417d2 commit 413388f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+15948
-15946
lines changed

codegen/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'path';
44
import { validateFHETypes, validateOperators } from './common';
55
import { generateOverloads } from './generateOverloads';
66
import { ALL_OPERATORS } from './operators';
7-
import { generateSolidityFheType, generateSolidityImplLib, generateSolidityTFHELib } from './templates';
7+
import { generateSolidityFheType, generateSolidityHTTPZLib, generateSolidityImplLib } from './templates';
88
import {
99
generateSolidityOverloadTestFiles,
1010
generateSolidityUnitTestContracts,
@@ -19,7 +19,7 @@ import { ALL_FHE_TYPES } from './types';
1919
* This function performs the following steps:
2020
* 1. Generates FHE types from a JSON file.
2121
* 2. Validates and processes the list of operators.
22-
* 3. Generates Solidity source code for TFHE and implementation contracts.
22+
* 3. Generates Solidity source code for HTTPZ and implementation contracts.
2323
* 4. Splits the generated overloads into multiple shards to avoid exceeding Solidity's contract size limit.
2424
* 5. Writes the generated Solidity contracts and test files to the appropriate directories.
2525
* 6. Generates TypeScript test code for the split overloads and writes them to the test directory.
@@ -36,7 +36,7 @@ function generateAllFiles() {
3636
/// Generate core Solidity contract files.
3737
writeFileSync('lib/FheType.sol', generateSolidityFheType(ALL_FHE_TYPES));
3838
writeFileSync('lib/Impl.sol', generateSolidityImplLib(ALL_OPERATORS));
39-
writeFileSync('lib/TFHE.sol', generateSolidityTFHELib(ALL_OPERATORS, ALL_FHE_TYPES));
39+
writeFileSync('lib/HTTPZ.sol', generateSolidityHTTPZLib(ALL_OPERATORS, ALL_FHE_TYPES));
4040

4141
// TODO: For now, the testgen only supports automatically generated tests for euintXX.
4242
/// Generate overloads, split them into shards, and generate Solidity contracts to be used for TypeScript unit test files.
@@ -49,11 +49,11 @@ function generateAllFiles() {
4949
const overloadShards = splitOverloadsToShards(generateSolidityOverloadTestFiles(ALL_OPERATORS, ALL_FHE_TYPES));
5050
mkdirSync('contracts/tests', { recursive: true });
5151
overloadShards.forEach((os) => {
52-
writeFileSync(`examples/tests/TFHETestSuite${os.shardNumber}.sol`, generateSolidityUnitTestContracts(os));
52+
writeFileSync(`examples/tests/HTTPZTestSuite${os.shardNumber}.sol`, generateSolidityUnitTestContracts(os));
5353
});
5454

5555
const tsSplits: string[] = generateTypeScriptTestCode(overloadShards, numberOfTestSplits);
56-
tsSplits.forEach((split, splitIdx) => writeFileSync(`test/tfheOperations/tfheOperations${splitIdx + 1}.ts`, split));
56+
tsSplits.forEach((split, splitIdx) => writeFileSync(`test/httpzOperations/httpzOperations${splitIdx + 1}.ts`, split));
5757
}
5858

5959
generateAllFiles();

codegen/overloads.json

Lines changed: 2595 additions & 2589 deletions
Large diffs are not rendered by default.

codegen/templates.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ function handleSolidityBinaryOperatorForImpl(op: Operator): string {
130130
return (
131131
`
132132
/**
133-
* @dev Returns the FHEVM config.
133+
* @dev Returns the HTTPZ config.
134134
*/
135135
function ${op.name}(bytes32 lhs, bytes32 rhs${scalarArg}) internal returns (bytes32 result) {
136136
${scalarSection}
137-
FHEVMConfigStruct storage $ = getFHEVMConfig();
137+
HTTPZConfigStruct storage $ = getHTTPZConfig();
138138
result = ITFHEExecutor($.TFHEExecutorAddress).${op.fheLibName}(lhs, rhs, scalarByte);
139139
}` + '\n'
140140
);
@@ -166,28 +166,28 @@ ${generateInputVerifierInterface()}
166166
* @notice This library is the core implementation for computing FHE operations (e.g. add, sub, xor).
167167
*/
168168
library Impl {
169-
/// keccak256(abi.encode(uint256(keccak256("fhevm.storage.FHEVMConfig")) - 1)) & ~bytes32(uint256(0xff))
170-
bytes32 private constant FHEVMConfigLocation = 0xed8d60e34876f751cc8b014c560745351147d9de11b9347c854e881b128ea600;
169+
/// keccak256(abi.encode(uint256(keccak256("httpz.storage.HTTPZConfig")) - 1)) & ~bytes32(uint256(0xff))
170+
bytes32 private constant HTTPZConfigLocation = 0x15b1d18ad3df4183245a6a11b17d9fa31dc4c35ffbf591bdfd0f9704a799c300;
171171
172172
/**
173-
* @dev Returns the FHEVM config.
173+
* @dev Returns the HTTPZ config.
174174
*/
175-
function getFHEVMConfig() internal pure returns (FHEVMConfigStruct storage $) {
175+
function getHTTPZConfig() internal pure returns (HTTPZConfigStruct storage $) {
176176
assembly {
177-
$.slot := FHEVMConfigLocation
177+
$.slot := HTTPZConfigLocation
178178
}
179179
}
180180
181181
/**
182-
* @notice Sets the FHEVM addresses.
183-
* @param fhevmConfig FHEVM config struct that contains contract addresses.
182+
* @notice Sets the coprocessor addresses.
183+
* @param httpzConfig HTTPZ config struct that contains contract addresses.
184184
*/
185-
function setFHEVM(FHEVMConfigStruct memory fhevmConfig) internal {
186-
FHEVMConfigStruct storage $ = getFHEVMConfig();
187-
$.ACLAddress = fhevmConfig.ACLAddress;
188-
$.TFHEExecutorAddress = fhevmConfig.TFHEExecutorAddress;
189-
$.KMSVerifierAddress = fhevmConfig.KMSVerifierAddress;
190-
$.InputVerifierAddress = fhevmConfig.InputVerifierAddress;
185+
function setCoprocessor(HTTPZConfigStruct memory httpzConfig) internal {
186+
HTTPZConfigStruct storage $ = getHTTPZConfig();
187+
$.ACLAddress = httpzConfig.ACLAddress;
188+
$.TFHEExecutorAddress = httpzConfig.TFHEExecutorAddress;
189+
$.KMSVerifierAddress = httpzConfig.KMSVerifierAddress;
190+
$.InputVerifierAddress = httpzConfig.InputVerifierAddress;
191191
}
192192
`);
193193

@@ -214,10 +214,10 @@ function generateImplCoprocessorInterface(operators: Operator[]): string {
214214

215215
res.push(`
216216
/**
217-
* @title FHEVMConfigStruct
217+
* @title HTTPZConfigStruct
218218
* @notice This struct contains all addresses of core contracts, which are needed in a typical dApp.
219219
*/
220-
struct FHEVMConfigStruct {
220+
struct HTTPZConfigStruct {
221221
address ACLAddress;
222222
address TFHEExecutorAddress;
223223
address KMSVerifierAddress;
@@ -414,7 +414,7 @@ function generateInputVerifierInterface(): string {
414414
`;
415415
}
416416

417-
export function generateSolidityTFHELib(operators: Operator[], fheTypes: FheType[]): string {
417+
export function generateSolidityHTTPZLib(operators: Operator[], fheTypes: FheType[]): string {
418418
const res: string[] = [];
419419

420420
res.push(`// SPDX-License-Identifier: BSD-3-Clause-Clear
@@ -426,11 +426,11 @@ export function generateSolidityTFHELib(operators: Operator[], fheTypes: FheType
426426
${createSolidityTypeAliasesFromFheTypes(fheTypes)}
427427
428428
/**
429-
* @title TFHE
429+
* @title HTTPZ
430430
* @notice This library is the interaction point for all smart contract developers
431-
* that interact with TFHE.
431+
* that interact with the HTTPZ protocol.
432432
*/
433-
library TFHE {
433+
library HTTPZ {
434434
435435
/// @notice Returned if the input's length is greater than 64 bytes.
436436
error InputLengthAbove64Bytes(uint256 inputLength);
@@ -442,11 +442,11 @@ export function generateSolidityTFHELib(operators: Operator[], fheTypes: FheType
442442
error InputLengthAbove256Bytes(uint256 inputLength);
443443
444444
/**
445-
* @notice Sets the FHEVM addresses.
446-
* @param fhevmConfig FHEVM config struct that contains contract addresses.
445+
* @notice Sets the coprocessor addresses.
446+
* @param httpzConfig HTTPZ config struct that contains contract addresses.
447447
*/
448-
function setFHEVM(FHEVMConfigStruct memory fhevmConfig) internal {
449-
Impl.setFHEVM(fhevmConfig);
448+
function setCoprocessor(HTTPZConfigStruct memory httpzConfig) internal {
449+
Impl.setCoprocessor(httpzConfig);
450450
}
451451
`);
452452

@@ -973,7 +973,7 @@ function handleSolidityTFHEConvertPlaintextAndEinputToRespectiveType(fheType: Ad
973973
function handleUnaryOperatorForImpl(op: Operator): string {
974974
return `
975975
function ${op.name}(bytes32 ct) internal returns (bytes32 result) {
976-
FHEVMConfigStruct storage $ = getFHEVMConfig();
976+
HTTPZConfigStruct storage $ = getHTTPZConfig();
977977
result = ITFHEExecutor($.TFHEExecutorAddress).${op.fheLibName}(ct);
978978
}
979979
`;
@@ -1089,7 +1089,7 @@ function generateCustomMethodsForImpl(): string {
10891089
* If 'control's value is 'false', the result has the same value as 'ifFalse'.
10901090
*/
10911091
function select(bytes32 control, bytes32 ifTrue, bytes32 ifFalse) internal returns (bytes32 result) {
1092-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1092+
HTTPZConfigStruct storage $ = getHTTPZConfig();
10931093
result = ITFHEExecutor($.TFHEExecutorAddress).fheIfThenElse(control, ifTrue, ifFalse);
10941094
}
10951095
@@ -1105,7 +1105,7 @@ function generateCustomMethodsForImpl(): string {
11051105
bytes memory inputProof,
11061106
FheType toType
11071107
) internal returns (bytes32 result) {
1108-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1108+
HTTPZConfigStruct storage $ = getHTTPZConfig();
11091109
result = ITFHEExecutor($.TFHEExecutorAddress).verifyCiphertext(inputHandle, msg.sender, inputProof, toType);
11101110
IACL($.ACLAddress).allowTransient(result, msg.sender);
11111111
}
@@ -1120,7 +1120,7 @@ function generateCustomMethodsForImpl(): string {
11201120
bytes32 ciphertext,
11211121
FheType toType
11221122
) internal returns (bytes32 result) {
1123-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1123+
HTTPZConfigStruct storage $ = getHTTPZConfig();
11241124
result = ITFHEExecutor($.TFHEExecutorAddress).cast(ciphertext, toType);
11251125
}
11261126
@@ -1134,7 +1134,7 @@ function generateCustomMethodsForImpl(): string {
11341134
uint256 value,
11351135
FheType toType
11361136
) internal returns (bytes32 result) {
1137-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1137+
HTTPZConfigStruct storage $ = getHTTPZConfig();
11381138
result = ITFHEExecutor($.TFHEExecutorAddress).trivialEncrypt(value, toType);
11391139
}
11401140
@@ -1148,7 +1148,7 @@ function generateCustomMethodsForImpl(): string {
11481148
bytes memory value,
11491149
FheType toType
11501150
) internal returns (bytes32 result) {
1151-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1151+
HTTPZConfigStruct storage $ = getHTTPZConfig();
11521152
result = ITFHEExecutor($.TFHEExecutorAddress).trivialEncrypt(value, toType);
11531153
}
11541154
@@ -1166,7 +1166,7 @@ function generateCustomMethodsForImpl(): string {
11661166
} else {
11671167
scalarByte = 0x00;
11681168
}
1169-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1169+
HTTPZConfigStruct storage $ = getHTTPZConfig();
11701170
result = ITFHEExecutor($.TFHEExecutorAddress).fheEq(lhs, rhs, scalarByte);
11711171
}
11721172
@@ -1184,17 +1184,17 @@ function generateCustomMethodsForImpl(): string {
11841184
} else {
11851185
scalarByte = 0x00;
11861186
}
1187-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1187+
HTTPZConfigStruct storage $ = getHTTPZConfig();
11881188
result = ITFHEExecutor($.TFHEExecutorAddress).fheNe(lhs, rhs, scalarByte);
11891189
}
11901190
11911191
function rand(FheType randType) internal returns(bytes32 result) {
1192-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1192+
HTTPZConfigStruct storage $ = getHTTPZConfig();
11931193
result = ITFHEExecutor($.TFHEExecutorAddress).fheRand(randType);
11941194
}
11951195
11961196
function randBounded(uint256 upperBound, FheType randType) internal returns(bytes32 result) {
1197-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1197+
HTTPZConfigStruct storage $ = getHTTPZConfig();
11981198
result = ITFHEExecutor($.TFHEExecutorAddress).fheRandBounded(upperBound, randType);
11991199
}
12001200
@@ -1207,7 +1207,7 @@ function generateCustomMethodsForImpl(): string {
12071207
* @param account Address of the account.
12081208
*/
12091209
function allowTransient(bytes32 handle, address account) internal {
1210-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1210+
HTTPZConfigStruct storage $ = getHTTPZConfig();
12111211
IACL($.ACLAddress).allowTransient(handle, account);
12121212
}
12131213
@@ -1219,7 +1219,7 @@ function generateCustomMethodsForImpl(): string {
12191219
* @param account Address of the account.
12201220
*/
12211221
function allow(bytes32 handle, address account) internal {
1222-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1222+
HTTPZConfigStruct storage $ = getHTTPZConfig();
12231223
IACL($.ACLAddress).allow(handle, account);
12241224
}
12251225
@@ -1228,7 +1228,7 @@ function generateCustomMethodsForImpl(): string {
12281228
* with Account Abstraction when bundling several UserOps calling the TFHEExecutorCoprocessor.
12291229
*/
12301230
function cleanTransientStorageACL() internal {
1231-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1231+
HTTPZConfigStruct storage $ = getHTTPZConfig();
12321232
IACL($.ACLAddress).cleanTransientStorage();
12331233
}
12341234
@@ -1238,7 +1238,7 @@ function generateCustomMethodsForImpl(): string {
12381238
* with Account Abstraction when bundling several UserOps calling the TFHEExecutorCoprocessor.
12391239
*/
12401240
function cleanTransientStorageInputVerifier() internal {
1241-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1241+
HTTPZConfigStruct storage $ = getHTTPZConfig();
12421242
IInputVerifier($.InputVerifierAddress).cleanTransientStorage();
12431243
}
12441244
@@ -1251,7 +1251,7 @@ function generateCustomMethodsForImpl(): string {
12511251
* @return isAllowed Whether the account can access the handle.
12521252
*/
12531253
function isAllowed(bytes32 handle, address account) internal view returns (bool) {
1254-
FHEVMConfigStruct storage $ = getFHEVMConfig();
1254+
HTTPZConfigStruct storage $ = getHTTPZConfig();
12551255
return IACL($.ACLAddress).isAllowed(handle, account);
12561256
}
12571257
`;

codegen/testgen.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,17 @@ function generateIntroTestCode(shards: OverloadShard[], idxSplit: number): strin
266266
`);
267267
shards.forEach((os) => {
268268
intro.push(`
269-
import type { TFHETestSuite${os.shardNumber} } from '../../types/contracts/tests/TFHETestSuite${os.shardNumber}';
269+
import type { HTTPZTestSuite${os.shardNumber} } from '../../types/contracts/tests/HTTPZTestSuite${os.shardNumber}';
270270
`);
271271
});
272272

273273
shards.forEach((os) => {
274274
intro.push(`
275-
async function deployTfheTestFixture${os.shardNumber}(): Promise<TFHETestSuite${os.shardNumber}> {
275+
async function deployHTTPZTestFixture${os.shardNumber}(): Promise<HTTPZTestSuite${os.shardNumber}> {
276276
const signers = await getSigners();
277277
const admin = signers.alice;
278278
279-
const contractFactory = await ethers.getContractFactory('TFHETestSuite${os.shardNumber}');
279+
const contractFactory = await ethers.getContractFactory('HTTPZTestSuite${os.shardNumber}');
280280
const contract = await contractFactory.connect(admin).deploy();
281281
await contract.waitForDeployment();
282282
@@ -286,7 +286,7 @@ async function deployTfheTestFixture${os.shardNumber}(): Promise<TFHETestSuite${
286286
});
287287

288288
intro.push(`
289-
describe('TFHE operations ${idxSplit}', function () {
289+
describe('HTTPZ operations ${idxSplit}', function () {
290290
before(async function () {
291291
await initSigners(1);
292292
this.signers = await getSigners();
@@ -295,7 +295,7 @@ async function deployTfheTestFixture${os.shardNumber}(): Promise<TFHETestSuite${
295295

296296
shards.forEach((os) => {
297297
intro.push(`
298-
const contract${os.shardNumber} = await deployTfheTestFixture${os.shardNumber}();
298+
const contract${os.shardNumber} = await deployHTTPZTestFixture${os.shardNumber}();
299299
this.contract${os.shardNumber}Address = await contract${os.shardNumber}.getAddress();
300300
this.contract${os.shardNumber} = contract${os.shardNumber};
301301
`);
@@ -420,7 +420,7 @@ function ensureNumberAcceptableInBitRange(bits: number, input: number | bigint)
420420
/**
421421
* Generates Solidity unit test contracts for a given OverloadShard.
422422
*
423-
* This function creates a Solidity contract named `TFHETestSuite` followed by the shard number.
423+
* This function creates a Solidity contract named `HTTPZTestSuite` followed by the shard number.
424424
* The contract includes several public variables of different encrypted types (ebool, euint8, euint16, euint32, euint64, euint128, euint256)
425425
* and a constructor that sets the FHEVM configuration using the default configuration from `FHEVMConfig`.
426426
* It also calls the `generateLibCallTest` function to add additional test logic to the contract.
@@ -435,10 +435,10 @@ export function generateSolidityUnitTestContracts(os: OverloadShard): string {
435435
// SPDX-License-Identifier: BSD-3-Clause-Clear
436436
pragma solidity ^0.8.24;
437437
438-
import "../../lib/TFHE.sol";
438+
import "../../lib/HTTPZ.sol";
439439
import "../FHEVMConfig.sol";
440440
441-
contract TFHETestSuite${os.shardNumber} {
441+
contract HTTPZTestSuite${os.shardNumber} {
442442
ebool public resEbool;
443443
euint8 public resEuint8;
444444
euint16 public resEuint16;
@@ -451,7 +451,7 @@ export function generateSolidityUnitTestContracts(os: OverloadShard): string {
451451
ebytes256 public resEbytes256;
452452
453453
constructor() {
454-
TFHE.setFHEVM(FHEVMConfig.defaultConfig());
454+
HTTPZ.setCoprocessor(FHEVMConfig.defaultConfig());
455455
}
456456
457457
`);
@@ -473,7 +473,7 @@ export function generateSolidityUnitTestContracts(os: OverloadShard): string {
473473
*
474474
* This function iterates over the overloads in the provided overload shard and generates
475475
* a Solidity function for each overload. The generated function includes the necessary
476-
* argument processing, type casting, and the appropriate TFHE library call. The result
476+
* argument processing, type casting, and the appropriate HTTPZ library call. The result
477477
* of the library call is then allowed and assigned to the corresponding state variable.
478478
*/
479479
function generateLibCallTest(os: OverloadShard, res: string[]) {
@@ -504,10 +504,10 @@ function generateLibCallTest(os: OverloadShard, res: string[]) {
504504
res.push(`${functionTypeToEncryptedType(o.returnType)} result = ${o.unaryOperator}aProc;`);
505505
res.push('\n');
506506
} else {
507-
res.push(`${functionTypeToEncryptedType(o.returnType)} result = TFHE.${o.name}(${tfheArgs});`);
507+
res.push(`${functionTypeToEncryptedType(o.returnType)} result = HTTPZ.${o.name}(${tfheArgs});`);
508508
res.push('\n');
509509
}
510-
res.push('TFHE.allowThis(result);');
510+
res.push('HTTPZ.allowThis(result);');
511511
res.push(`${stateVar[functionTypeToEncryptedType(o.returnType) as keyof typeof stateVar]} = result;
512512
}
513513
`);
@@ -586,13 +586,13 @@ function signatureContractEncryptedSignature(s: OverloadSignature): string {
586586
function castExpressionToType(argExpr: string, outputType: FunctionType): string {
587587
switch (outputType.type) {
588588
case ArgumentType.Euint:
589-
return `TFHE.asEuint${outputType.bits}(${argExpr}, inputProof)`;
589+
return `HTTPZ.asEuint${outputType.bits}(${argExpr}, inputProof)`;
590590
case ArgumentType.Uint:
591591
return argExpr;
592592
case ArgumentType.Ebool:
593-
return `TFHE.asEbool(${argExpr})`;
593+
return `HTTPZ.asEbool(${argExpr})`;
594594
// case ArgumentType.Ebytes:
595-
// return `TFHE.asEbytes${outputType.bits / 8}(${argExpr})`;
595+
// return `HTTPZ.asEbytes${outputType.bits / 8}(${argExpr})`;
596596
}
597597
}
598598

0 commit comments

Comments
 (0)