Skip to content

Commit

Permalink
Merge pull request #632 from zama-ai/improvedNpmIgnore
Browse files Browse the repository at this point in the history
Improved npm ignore
  • Loading branch information
jatZama authored Dec 3, 2024
2 parents 4e003a6 + b629634 commit 909caa6
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 118 deletions.
2 changes: 1 addition & 1 deletion docs/fundamentals/first_step/decrypt.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract EncryptedCounter3 is MockZamaFHEVMConfig, MockZamaGatewayConfig, Gatewa
uint8 public decryptedCounter;
constructor() {
Gateway.setGateway(Gateway.defaultGatewayAddress());
Gateway.setGateway(GatewayConfig.defaultGatewayContract());
// Initialize counter with an encrypted zero value
counter = TFHE.asEuint8(0);
Expand Down
3 changes: 2 additions & 1 deletion examples/BlindAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.24;

import "../lib/TFHE.sol";
import "./FHEVMConfig.sol";
import "./GatewayConfig.sol";
import "./EncryptedERC20.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "../gateway/GatewayCaller.sol";
Expand Down Expand Up @@ -75,7 +76,7 @@ contract BlindAuction is Ownable2Step, GatewayCaller {
bool isStoppable
) Ownable(msg.sender) {
TFHE.setFHEVM(FHEVMConfig.defaultConfig());
Gateway.setGateway(Gateway.defaultGatewayAddress());
Gateway.setGateway(GatewayConfig.defaultGatewayContract());
beneficiary = _beneficiary;
tokenContract = _tokenContract;
endTime = block.timestamp + biddingTime;
Expand Down
19 changes: 19 additions & 0 deletions examples/GatewayConfig.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import "fhevm-core-contracts/addresses/GatewayContractAddress.sol";

/**
* @title FHEVMConfig
* @notice This library returns all addresses for the ACL, TFHEExecutor, FHEPayment,
* and KMSVerifier contracts.
*/
library GatewayConfig {
/**
* @notice This function returns a struct containing all contract addresses.
* @dev It returns an immutable struct.
*/
function defaultGatewayContract() internal pure returns (address) {
return GATEWAY_CONTRACT_PREDEPLOY_ADDRESS;
}
}
3 changes: 2 additions & 1 deletion examples/TestAsyncDecrypt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.24;

import "../lib/TFHE.sol";
import "./FHEVMConfig.sol";
import "./GatewayConfig.sol";
import "../gateway/GatewayCaller.sol";

/// @notice Contract for testing asynchronous decryption using the Gateway
Expand Down Expand Up @@ -45,7 +46,7 @@ contract TestAsyncDecrypt is GatewayCaller {
/// @notice Constructor to initialize the contract and set up encrypted values
constructor() {
TFHE.setFHEVM(FHEVMConfig.defaultConfig());
Gateway.setGateway(Gateway.defaultGatewayAddress());
Gateway.setGateway(GatewayConfig.defaultGatewayContract());

/// @dev Initialize encrypted variables with sample values
xBool = TFHE.asEbool(true);
Expand Down
13 changes: 4 additions & 9 deletions gateway/lib/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pragma solidity ^0.8.24;

import "./GatewayContractAddress.sol";
import "../../lib/Impl.sol";
import "fhevm-core-contracts/addresses/ACLAddress.sol";

Expand All @@ -25,18 +24,14 @@ interface IGatewayContract {
) external returns (uint256);
}

library Gateway {
struct GatewayConfigStruct {
address GatewayContractAddress;
}
struct GatewayConfigStruct {
address GatewayContractAddress;
}

library Gateway {
// keccak256(abi.encode(uint256(keccak256("fhevm.storage.GatewayConfig")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant GatewayLocation = 0x93ab6e17f2c461cce6ea5d4ec117e51dda77a64affc2b2c05f8cd440def0e700;

function defaultGatewayAddress() internal pure returns (address) {
return GATEWAY_CONTRACT_PREDEPLOY_ADDRESS;
}

function getGetwayConfig() internal pure returns (GatewayConfigStruct storage $) {
assembly {
$.slot := GatewayLocation
Expand Down
1 change: 0 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as path from 'path';
import CustomProvider from './CustomProvider';
// Adjust the import path as needed
import './tasks/accounts';
import './tasks/etherscanVerify';
import './tasks/getEthereumAddress';
import './tasks/taskDeploy';
import './tasks/taskGatewayRelayer';
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fhevm",
"description": "A Solidity library for interacting with the Zama Blockchain",
"version": "0.6.0-5",
"version": "0.6.0-6",
"engines": {
"node": ">=20.0.0"
},
Expand Down
93 changes: 0 additions & 93 deletions tasks/etherscanVerify.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tasks/taskDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task('task:deployGateway')
});
await Gateway.waitForDeployment();
const GatewayContractAddress = await Gateway.getAddress();
const envConfig = dotenv.parse(fs.readFileSync('gateway/.env.gateway'));
const envConfig = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.gateway'));
if (GatewayContractAddress !== envConfig.GATEWAY_CONTRACT_PREDEPLOY_ADDRESS) {
throw new Error(
`The nonce of the deployer account is not null. Please use another deployer private key or relaunch a clean instance of the fhEVM`,
Expand Down
21 changes: 14 additions & 7 deletions tasks/taskGatewayRelayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ task('task:computeGatewayAddress')
from: deployerAddress,
nonce: 1, // deployer is supposed to have nonce 0 when deploying GatewayContract (0 nonce for implementation, +1 for UUPS)
});
const envFilePath = path.join(__dirname, '../gateway/.env.gateway');
const envFilePath = path.join(__dirname, '../node_modules/fhevm-core-contracts/addresses/.env.gateway');
const content = `GATEWAY_CONTRACT_PREDEPLOY_ADDRESS=${gatewayContractAddressPrecomputed}`;
try {
fs.writeFileSync(envFilePath, content, { flag: 'w' });
console.log('gatewayContractAddress written to gateway/.env.gateway successfully!');
console.log(
'gatewayContractAddress written to node_modules/fhevm-core-contracts/addresses/.env.gateway successfully!',
);
} catch (err) {
console.error('Failed to write to gateway/.env.gateway:', err);
console.error('Failed to write to node_modules/fhevm-core-contracts/addresses/.env.gateway:', err);
}

const solidityTemplate = `// SPDX-License-Identifier: BSD-3-Clause-Clear
Expand All @@ -40,10 +42,15 @@ address constant GATEWAY_CONTRACT_PREDEPLOY_ADDRESS = ${gatewayContractAddressPr
`;

try {
fs.writeFileSync('./gateway/lib/GatewayContractAddress.sol', solidityTemplate, { encoding: 'utf8', flag: 'w' });
console.log('gateway/lib/GatewayContractAddress.sol file has been generated successfully.');
fs.writeFileSync('node_modules/fhevm-core-contracts/addresses/GatewayContractAddress.sol', solidityTemplate, {
encoding: 'utf8',
flag: 'w',
});
console.log(
'node_modules/fhevm-core-contracts/addresses/GatewayContractAddress.sol file has been generated successfully.',
);
} catch (error) {
console.error('Failed to write gateway/lib/GatewayContractAddress.sol', error);
console.error('Failed to write node_modules/fhevm-core-contracts/addresses/GatewayContractAddress.sol', error);
}
});

Expand Down Expand Up @@ -115,7 +122,7 @@ task('task:launchFhevm')
}
await hre.run('task:deployGateway', { privateKey: privKeyDeployer, ownerAddress: deployerAddress });

const parsedEnv = dotenv.parse(fs.readFileSync('gateway/.env.gateway'));
const parsedEnv = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.gateway'));
const gatewayContractAddress = parsedEnv.GATEWAY_CONTRACT_PREDEPLOY_ADDRESS;

await hre.run('task:addRelayer', {
Expand Down
2 changes: 1 addition & 1 deletion test/asyncDecrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const currentTime = (): string => {
return now.toLocaleTimeString('en-US', { hour12: true, hour: 'numeric', minute: 'numeric', second: 'numeric' });
};

const parsedEnv = dotenv.parse(fs.readFileSync('gateway/.env.gateway'));
const parsedEnv = dotenv.parse(fs.readFileSync('node_modules/fhevm-core-contracts/addresses/.env.gateway'));
let relayer: Wallet;
if (networkName === 'hardhat') {
const privKeyRelayer = process.env.PRIVATE_KEY_GATEWAY_RELAYER;
Expand Down

0 comments on commit 909caa6

Please sign in to comment.