Skip to content

Commit

Permalink
build(local): improve local build process and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
leventdem committed Sep 14, 2023
1 parent 7f33437 commit 0624fbd
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 33 deletions.
10 changes: 4 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# TFHE_RS_VERSION=0.2.1
# TFHE_RS_VERSION=0.3.1
# TFHE_RS_PATH=../tfhe-rs
# ZBC_DEVELOPMENT_PATH=../zbc-development
# ZBC_SOLIDITY_PATH=../zbc-solidity
# ZBC_FHE_TOOL_PATH=../zbc-fhe-tool
#LOCAL_BUILD=false
# FHEVM_SOLIDITY_PATH=../fhevm-solidity
# FHEVM_TFHE_CLI_PATH=../fhevm-tfhe-cli
# LOCAL_BUILD=false
LOCAL_BUILD=true
GOPRIVATE=github.com/zama-ai/*
28 changes: 13 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,37 +159,35 @@ print-info:
@bash scripts/get_repository_info.sh fhevm-tfhe-cli $(FHEVM_TFHE_CLI_PATH)
@bash scripts/get_repository_info.sh fhevm-solidity $(FHEVM_SOLIDITY_PATH)

copy_c_api_to_system_path:
# In tfhe.go the library path is specified as following : #cgo LDFLAGS: -L/usr/lib/ -ltfhe
$(SUDO) cp $(TFHE_RS_PATH)/target/release/tfhe.h /usr/include/
$(SUDO) cp $(TFHE_RS_PATH)/target/release/libtfhe.* /usr/lib/


build_c_api_tfhe:
build_c_api_tfhe: check-tfhe-rs
$(info build tfhe-rs C API)
mkdir -p $(WORKDIR)/
$(info tfhe-rs path $(TFHE_RS_PATH))
$(info sudo_bin $(SUDO_BIN))
cd $(TFHE_RS_PATH) && RUSTFLAGS="" make build_c_api_experimental_deterministic_fft
ls $(TFHE_RS_PATH)/target/release
# In tfhe.go the library path is specified as following : #cgo LDFLAGS: -L/usr/lib/tfhe -ltfhe
$(SUDO) cp $(TFHE_RS_PATH)/target/release/tfhe.h /usr/include/
$(SUDO) cp $(TFHE_RS_PATH)/target/release/libtfhe.* /usr/lib/

build:
BUILD_ARGS=-o $(BUILDDIR)
$(info build)


build-linux:
$(info build-linux)
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build

build-local: check-tfhe-rs go.sum build_c_api_tfhe $(BUILDDIR)/
$(info build-local)
$(BUILD_TARGETS): go.sum $(BUILDDIR)/
$(info build)
go install $(BUILD_FLAGS) $(BUILD_ARGS) ./...
@echo 'evmosd binary is ready in $(HOME)/go/bin'

build-local: go.sum build_c_api_tfhe copy_c_api_to_system_path $(BUILDDIR)/
$(info build-local for docker build)
go build $(BUILD_FLAGS) -o build $(BUILD_ARGS) ./...
@echo 'evmosd binary is ready in build folder'


# $(BUILD_TARGETS): go.sum $(BUILDDIR)/
$(BUILD_TARGETS): go.sum build_c_api_tfhe $(BUILDDIR)/
$(info BUILD_TARGETS)
go $@ $(BUILD_FLAGS) -o build $(BUILD_ARGS) ./...

check-tfhe-rs: $(WORKDIR)/
$(info check-tfhe-rs)
Expand Down
89 changes: 86 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,97 @@ The quick start is to follow this [section](#from-github-package-registry)

# Local build

## Prepare tfhe-rs C API

### Build

To build automatically the C library one can use the following commands:

```bash
make build_c_api_tfhe
```

This will clone **tfhe-rs** repository in work_dir folder and build the C api in __work_dir/tfhe-rs/target/release__.

If the developer hash its own **tfhe-rs** repository the TFHE_RS_PATH env variable could be set in .env file.

### Copy tfhe header file and C library

**Go-ethereum** needs the tfhe.h header file located in __go-ethereum/core/vm__ and the libtfhe.so (linux) or libtfhe.dylib for (Mac) in __go-ethereum/core/vm/lib__.


## Use custom go-ethereum and ethermint repositories

To use custom **go-ethereum** and **ethermint** repositories, please update the go.mod file accordingly:

```bash
-replace github.com/ethereum/go-ethereum v1.10.19 => github.com/zama-ai/go-ethereum v0.1.10
+replace github.com/ethereum/go-ethereum v1.10.19 => ../go-ethereum

-replace github.com/evmos/ethermint v0.19.3 => github.com/zama-ai/ethermint v0.1.2
+replace github.com/evmos/ethermint v0.19.3 => ../ethermint
```

To build evmosd binary directly in your system.

```bash
export GOPRIVATE=github.com/zama-ai/*
make build-local
make build
```

The binary is installed in your system go binary path (e.g. $HOME/go/bin)

IMPORTANT NOTES:

<details>
<summary>Check if evmosd is linked with the right tfhe-rs C libray - Linux</summary>
<br />

```bash
ldd $HOME/go/bin/evmosd
linux-vdso.so.1 (0x00007ffdb6d73000)
libtfhe.so => /PATH_TO/tfhe-rs/target/release/libtfhe.so (0x00007fa87c3a7000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa87c185000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa87c165000)
libm.so.6 => /lib64/libm.so.6 (0x00007fa87c087000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa87c9e5000)
```

The binary is built in build folder.
If the user get:
```bash
evmosd: error while loading shared libraries: libtfhe.so: cannot open shared object file: No such file or directory
```
For linux one solution is to update the LD_LIBRARY_PATH to the libtfhe.so compiled in tfhe-rs
</details>
<details>
<summary>Generate FHE keys</summary>
<br />
```bash
./scripts/prepare_volumes_from_fhe_tool_docker.sh v0.2.0
```
Copy them to evmos HOME folder in __.evmosd/zama/keys/network-fhe-keys__
</details>
<details>
<summary>Run a node</summary>
<br />
```bash
./setup.sh
./start.sh
```
If you want to reset the state:
```bash
rm -r $HOME/.evmosd/config
rm -r $HOME/.evmosd/keyring-test/
rm -r $HOME/.evmosd/data/
```
</details>
<br />
Dependencies:
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.evmos-node.local
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN cp go.mod.updated /src/evmos/go.mod

RUN tail /src/evmos/go.mod

RUN make build
RUN make build-local
RUN ls /src/evmos
RUN ls /src/evmos/build
RUN mkdir -p /src/evmos/build
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.evmos-node.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN cp /src/tfhe-rs/target/release/libtfhe.* /src/go-ethereum/core/vm/lib/
# RUN cp /src/tfhe-rs/target/release/libtfhe.* /usr/lib/


RUN make build
RUN make build-local

ARG ZBC_BUILD_IMAGE_TAG
FROM ghcr.io/zama-ai/zama-zbc-build:$ZBC_BUILD_IMAGE_TAG
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,6 @@ replace (
replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0

// TODO: Remove once our forks are public.
replace github.com/ethereum/go-ethereum v1.10.19 => github.com/zama-ai/go-ethereum v0.1.10
replace github.com/ethereum/go-ethereum v1.10.19 => ../go-ethereum

replace github.com/evmos/ethermint v0.19.3 => github.com/zama-ai/ethermint v0.1.2
replace github.com/evmos/ethermint v0.19.3 => ../ethermint
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,6 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zama-ai/ethermint v1.0.0-test h1:x00Rxncw8qhzvV75S9lPbcmYBumGZ8ZZ8lGWgDawjHY=
github.com/zama-ai/ethermint v1.0.0-test/go.mod h1:JEqkvu6ZC6GV0nq7txpzmaRQdfDzwFay1SRumKsEkg8=
github.com/zama-ai/go-ethereum v1.0.1-test h1:WpTU7WP2W9fyZZYD+n0t26S1Njk6lzb3szKVgvVZ/SE=
github.com/zama-ai/go-ethereum v1.0.1-test/go.mod h1:IJBNMtzKcNHPtllYihy6BL2IgK1u+32JriaTbdt4v+w=
github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8=
github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare_demo_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -Eeuo pipefail

VOLUME_NETWORK_PUBLIC_KEYS_PATH=./volumes/network-public-fhe-keys
VOLUME_NETWORK_PRIVATE_KEYS_PATH=./volumes/network-private-fhe-keys
EVMOS_NETWORK_KEYS_PATH=./running_node/node1/.evmosd/zama/keys/network-fhe-keys
EVMOS_NETWORK_KEYS_PATH=$HOME/.evmosd/zama/keys/network-fhe-keys

mkdir -p $EVMOS_NETWORK_KEYS_PATH

Expand Down

0 comments on commit 0624fbd

Please sign in to comment.