Skip to content

Commit

Permalink
Merge branch 'main' of github.com:zama-ai/fhevm into docs-fhevm06
Browse files Browse the repository at this point in the history
  • Loading branch information
poppyseedDev committed Dec 10, 2024
2 parents af6f634 + 8d8cd43 commit e724e02
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<hr/>

<p align="center">
<a href="./fhevm-whitepaper.pdf"> 📃 Read white paper</a> |<a href="https://docs.zama.ai/fhevm"> 📒 Documentation</a> | <a href="https://zama.ai/community"> 💛 Community support</a> | <a href="https://github.com/zama-ai/awesome-zama"> 📚 FHE resources by Zama</a>
<a href="fhevm-whitepaper-v2.pdf"> 📃 Read white paper</a> |<a href="https://docs.zama.ai/fhevm"> 📒 Documentation</a> | <a href="https://zama.ai/community"> 💛 Community support</a> | <a href="https://github.com/zama-ai/awesome-zama"> 📚 FHE resources by Zama</a>
</p>

<p align="center">
Expand Down Expand Up @@ -136,7 +136,7 @@ _More examples are available [here](https://docs.zama.ai/fhevm/tutorials/see-all
<a href="#about" > ↑ Back to top </a>
</p>

> [!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.
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><strong>Fundamentals</strong></td><td>Explore core features.</td><td><ul><li><a href="getting_started/write_contract/hardhat.md">Write contract with Hardhat</a></li><li><a href="fundamentals/types.md">Use encrypted types</a></li></ul></td><td><a href=".gitbook/assets/build1.png">build1.png</a></td></tr><tr><td><strong>Guides</strong></td><td>Learn further.</td><td><ul><li><a href="guides/smart-contracts/">Smart Contracts</a></li><li><a href="guides/frontend/">Frontend</a></li></ul></td><td><a href=".gitbook/assets/build2.png">build2.png</a></td></tr><tr><td><strong>Tutorials</strong></td><td>Learn more with tutorials.</td><td><ul><li><a href="tutorials/see-all-tutorials.md">See all tutorials</a></li><li><a href="tutorials/see-all-tutorials.md#start-here">Start here</a></li><li><a href="tutorials/see-all-tutorials.md#go-further">Go further</a></li></ul></td><td><a href=".gitbook/assets/build3.png">build3.png</a></td></tr></tbody></table>
<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><strong>Fundamentals</strong></td><td>Explore core features.</td><td><ul><li><a href="getting_started/write_contract/hardhat.md">Write contract with Hardhat</a></li><li><a href="fundamentals/types.md">Use encrypted types</a></li></ul></td><td><a href=".gitbook/assets/build1.png">build1.png</a></td></tr><tr><td><strong>Guides</strong></td><td>Learn more about fhEVM implementation.</td><td><ul><li><a href="guides/smart-contracts/">Smart contracts</a></li><li><a href="guides/frontend/">Frontend</a></li></ul></td><td><a href=".gitbook/assets/build2.png">build2.png</a></td></tr><tr><td><strong>Tutorials</strong></td><td>Build quickly with tutorials.</td><td><ul><li><a href="tutorials/see-all-tutorials.md">See all tutorials</a></li></ul></td><td><a href=".gitbook/assets/build3.png">build3.png</a></td></tr></tbody></table>

## Explore more

Expand Down
18 changes: 9 additions & 9 deletions docs/getting_started/ethereum.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/` |
41 changes: 40 additions & 1 deletion gateway/lib/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 4 additions & 8 deletions test/asyncDecrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e724e02

Please sign in to comment.