Skip to content

Conversation

@0xalexbel
Copy link
Contributor

  • FHE.sol : remove verifySignatures
  • FHE.sol : add checkSignatures
  • New ZamaConfig.sol
  • Add local coprocessor config
  • Add mock publicDecrypt function
  • Add publicDecrypt tests
  • Add verifySignatures tests
  • Refactor the HH mock typescript code: fhevmjsMock.ts, instance.ts etc.
  • host-contracts & library-solidity must have the same mock code.

@0xalexbel 0xalexbel requested review from a team as code owners November 12, 2025 15:12
@cla-bot cla-bot bot added the cla-signed label Nov 12, 2025
@@ -1,3 +1,4 @@
ENV_HOST_ADDRESSES_PATH="addresses/.env.host"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an environment variable used only for tests, maybe you could define it in the `hardhat.config.js file, similar to what we do at the Gateway.

Same here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Isaac, don't put this in the .env, this was not needed until now, I don't see the point.

@@ -0,0 +1,133 @@
import { FlatCompat } from "@eslint/eslintrc";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are all those eslint files needed now? linter was working before without those.

"scripts": {
"compile": "HARDHAT_NETWORK=hardhat npm run deploy:emptyProxies && cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile",
"deploy:emptyProxies": "hardhat task:deployEmptyUUPSProxies && hardhat compile:specific --contract 'contracts/immutable' && hardhat task:deployPauserSet",
"addresses": "npm run deploy:emptyProxies",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: having this "addresses" script seems a bit redundant already having "deploy:emptyProxies"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what's the point indeed of changing those. Also this might break the e2e deployment script made by @enitrat but I am not sure.

/// @notice Reverts if the KMS signatures verification against the provided handles and public decryption data
/// fails.
/// @dev The function MUST be called inside a public decryption callback function of a dApp contract
/// to verify the signatures and prevent fake decryption results for being submitted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// to verify the signatures and prevent fake decryption results for being submitted.
/// to verify the signatures and prevent fake decryption results from being submitted.

"addresses": "npm run deploy:emptyProxies",
"tsc": "tsc --project tsconfig.json --noEmit",
"clean": "rm -rf addresses dist build artifacts cache typechain-types",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: note that the typechain is also generated when running "hardhat compile", so maybe not needed to have a separate script for generating the typechain.

expect.fail('Expected an error to be thrown - Bob should not be able to reencrypt Alice balance');
} catch (error) {
expect(error.message).to.equal('User is not authorized to reencrypt this handle!');
expect((error as any).message).to.equal('User is not authorized to reencrypt this handle!');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to use error as Error to avoid the usage of any.

dave: HardhatEthersSigner;
eve: HardhatEthersSigner;
fred: HardhatEthersSigner;
alice: HardhatEthersSigner | HDNodeWallet;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need HDNodeWallet here?

return getDecryptor().decryptEbytes256(await getCiphertext(handle, ethers));
}
};
export { getTxHCUFromTxReceipt, awaitCoprocessor };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering what the intention of re-exporting these two functions here is, if they're already exported by fhevmjsMocked?

describe('Pausing and Unpausing Tasks', function () {
let pauserSet;
let acl;
let acl: ACL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe doesn't make much sense to define its type if you then need to do the type assertion as ACL in line 19. In such a case, should the pauserSet also have its type defined to be consistent?

}
return coprocessorSigners;
function loadEnvFhevmMockConfig(): EnvFhevmMockConfig {
const hostEnvPath = getRequiredEnvVar('ENV_HOST_ADDRESSES_PATH');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need this to be inside a .env?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for getting identical code for fhevmjsMocked between host and lib?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't have a lot of context here, but env var should be kept only for infra / production tools as much as possible, if we can avoid them for test-only purposes, then it's much better

INPUT_VERIFICATION_ADDRESS="0x812b06e1CDCE800494b79fFE4f925A504a9A9810"
NUM_KMS_NODES="1"
KMS_THRESHOLD="1"
# In practice, the `PUBLIC_DECRYPTION_THRESHOLD` is currently set to `floor(n/2) + 1` with `n`` the number of KMS nodes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this comment, can you remove it? This changed several times very recently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah but this was already inside the host-contracts' .env.
Let's keep it then, even if i am not sure.

Copy link
Contributor

@melanciani melanciani Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to remove and replace by

Should be the same as `PUBLIC_DECRYPTION_THRESHOLD` set in the Gateway

same for host

function getEthereumProtocolId() internal pure returns (uint256) {
/// @note Zama Ethereum protocol id is '1'
return 1;
/// @dev chainid == 11155111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong chain id here

/// @dev chainid == 11155111
function _getLocalProtocolId() private pure returns (uint256) {
/// @note Development protocol id is '100000 + Zama Ethereum protocol id'
return 100001;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe for local net, send back type(uint256).max , just in case.
10001 seems too small

@0xalexbel 0xalexbel force-pushed the alexB/check-signatures branch from c1d52a0 to fd33308 Compare November 14, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants