Skip to content

Commit

Permalink
change VRF implementation to libsodium
Browse files Browse the repository at this point in the history
  • Loading branch information
torao committed Aug 4, 2021
1 parent a727fe1 commit eed25ef
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 99 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Create a file with all the pkgs
run: go list ./... > pkgs.txt
- name: Split pkgs into 4 files
Expand Down Expand Up @@ -43,6 +45,8 @@ jobs:
with:
go-version: "^1.15.4"
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Checkout submodules
uses: textbook/git-checkout-submodule-action@master
- name: Prepare
id: prep
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
with:
go-version: '^1.15.4'
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
Expand Down
154 changes: 81 additions & 73 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
with:
go-version: "^1.15.4"
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
Expand All @@ -50,76 +52,82 @@ jobs:
key: ${{ runner.os }}-${{ github.sha }}-tm-binary
if: env.GIT_DIFF

# test_abci_apps:
# runs-on: ubuntu-latest
# needs: build
# timeout-minutes: 5
# steps:
# - uses: actions/setup-go@v2
# with:
# go-version: "^1.15.4"
# - uses: actions/checkout@v2
# - uses: technote-space/get-diff-action@v4
# with:
# PATTERNS: |
# **/**.go
# go.mod
# go.sum
# - uses: actions/cache@v1
# with:
# path: ~/go/bin
# key: ${{ runner.os }}-${{ github.sha }}-tm-binary
# if: env.GIT_DIFF
# - name: test_abci_apps
# run: abci/tests/test_app/test.sh
# shell: bash
# if: env.GIT_DIFF
#
# test_abci_cli:
# runs-on: ubuntu-latest
# needs: build
# timeout-minutes: 5
# steps:
# - uses: actions/setup-go@v2
# with:
# go-version: "^1.15.4"
# - uses: actions/checkout@v2
# - uses: technote-space/get-diff-action@v4
# with:
# PATTERNS: |
# **/**.go
# go.mod
# go.sum
# - uses: actions/cache@v1
# with:
# path: ~/go/bin
# key: ${{ runner.os }}-${{ github.sha }}-tm-binary
# if: env.GIT_DIFF
# - run: abci/tests/test_cli/test.sh
# shell: bash
# if: env.GIT_DIFF
#
# test_apps:
# runs-on: ubuntu-latest
# needs: build
# timeout-minutes: 5
# steps:
# - uses: actions/setup-go@v2
# with:
# go-version: "^1.15.4"
# - uses: actions/checkout@v2
# - uses: technote-space/get-diff-action@v4
# with:
# PATTERNS: |
# **/**.go
# go.mod
# go.sum
# - uses: actions/cache@v1
# with:
# path: ~/go/bin
# key: ${{ runner.os }}-${{ github.sha }}-tm-binary
# if: env.GIT_DIFF
# - name: test_apps
# run: test/app/test.sh
# shell: bash
# if: env.GIT_DIFF
test_abci_apps:
runs-on: ubuntu-latest
needs: build
timeout-minutes: 5
steps:
- uses: actions/setup-go@v2
with:
go-version: "^1.15.4"
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/cache@v1
with:
path: ~/go/bin
key: ${{ runner.os }}-${{ github.sha }}-tm-binary
if: env.GIT_DIFF
- name: test_abci_apps
run: abci/tests/test_app/test.sh
shell: bash
if: env.GIT_DIFF

test_abci_cli:
runs-on: ubuntu-latest
needs: build
timeout-minutes: 5
steps:
- uses: actions/setup-go@v2
with:
go-version: "^1.15.4"
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/cache@v1
with:
path: ~/go/bin
key: ${{ runner.os }}-${{ github.sha }}-tm-binary
if: env.GIT_DIFF
- run: abci/tests/test_cli/test.sh
shell: bash
if: env.GIT_DIFF

test_apps:
runs-on: ubuntu-latest
needs: build
timeout-minutes: 5
steps:
- uses: actions/setup-go@v2
with:
go-version: "^1.15.4"
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/cache@v1
with:
path: ~/go/bin
key: ${{ runner.os }}-${{ github.sha }}-tm-binary
if: env.GIT_DIFF
- name: test_apps
run: test/app/test.sh
shell: bash
if: env.GIT_DIFF
6 changes: 3 additions & 3 deletions DOCKER/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
FROM golang:1.15-alpine as builder
RUN apk update && \
apk upgrade && \
apk add --no-cache git make gcc libc-dev build-base curl jq bash file gmp-dev clang
COPY / /ostracon
apk add --no-cache git make gcc libc-dev build-base curl jq bash file gmp-dev clang libtool autoconf automake
COPY . /ostracon/
WORKDIR /ostracon
RUN make build-linux

Expand All @@ -25,7 +25,7 @@ ENV TMHOME /ostracon
# could execute bash commands.
RUN apk update && \
apk upgrade && \
apk add --no-cache git make gcc libc-dev build-base curl jq bash file gmp-dev clang && \
apk add --no-cache git make gcc libc-dev build-base curl jq bash file gmp-dev clang libtool autoconf automake && \
addgroup ostracon && \
adduser -S -G ostracon ostracon -h "$TMHOME"

