diff --git a/README.md b/README.md
index cc2e8d3f..3b251665 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
@@ -136,7 +136,7 @@ _More examples are available [here](https://docs.zama.ai/fhevm/tutorials/see-all
↑ 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.
-
+
## Explore more
diff --git a/docs/getting_started/ethereum.md b/docs/getting_started/ethereum.md
index c136b227..2b7661f4 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/` |
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 22d0cea2..f49e61f8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "fhevm",
- "version": "0.6.0-8",
+ "version": "0.6.1-0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "fhevm",
- "version": "0.6.0-8",
+ "version": "0.6.1-0",
"license": "BSD-3-Clause-Clear",
"dependencies": {
"@openzeppelin/contracts": "^5.0.1",
@@ -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 03b99d6d..6a2cf31f 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.1-0",
"engines": {
"node": ">=20.0.0"
},
@@ -72,8 +72,8 @@
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^6.8.0",
- "fhevm-core-contracts": "0.6.0-5",
"fhevmjs": "^0.6.0-8",
+ "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);