-
Notifications
You must be signed in to change notification settings - Fork 2.6k
chore(common): checkSignatures, ZamaConfig.sol, mock publicDecrypt an… #1316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
0xalexbel
commented
Nov 12, 2025
- 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.
| @@ -1,3 +1,4 @@ | |||
| ENV_HOST_ADDRESSES_PATH="addresses/.env.host" | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"; | |||
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// 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", |
There was a problem hiding this comment.
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!'); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
c1d52a0 to
fd33308
Compare