Expand Down
46 changes: 27 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ SRCPATH=$(shell pwd)
OUTPUT?=build/ostracon

INCLUDE = -I=${GOPATH}/src/github.com/line/ostracon -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
BUILD_TAGS?='ostracon'
BUILD_TAGS ?= ostracon
VERSION := $(shell git describe --always)
CGO_OPTPTION=0
LIBSODIUM_TARGET=
PREPARE_LIBSODIUM_TARGET=
LIBSODIUM=1
ifeq ($(LIBSODIUM), 1)
BUILD_TAGS='libsodium ostracon'
LIBSODIUM_TARGET=libsodium
ifneq ($(OS), Windows_NT)
ifeq ($(shell uname -s), Linux)
PREPARE_LIBSODIUM_TARGET=prepare-libsodium-linux
BUILD_TAGS += libsodium
LIBSODIUM_TARGET = libsodium
else
LIBSODIUM_TARGET =
endif
endif
endif
LIBSODIM_BUILD_TAGS='libsodium ostracon'
LD_FLAGS = -X github.com/line/ostracon/version.Version=$(VERSION)
BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
HTTPS_GIT := https://github.com/line/ostracon.git
Expand Down Expand Up @@ -72,7 +66,7 @@ build: $(LIBSODIUM_TARGET)
CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" -o $(OUTPUT) ./cmd/ostracon/
.PHONY: build

install:
install: $(LIBSODIUM_TARGET)
CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" ./cmd/ostracon
.PHONY: install

Expand Down Expand Up @@ -151,15 +145,28 @@ install_abci:
########################################
### libsodium

ifeq ($(shell uname -s), Darwin)
prepare-libsodium-linux:
brew install libtool autoconf automake
else
ifeq ($(shall uname -s), Linux)
prepare-libsodium-linux:
apt-get update && apt-get -y install libtool libboost-all-dev autoconf build-essential
else
prepare-libsodium-linux:
@echo "$(error This platform isn't supported. Please build libsodium manually.)"
endif
endif

libsodium:
cd $(SRCPATH)/crypto/vrf/internal/vrf/libsodium && \
./autogen.sh && \
./configure --disable-shared --prefix="$(SRCPATH)/crypto/vrf/internal/vrf/" && \
$(MAKE) && \
$(MAKE) install
@if [ ! -f $(SRCPATH)/crypto/vrf/internal/vrf/lib/libsodium.a ]; then \
cd $(SRCPATH)/crypto/vrf/internal/vrf/libsodium && \
./autogen.sh && \
./configure --disable-shared --prefix="$(SRCPATH)/crypto/vrf/internal/vrf/" && \
$(MAKE) && \
$(MAKE) install; \
fi
.PHONY: libsodium

########################################
### Distribution
Expand Down Expand Up @@ -287,8 +294,9 @@ DOCKER_CMD = docker run --rm \
-v `pwd`:$(DOCKER_HOME) \
-w $(DOCKER_HOME)
DOCKER_IMG = golang:1.15-alpine
BUILD_CMD = apk add --update --no-cache git make gcc libc-dev build-base curl jq file gmp-dev clang \
BUILD_CMD = apk add --update --no-cache git make gcc libc-dev build-base curl jq file gmp-dev clang libtool autoconf automake \
&& cd $(DOCKER_HOME) \
&& make libsodium \
&& make build-linux

# Login docker-container for confirmation building linux binary
Expand Down
2 changes: 1 addition & 1 deletion crypto/vrf/vrf_libsodium.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {
}

func (base vrfImplLibsodium) Prove(privateKey []byte, message []byte) (Proof, error) {
privKey := (*[libsodium.SECRETKEYBYTES]byte)(unsafe.Pointer(&(*privateKey)))
privKey := (*[libsodium.SECRETKEYBYTES]byte)(unsafe.Pointer(&privateKey))
pf, err := libsodium.Prove(privKey, message)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion networks/local/localnode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.15-alpine

RUN apk update && \
apk upgrade && \
apk add --no-cache git make gcc libc-dev build-base curl jq bash file gmp-dev clang
apk add --no-cache git make gcc libc-dev build-base curl jq bash file gmp-dev clang libtool autoconf automake

VOLUME [ "/ostracon" ]
WORKDIR /ostracon
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
FROM golang:1.15

RUN apt-get -qq update -y && apt-get -qq upgrade -y >/dev/null
RUN apt-get -qq install -y libleveldb-dev librocksdb-dev >/dev/null
RUN apt-get -qq install -y libleveldb-dev librocksdb-dev libtool libboost-all-dev autoconf build-essential >/dev/null

# Set up build directory /src/ostracon
ENV OSTRACON_BUILD_OPTIONS badgerdb,boltdb,cleveldb,rocksdb
Expand Down
2 changes: 1 addition & 1 deletion tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ vagrant_test:
### go tests
test:
@echo "--> Running go test"
@go test -p 1 $(PACKAGES) -tags deadlock
@go test -p 1 $(PACKAGES) -tags deadlock $(BUILD_TAGS)
.PHONY: test

test_race:
Expand Down

0 comments on commit eed25ef

Please sign in to comment.