Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 8d8cd43

Browse files
authored
Merge pull request #645 from zama-ai/coreContracts061-0
Core contracts061 0
2 parents 77f3545 + b0c9133 commit 8d8cd43

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

gateway/lib/Gateway.sol

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ library Gateway {
124124
assembly {
125125
calldatacopy(add(decryptedResult, 0x20), start, length) // Copy the relevant part of calldata to decryptedResult memory
126126
}
127+
decryptedResult = shiftOffsets(decryptedResult, handlesList);
127128
FHEVMConfigStruct storage $ = Impl.getFHEVMConfig();
128129
return
129130
IKMSVerifier($.KMSVerifierAddress).verifyDecryptionEIP712KMSSignatures(
@@ -154,7 +155,45 @@ library Gateway {
154155
revert("Unsupported handle type");
155156
}
156157
}
157-
signedDataLength += 32; // for the signatures offset
158+
signedDataLength += 32; // add offset of signatures
158159
return signedDataLength;
159160
}
161+
162+
function shiftOffsets(bytes memory input, uint256[] memory handlesList) private pure returns (bytes memory) {
163+
uint256 numArgs = handlesList.length;
164+
for (uint256 i = 0; i < numArgs; i++) {
165+
uint8 typeCt = uint8(handlesList[i] >> 8);
166+
if (typeCt >= 9) {
167+
input = subToBytes32Slice(input, 32 * i); // because we append the signatures, all bytes offsets are shifted by 0x20
168+
}
169+
}
170+
input = remove32Slice(input, 32 * numArgs);
171+
return input;
172+
}
173+
174+
function subToBytes32Slice(bytes memory data, uint256 offset) private pure returns (bytes memory) {
175+
// @note: data is assumed to be more than 32+offset bytes long
176+
assembly {
177+
let ptr := add(add(data, 0x20), offset)
178+
let val := mload(ptr)
179+
val := sub(val, 0x20)
180+
mstore(ptr, val)
181+
}
182+
return data;
183+
}
184+
185+
function remove32Slice(bytes memory input, uint256 start) public pure returns (bytes memory) {
186+
// @note we assume start+32 is less than input.length
187+
bytes memory result = new bytes(input.length - 32);
188+
189+
for (uint256 i = 0; i < start; i++) {
190+
result[i] = input[i];
191+
}
192+
193+
for (uint256 i = start + 32; i < input.length; i++) {
194+
result[i - 32] = input[i];
195+
}
196+
197+
return result;
198+
}
160199
}

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fhevm",
33
"description": "A Solidity library for interacting with the Zama Blockchain",
4-
"version": "0.6.0",
4+
"version": "0.6.1-0",
55
"engines": {
66
"node": ">=20.0.0"
77
},
@@ -73,7 +73,7 @@
7373
"eslint-config-prettier": "^8.5.0",
7474
"ethers": "^6.8.0",
7575
"fhevmjs": "^0.6.0-8",
76-
"fhevm-core-contracts": "0.6.0-5",
76+
"fhevm-core-contracts": "0.6.1-0",
7777
"hardhat": "^2.22.10",
7878
"hardhat-deploy": "^0.11.29",
7979
"hardhat-gas-reporter": "^1.0.2",

test/asyncDecrypt.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const fulfillAllPastRequestsIds = async (mocked: boolean) => {
122122
const handles = event.args[1];
123123
const typesList = handles.map((handle) => parseInt(handle.toString(16).slice(-4, -2), 16));
124124
const msgValue = event.args[4];
125-
const passSignaturesToCaller = event.args[6];
125+
126126
if (!results.includes(requestID)) {
127127
// if request is not already fulfilled
128128
if (mocked) {
@@ -154,13 +154,9 @@ const fulfillAllPastRequestsIds = async (mocked: boolean) => {
154154
const abiCoder = new ethers.AbiCoder();
155155
let encodedData;
156156
let calldata;
157-
if (!passSignaturesToCaller) {
158-
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)
159-
calldata = '0x' + encodedData.slice(66); // we just pop the dummy requestID to get the correct value to pass for `decryptedCts`
160-
} else {
161-
encodedData = abiCoder.encode(['uint256', ...types, 'bytes[]'], [31, ...valuesFormatted4, []]); // adding also a dummy empty array of bytes for correct abi-encoding when used with signatures
162-
calldata = '0x' + encodedData.slice(66).slice(0, -64); // we also pop the last 32 bytes (empty bytes[])
163-
}
157+
158+
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)
159+
calldata = '0x' + encodedData.slice(66); // we just pop the dummy requestID to get the correct value to pass for `decryptedCts`
164160

165161
const numSigners = +process.env.NUM_KMS_SIGNERS!;
166162
const decryptResultsEIP712signatures = await computeDecryptSignatures(handles, calldata, numSigners);

0 commit comments

Comments
 (0)