Skip to content

Commit

Permalink
Merge pull request #80 from zama-ai/fix/64bits
Browse files Browse the repository at this point in the history
fix: add FheType for Euint64 for kms
  • Loading branch information
immortal-tofu authored Feb 8, 2024
2 parents b7d5a66 + 5b8f2dd commit df24c08
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 37 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@

**fhEVM-go** is an open-source library used to easily integrate the [fhEVM](https://docs.zama.ai/fhevm) into an EVM-compatible blockchain.


## Main features

fhEVM-go gives your EVM the ability to compute on encrypted data using fully homomorphic encryption by:

- a collection of operations on encrypted data via precompiled contracts
- various additional EVM components that support encrypted computation


## Getting started

In order to use the library, you need to clone the repository and build it. This is required because the library depends on the `tfhe-rs` library that needs to be built from source (for now), and Go doesn't support such a build.

```bash
$ git clone https://github.com/zama-ai/fhevm-go
$ cd fhevm-go
$ make build
```

That's it! You can now use it in your project by adding it to `go.mod`, and adding a `replace` to point to your local build. An example using `fhevm-go` v1.0.0:

```
...
require(
Expand All @@ -57,6 +58,11 @@ replace(
> [!NOTE]
> The replace in necessary for now as Go build system can't build the `tfhe-rs` library that `fhevm-go` needs. It's therefore necessary that we build it manually as mentioned above, then point to our ready-to-use directory in `go.mod`.
## Regenerate protobuff files

To re-generate these files, install `protoc`, `protoc-gen-go` and `protoc-gen-go-grpc` and run protoc
`cd proto && protoc --go_out=../kms --go_opt=paths=source_relative --go-grpc_out=../kms --go-grpc_opt=paths=source_relative kms.proto && cd ..`.

## Documentation

Full, comprehensive documentation is available at [https://docs.zama.ai/fhevm-go](https://docs.zama.ai/fhevm-go).
Expand Down
4 changes: 4 additions & 0 deletions fhevm/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,8 @@ func reencryptRun(environment EVMEnvironment, caller common.Address, addr common
fheType = kms.FheType_Euint16
case FheUint32:
fheType = kms.FheType_Euint32
case FheUint64:
fheType = kms.FheType_Euint64
}

pubKey := input[32:64]
Expand Down Expand Up @@ -2230,6 +2232,8 @@ func decryptValue(environment EVMEnvironment, ct *tfheCiphertext) (uint64, error
fheType = kms.FheType_Euint16
case FheUint32:
fheType = kms.FheType_Euint32
case FheUint64:
fheType = kms.FheType_Euint64
}

// TODO: generate merkle proof for some data
Expand Down
6 changes: 6 additions & 0 deletions kms/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package kms

import "os"

// URL of the KMS gRPC endpoint
var KmsEndpointAddr = os.Getenv("KMS_ENDPOINT_ADDR")
60 changes: 32 additions & 28 deletions kms/kms.pb.go

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

7 changes: 1 addition & 6 deletions kms/kms_grpc.pb.go

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

3 changes: 2 additions & 1 deletion proto/kms.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum FheType {
Euint8 = 1;
Euint16 = 2;
Euint32 = 3;
Euint64 = 4;
}

message Proof {
Expand All @@ -32,7 +33,7 @@ message DecryptionRequest {
message DecryptionResponse {
bytes signature = 1;
FheType fhe_type = 2;
uint32 plaintext = 3;
uint64 plaintext = 3;
}

message ReencryptionRequest {
Expand Down

0 comments on commit df24c08

Please sign in to comment.