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 97863c5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
2 changes: 2 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
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/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 Down
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: build
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 tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ vagrant_test:
.PHONY: vagrant_test

### go tests
test:
test: build
@echo "--> Running go test"
@go test -p 1 $(PACKAGES) -tags deadlock
.PHONY: test
Expand Down

0 comments on commit 97863c5

Please sign in to comment.