-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: a precompile to get ciphertext bytes
Given a contract address and an ebool/euint value stored in it, return the underlying ciphertext. Returns an empty response if no such ciphertext exist. Only works via `eth_call`. The function selector for it, as of this commit, is `e4b808cb`. Move protected storage code into its own file. Add a `FheLib Library` section in the getting started doc section. Nit: rename `arg_types` to `argTypes` in instructions.go for naming consistency.
- Loading branch information
1 parent
965afb6
commit 26427fd
Showing
9 changed files
with
597 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# FheLib | ||
|
||
`FheLib` is a library implemented inside fhevm-go. It offers FHE-related functionalities such as homomorphic operations, decryption/reencryption requests and so on. FheLib is exposed as a single `precompiled` contract (or a `precompile` for short) that is integrated into the underlying blockchain. | ||
|
||
FheLib functions can be called by calling the FheLib precompile with a respective EVM function selector. | ||
|
||
This page describes the required inputs, behaviours and outputs of some of these functions. | ||
|
||
## GetCiphertext Function (selector: e4b808cb) | ||
|
||
The `GetCiphertext` function returns a serialized TFHE ciphertext from protected storage given: | ||
* contract address where the ciphertext is stored at | ||
* the ebool/e(u)int value (also called a handle) for which the ciphertext is requested | ||
|
||
GetCiphertext only works via the `eth_call` RPC. | ||
|
||
To call GetCiphertext via `eth_call`, the following Python can serve as an example: | ||
|
||
```python | ||
import http.client | ||
import json | ||
|
||
# This is the address of the FheLib precompile. This value is hardcoded per blockchain. | ||
fhe_lib_precompile_address = "0x000000000000000000000000000000000000005d" | ||
|
||
# The contract address where the ciphertext is stored at. | ||
contract_address = "ACD7Be4EBF68Bf2A5b6eB0CaFb15460C169BC459" | ||
# 12 bytes of 0s for padding the contract address. | ||
address_zero_padding = "000000000000000000000000" | ||
|
||
# The ebool/e(u)int value for which the ciphertext is requested. | ||
handle = "f038cdc8bf630e239f143abeb039b91ec82ec17a8460582e7a409fa551030c06" | ||
|
||
# The function selector of GetCiphertext. | ||
get_ciphertext_selector = "e4b808cb" | ||
|
||
# Call the FheLib precompile with `data` being the concatenation of: | ||
# - getCiphertext function selector; | ||
# - 12 bytes of 0s to padd the contract address; | ||
# - contract address; | ||
# - the handle to the ciphertext. | ||
payload = { | ||
"jsonrpc": "2.0", | ||
"method": "eth_call", | ||
"params": [ | ||
{ | ||
"to": fhe_lib_precompile_address, | ||
"data": "0x" + get_ciphertext_selector + address_zero_padding + | ||
contract_address + handle | ||
}, | ||
"latest" | ||
], | ||
"id": 1, | ||
} | ||
|
||
con = http.client.HTTPConnection("localhost", 8545) | ||
con.request("POST", "/", body=json.dumps(payload), | ||
headers={"Content-Type": "application/json"}) | ||
resp = json.loads(con.getresponse().read()) | ||
|
||
# Remove leading "0x" and decode hex to get a byte buffer with the ciphertext. | ||
ciphertext = bytes.fromhex(resp["result"][2:]) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.