From bd65f767dcc1500177095e933658572c28c57cab Mon Sep 17 00:00:00 2001 From: yuxizama <157474013+yuxizama@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:02:46 +0100 Subject: [PATCH 1/5] docs: minor adjustments updates whitepaper (#638) * docs: update the whitepaper * docs: update the welcome page * docs: prettier --------- Co-authored-by: Aurora Poppyseed <30662672+poppyseedDev@users.noreply.github.com> --- README.md | 4 ++-- docs/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9f530431..9f01720d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@

- 📃 Read white paper | 📒 Documentation | 💛 Community support | 📚 FHE resources by Zama + 📃 Read white paper | 📒 Documentation | 💛 Community support | 📚 FHE resources by Zama

@@ -130,7 +130,7 @@ _More examples are available [here](https://github.com/zama-ai/fhevm/tree/main/e ↑ Back to top

-> [!Note] >**Zama 5-Question Developer Survey** +> [!Note] > **Zama 5-Question Developer Survey** > > We want to hear from you! Take 1 minute to share your thoughts and helping us enhance our documentation and libraries. 👉 **[Click here](https://www.zama.ai/developer-survey)** to participate. diff --git a/docs/README.md b/docs/README.md index 93a2e535..113aed84 100644 --- a/docs/README.md +++ b/docs/README.md @@ -27,7 +27,7 @@ Learn the basics of fhEVM, set it up, and make it run with ease. Start developing fhEVM smart contracts in Solidity by exploring its core features, discovering essential guides, and learning more with user-friendly tutorials. -
FundamentalsExplore core features.build1.png
GuidesLearn further.build2.png
TutorialsLearn more with tutorials.build3.png
+
FundamentalsExplore core features.build1.png
GuidesLearn more about fhEVM implementation.build2.png
TutorialsBuild quickly with tutorials.build3.png
## Explore more From 3a1d900d6bf93d22257edc10757b71da51d73250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Thu, 5 Dec 2024 15:45:31 +0100 Subject: [PATCH 2/5] 0.6.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a94c6a9e..aa94e9bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fhevm", - "version": "0.6.0-8", + "version": "0.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "fhevm", - "version": "0.6.0-8", + "version": "0.6.0", "license": "BSD-3-Clause-Clear", "dependencies": { "@openzeppelin/contracts": "^5.0.1", diff --git a/package.json b/package.json index 6f02fe2e..46ef8b2c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fhevm", "description": "A Solidity library for interacting with the Zama Blockchain", - "version": "0.6.0-8", + "version": "0.6.0", "engines": { "node": ">=20.0.0" }, From 6bcb20a429c4119528138e3903575abd8d277308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Mon, 9 Dec 2024 23:17:01 +0100 Subject: [PATCH 3/5] docs: update gateway url --- docs/getting_started/ethereum.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/getting_started/ethereum.md b/docs/getting_started/ethereum.md index 6452f991..20632414 100644 --- a/docs/getting_started/ethereum.md +++ b/docs/getting_started/ethereum.md @@ -121,12 +121,12 @@ Each iteration of the counter will build upon previous concepts while introducin Save this in your `.env` file: -| Contract/Service | Address/Value | -| ---------------------- | -------------------------------------------------- | -| TFHE_EXECUTOR_CONTRACT | 0x199fB61DFdfE46f9F90C9773769c28D9623Bb90e | -| ACL_CONTRACT | 0x9479B455904dCccCf8Bc4f7dF8e9A1105cBa2A8e | -| PAYMENT_CONTRACT | 0x25FE5d92Ae6f89AF37D177cF818bF27EDFe37F7c | -| KMS_VERIFIER_CONTRACT | 0x904Af2B61068f686838bD6257E385C2cE7a09195 | -| GATEWAY_CONTRACT | 0x7455c89669cdE1f7Cb6D026DFB87263422D821ca | -| PUBLIC_KEY_ID | 55729ddea48547ea837137d122e1c90043e94c41 | -| GATEWAY_URL | `https://gateway-sepolia.kms-dev-v1.bc.zama.team/` | +| Contract/Service | Address/Value | +| ---------------------- | ------------------------------------------ | +| TFHE_EXECUTOR_CONTRACT | 0x199fB61DFdfE46f9F90C9773769c28D9623Bb90e | +| ACL_CONTRACT | 0x9479B455904dCccCf8Bc4f7dF8e9A1105cBa2A8e | +| PAYMENT_CONTRACT | 0x25FE5d92Ae6f89AF37D177cF818bF27EDFe37F7c | +| KMS_VERIFIER_CONTRACT | 0x904Af2B61068f686838bD6257E385C2cE7a09195 | +| GATEWAY_CONTRACT | 0x7455c89669cdE1f7Cb6D026DFB87263422D821ca | +| PUBLIC_KEY_ID | 55729ddea48547ea837137d122e1c90043e94c41 | +| GATEWAY_URL | `https://gateway.sepolia.zama.ai/` | From 09a9c8fe4b59bde4328adedaea5b033696bf6058 Mon Sep 17 00:00:00 2001 From: jatZama Date: Tue, 10 Dec 2024 00:38:06 +0100 Subject: [PATCH 4/5] feat: fix Gateway library to be compatible with trustless decryption --- gateway/lib/Gateway.sol | 41 ++++++++++++++++++++++++++++++++++++++++- package-lock.json | 8 ++++---- package.json | 2 +- test/asyncDecrypt.ts | 12 ++++-------- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/gateway/lib/Gateway.sol b/gateway/lib/Gateway.sol index 8c56d4c7..746b0fa7 100644 --- a/gateway/lib/Gateway.sol +++ b/gateway/lib/Gateway.sol @@ -124,6 +124,7 @@ library Gateway { assembly { calldatacopy(add(decryptedResult, 0x20), start, length) // Copy the relevant part of calldata to decryptedResult memory } + decryptedResult = shiftOffsets(decryptedResult, handlesList); FHEVMConfigStruct storage $ = Impl.getFHEVMConfig(); return IKMSVerifier($.KMSVerifierAddress).verifyDecryptionEIP712KMSSignatures( @@ -154,7 +155,45 @@ library Gateway { revert("Unsupported handle type"); } } - signedDataLength += 32; // for the signatures offset + signedDataLength += 32; // add offset of signatures return signedDataLength; } + + function shiftOffsets(bytes memory input, uint256[] memory handlesList) private pure returns (bytes memory) { + uint256 numArgs = handlesList.length; + for (uint256 i = 0; i < numArgs; i++) { + uint8 typeCt = uint8(handlesList[i] >> 8); + if (typeCt >= 9) { + input = subToBytes32Slice(input, 32 * i); // because we append the signatures, all bytes offsets are shifted by 0x20 + } + } + input = remove32Slice(input, 32 * numArgs); + return input; + } + + function subToBytes32Slice(bytes memory data, uint256 offset) private pure returns (bytes memory) { + // @note: data is assumed to be more than 32+offset bytes long + assembly { + let ptr := add(add(data, 0x20), offset) + let val := mload(ptr) + val := sub(val, 0x20) + mstore(ptr, val) + } + return data; + } + + function remove32Slice(bytes memory input, uint256 start) public pure returns (bytes memory) { + // @note we assume start+32 is less than input.length + bytes memory result = new bytes(input.length - 32); + + for (uint256 i = 0; i < start; i++) { + result[i] = input[i]; + } + + for (uint256 i = start + 32; i < input.length; i++) { + result[i - 32] = input[i]; + } + + return result; + } } diff --git a/package-lock.json b/package-lock.json index aa94e9bb..e5d63be3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "eslint": "^8.28.0", "eslint-config-prettier": "^8.5.0", "ethers": "^6.8.0", - "fhevm-core-contracts": "0.6.0-5", + "fhevm-core-contracts": "0.6.1-0", "fhevmjs": "^0.6.0-8", "hardhat": "^2.22.10", "hardhat-deploy": "^0.11.29", @@ -6110,9 +6110,9 @@ } }, "node_modules/fhevm-core-contracts": { - "version": "0.6.0-5", - "resolved": "https://registry.npmjs.org/fhevm-core-contracts/-/fhevm-core-contracts-0.6.0-5.tgz", - "integrity": "sha512-o3ZInT2RA+uldzIMM2fHMjoIhI2466psLGI4tU4BJYOeV6wgJpw+T+m6/tN3WSf3nE0bU4yLrD1S/lM3Wk24vg==", + "version": "0.6.1-0", + "resolved": "https://registry.npmjs.org/fhevm-core-contracts/-/fhevm-core-contracts-0.6.1-0.tgz", + "integrity": "sha512-4UrR/SMdR/uNla7zkzd812ppcIovnJfDYIAY1FxM2E5ZSe2+4xXhVlQlcwyQ+ak2lDUhP29MixIORTJN+zZ4vA==", "dev": true }, "node_modules/fhevmjs": { diff --git a/package.json b/package.json index 46ef8b2c..f68baaef 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "eslint-config-prettier": "^8.5.0", "ethers": "^6.8.0", "fhevmjs": "^0.6.0-8", - "fhevm-core-contracts": "0.6.0-5", + "fhevm-core-contracts": "0.6.1-0", "hardhat": "^2.22.10", "hardhat-deploy": "^0.11.29", "hardhat-gas-reporter": "^1.0.2", diff --git a/test/asyncDecrypt.ts b/test/asyncDecrypt.ts index 65e66963..74fa92cf 100644 --- a/test/asyncDecrypt.ts +++ b/test/asyncDecrypt.ts @@ -122,7 +122,7 @@ const fulfillAllPastRequestsIds = async (mocked: boolean) => { const handles = event.args[1]; const typesList = handles.map((handle) => parseInt(handle.toString(16).slice(-4, -2), 16)); const msgValue = event.args[4]; - const passSignaturesToCaller = event.args[6]; + if (!results.includes(requestID)) { // if request is not already fulfilled if (mocked) { @@ -154,13 +154,9 @@ const fulfillAllPastRequestsIds = async (mocked: boolean) => { const abiCoder = new ethers.AbiCoder(); let encodedData; let calldata; - if (!passSignaturesToCaller) { - encodedData = abiCoder.encode(['uint256', ...types], [31, ...valuesFormatted4]); // 31 is just a dummy uint256 requestID to get correct abi encoding for the remaining arguments (i.e everything except the requestID) - calldata = '0x' + encodedData.slice(66); // we just pop the dummy requestID to get the correct value to pass for `decryptedCts` - } else { - encodedData = abiCoder.encode(['uint256', ...types, 'bytes[]'], [31, ...valuesFormatted4, []]); // adding also a dummy empty array of bytes for correct abi-encoding when used with signatures - calldata = '0x' + encodedData.slice(66).slice(0, -64); // we also pop the last 32 bytes (empty bytes[]) - } + + encodedData = abiCoder.encode(['uint256', ...types], [31, ...valuesFormatted4]); // 31 is just a dummy uint256 requestID to get correct abi encoding for the remaining arguments (i.e everything except the requestID) + calldata = '0x' + encodedData.slice(66); // we just pop the dummy requestID to get the correct value to pass for `decryptedCts` const numSigners = +process.env.NUM_KMS_SIGNERS!; const decryptResultsEIP712signatures = await computeDecryptSignatures(handles, calldata, numSigners); From b0c9133265bb295016cdca4ead01e370e8cf19d1 Mon Sep 17 00:00:00 2001 From: jatZama Date: Tue, 10 Dec 2024 00:38:28 +0100 Subject: [PATCH 5/5] 0.6.1-0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e5d63be3..2e25a2a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fhevm", - "version": "0.6.0", + "version": "0.6.1-0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "fhevm", - "version": "0.6.0", + "version": "0.6.1-0", "license": "BSD-3-Clause-Clear", "dependencies": { "@openzeppelin/contracts": "^5.0.1", diff --git a/package.json b/package.json index f68baaef..143984a4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fhevm", "description": "A Solidity library for interacting with the Zama Blockchain", - "version": "0.6.0", + "version": "0.6.1-0", "engines": { "node": ">=20.0.0" },