Skip to content

Commit

Permalink
Update earlyWin.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoshiya authored Jun 1, 2024
1 parent 3aba231 commit f6905fb
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions docs/tutorial/earlyWin.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,42 @@ displayed_sidebar: tutorialSidebar

# Overview

In this guide, we'll be creating a shielded ERC20 token using Solidity. Our token will be unique in that it will offer encrypted token balances, thereby enhancing privacy for token holders.
In this short guide well encrypt plaintext to ciphertext using FHE, demonstrating how simple it is to enable confidentiality in your smart contracts with Fhenix.

1. Define a view function in your contract. For example, to retrieve sensitive data:

```solidity
function getSensitiveData(Permission calldata perm) public view onlySender(perm) returns (string memory) {
// Logic to return sensitive data
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@fhenixprotocol/contracts/FHE.sol";
contract EarlyWin {
uint8 _plaintext;
euint8 public _cipherText;
function setCipherText(inEuint8 calldata _encryptedNumber) public {
// convert inEuint8 type structure to euint8
_cipherText = FHE.asEuint8(_encryptedNumber);
}
function setPlainText(uint8 _number) public {
//set standard plaintext
_plaintext = _number;
}
function decrypt() public view returns (uint8) {
return FHE.decrypt(_cipherText);
}
}
```
# Overview
First, FHE is imported directly into your contract with a single line of code. Next we establish two numbers or unsigned integers, withhowever the _cipherText number beingwill be encrypted. This means that it will not be publicly accessible from anyone other than the intended viewer. The standard _plaintext unit8 represents a number that is public for all to view. On line 11 we have a setter function that allows us to pass in a new encrypted number that will stay private. On line 21 we have a decrypt function that allows us to view the number that was written to state in the setCipherText function. As you can see there is no requirement for off-chain proof generation or storage.

0 comments on commit f6905fb

Please sign in to comment.