Skip to content
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

Added documentation for pitfalls and best practises #276

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

jatZama
Copy link
Member

@jatZama jatZama commented Feb 1, 2024

No description provided.

@jatZama jatZama requested a review from immortal-tofu February 1, 2024 16:06
@cla-bot cla-bot bot added the cla-signed label Feb 1, 2024
docs/howto/pitfalls.md Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
docs/howto/pitfalls.md Outdated Show resolved Hide resolved
@jatZama jatZama requested a review from immortal-tofu February 1, 2024 19:20
docs/getting_started/workflow.md Outdated Show resolved Hide resolved
docs/SUMMARY.md Outdated Show resolved Hide resolved
@jatZama jatZama force-pushed the docs/add_common_pitfalls_best_practices branch from 6a50c19 to a269f53 Compare February 1, 2024 23:17
@jatZama jatZama requested a review from immortal-tofu February 1, 2024 23:17

2/ A good first step is to start with an unencrypted version of the contract you want to implement, as you would usually do on a regular EVM chain. It is easier to reason first on cleartext variables, before thinking on how to add confidentialy. You could test your contracts on a regular hardhat node via : `npx hardhat test --network hardhat`.

3/ Then launch an fhEVM local node with `pnpm fhevm:start` and start to add confidentiality by using the `TFHE` solidity library. Typically, this would involve converting some `uintX` types to `euintX`, as well as following all the detailed advices that we gave in the [pitfalls to avoid and best practises](../howto/pitfalls.md) section of the documentation. For inspiration, you can look at the examples inside the [`fhevm` repository](https://github.com/zama-ai/fhevm/tree/main/examples). Before using the hardhat template, please alse read the advices that we gave in the [hardhat section](./write_contract/hardhat.md).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you're ready, you can start to add confidentiality by using the `TFHE` solidity library. Typically, this would involve converting some `uintX` types to `euintX`, as well as following all the detailed advices that we gave in the [pitfalls to avoid and best practises](../howto/pitfalls.md) section of the documentation. For inspiration, you can take a look at the examples inside the [`fhevm` repository](https://github.com/zama-ai/fhevm/tree/main/examples). If you're using the Hardhat template, read the advices that we gave in the [Hardhat section](./write_contract/hardhat.md).


We present here a quick sketch of a typical workflow for writing confidential smart contracts on the fhEVM.

1/ For quick prototyping of a specific feature, use the [Zama version of the Remix IDE](./write_contract/remix.md). This will let you quickly deploy a contract on the devnet via Metamask, and interact easily with it throug the Remix UI. Otherwise, for a bigger project, you should start by cloning our custom [`fhevm-hardhat-template` repository](https://github.com/zama-ai/fhevm-hardhat-template). Hardhat is a popular development environment for Solidity developers and will let you test and deploy your contracts to the fhEVM using Javascript or Typescript code.
Copy link
Collaborator

@immortal-tofu immortal-tofu Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For quick prototyping of a specific feature, use the [Zama version of the Remix IDE](./write_contract/remix.md). This will let you quickly deploy a contract on the devnet via Metamask, and interact easily with it through the Remix UI.
Otherwise, for a bigger project, you should use our custom [`fhevm-hardhat-template` repository](https://github.com/zama-ai/fhevm-hardhat-template). Hardhat is a popular development environment for Solidity developers and will let you test and deploy your contracts to the fhEVM using TypeScript.


## Typical workflow for writing confidential smart contracts

We present here a quick sketch of a typical workflow for writing confidential smart contracts on the fhEVM.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this sentence ?


1/ For quick prototyping of a specific feature, use the [Zama version of the Remix IDE](./write_contract/remix.md). This will let you quickly deploy a contract on the devnet via Metamask, and interact easily with it throug the Remix UI. Otherwise, for a bigger project, you should start by cloning our custom [`fhevm-hardhat-template` repository](https://github.com/zama-ai/fhevm-hardhat-template). Hardhat is a popular development environment for Solidity developers and will let you test and deploy your contracts to the fhEVM using Javascript or Typescript code.

2/ A good first step is to start with an unencrypted version of the contract you want to implement, as you would usually do on a regular EVM chain. It is easier to reason first on cleartext variables, before thinking on how to add confidentialy. You could test your contracts on a regular hardhat node via : `npx hardhat test --network hardhat`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good first step is to start with an unencrypted version of the contract you want to implement, as you would usually do on a regular EVM chain. It is easier to reason first on cleartext variables, before thinking on how to add confidentialy.

@@ -4,6 +4,10 @@ The best way to start writing smart contracts with fhEVM is to use our [Hardhat

It allows you to start a fhEVM docker image and run your smart contract on it. Read the [README](https://github.com/zama-ai/fhevm-hardhat-template/blob/main/README.md) for more information.

When developing confidential contracts, we recommend to use first the mocked version of fhEVM for faster testing with `pnpm test:mock` and coverage computation via `pnpm coverage:mock`, this will lead to a better developer experience. But please keep in mind that the mocked fhEVM has some limitations and discrepencies compared to the real fhEVM node, as explained in the warning section at the end of this section.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But please keep in mind => However, keep in mind

@@ -4,6 +4,10 @@ The best way to start writing smart contracts with fhEVM is to use our [Hardhat

It allows you to start a fhEVM docker image and run your smart contract on it. Read the [README](https://github.com/zama-ai/fhevm-hardhat-template/blob/main/README.md) for more information.

When developing confidential contracts, we recommend to use first the mocked version of fhEVM for faster testing with `pnpm test:mock` and coverage computation via `pnpm coverage:mock`, this will lead to a better developer experience. But please keep in mind that the mocked fhEVM has some limitations and discrepencies compared to the real fhEVM node, as explained in the warning section at the end of this section.

Finally, always remember to test the final version of your contract on the real fhEVM with `pnpm test` before deployment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's essential to run tests of the final contract version using the real fhEVM. You can do this by running `pnpm test` before deployment.

@immortal-tofu
Copy link
Collaborator

Once merged in main, you need to open a pull request for release/0.3.x to make the changes happen in the current documentation.

@jatZama jatZama force-pushed the docs/add_common_pitfalls_best_practices branch from a269f53 to 9308436 Compare February 2, 2024 09:18
@jatZama jatZama force-pushed the docs/add_common_pitfalls_best_practices branch from 9308436 to ba35fe1 Compare February 2, 2024 09:22
@jatZama jatZama merged commit 1c22c66 into main Feb 2, 2024
5 checks passed
@jatZama jatZama deleted the docs/add_common_pitfalls_best_practices branch February 2, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants