From 1d0482a7fc8e0e04ead53e5f81874cf4e8bafa88 Mon Sep 17 00:00:00 2001 From: noot <36753753+noot@users.noreply.github.com> Date: Mon, 1 Aug 2022 21:54:32 -0400 Subject: [PATCH] update dleq library (#142) --- .github/workflows/checks.yml | 9 ++++---- .gitmodules | 4 ++++ Makefile | 20 ++++++++++-------- dleq/cgo-dleq | 1 + dleq/cgo_dleq_test.go | 9 ++++++++ go.mod | 4 +++- go.sum | 4 ++-- scripts/build-macos.sh | 41 ++++++++++++++++++++++++++++++++++++ scripts/build-windows.sh | 41 ++++++++++++++++++++++++++++++++++++ scripts/install-rust.sh | 3 ++- 10 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 .gitmodules create mode 160000 dleq/cgo-dleq create mode 100644 scripts/build-macos.sh create mode 100644 scripts/build-windows.sh diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 06bd52ca..2894da30 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -18,10 +18,7 @@ jobs: run: diff -u <(echo -n) <(gofmt -d -s .) - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: 'latest' - args: -v + run: make lint vet-check: runs-on: ubuntu-latest @@ -32,4 +29,6 @@ jobs: - uses: actions/checkout@v2 - name: Run go vet - run: go vet ./... \ No newline at end of file + run: | + make init + go vet ./... diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..918463d7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "dleq/cgo-dleq"] + path = dleq/cgo-dleq + url = https://github.com/noot/cgo-dleq.git + branch = main diff --git a/Makefile b/Makefile index 27d09851..829b4724 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,14 @@ -.PHONY: lint test install build build-dleq mock -all: build-dleq install +.PHONY: init lint test install build build-dleq mock +all: install GOPATH ?= $(shell go env GOPATH) -lint: +init: + ./scripts/install-rust.sh + git submodule update --init --recursive + cd dleq/cgo-dleq && make build + +lint: init ./scripts/install-lint.sh ${GOPATH}/bin/golangci-lint run @@ -13,17 +18,14 @@ test: test-integration: ./scripts/run-integration-tests.sh -install: +install: init cd cmd/ && go install && cd .. -build: +build: init ./scripts/build.sh -build-all: +build-all: init ALL=true ./scripts/build.sh - -build-dleq: - ./scripts/install-rust.sh && cd farcaster-dleq && cargo build --release && cd .. mock: go generate -run mockgen ./... diff --git a/dleq/cgo-dleq b/dleq/cgo-dleq new file mode 160000 index 00000000..d0716fb5 --- /dev/null +++ b/dleq/cgo-dleq @@ -0,0 +1 @@ +Subproject commit d0716fb55684d8768b80f2e75b2da1bab085d752 diff --git a/dleq/cgo_dleq_test.go b/dleq/cgo_dleq_test.go index f1762370..7e5ed315 100644 --- a/dleq/cgo_dleq_test.go +++ b/dleq/cgo_dleq_test.go @@ -32,6 +32,15 @@ func TestCGODLEq(t *testing.T) { require.Equal(t, res.ed25519Pub[:], ed25519Pub) } +func TestCGODLEq_Invalid(t *testing.T) { + proof, err := (&CGODLEq{}).Prove() + require.NoError(t, err) + proof.proof[0] = 0 + + _, err = (&CGODLEq{}).Verify(proof) + require.Error(t, err) +} + func TestProofSecretComputesVerifyPubKeys(t *testing.T) { // It would be nice to increase the number of iterations, but it's pretty slow even at 128. We // previously had an issue when X or Y needed at least one high order padding byte. The chance diff --git a/go.mod b/go.mod index 1d598d25..0c095f62 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/libp2p/go-libp2p-discovery v0.5.1 github.com/libp2p/go-libp2p-kad-dht v0.15.0 github.com/multiformats/go-multiaddr v0.4.1 - github.com/noot/cgo-dleq v0.0.0-20220501212638-9961539c958f + github.com/noot/cgo-dleq v0.0.0-20220726051627-d0716fb55684 github.com/stretchr/testify v1.7.1 github.com/urfave/cli v1.22.5 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 @@ -141,3 +141,5 @@ require ( gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) + +replace github.com/noot/cgo-dleq => ./dleq/cgo-dleq diff --git a/go.sum b/go.sum index c548e5ae..6cf2caeb 100644 --- a/go.sum +++ b/go.sum @@ -978,8 +978,8 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/noot/cgo-dleq v0.0.0-20220501212638-9961539c958f h1:fA56suVDpwUlsU/AS9oWJZaPjMNxoRKLMgkHAqT0n1Y= -github.com/noot/cgo-dleq v0.0.0-20220501212638-9961539c958f/go.mod h1:jkCwyyhTIZfTMPJDKcWoC/naacZz0wbksGkrBxZIbJM= +github.com/noot/cgo-dleq v0.0.0-20220726051627-d0716fb55684 h1:T4KqJ947AnY/V0/rizx72GM6bnOn1OsGJKieHJuyayk= +github.com/noot/cgo-dleq v0.0.0-20220726051627-d0716fb55684/go.mod h1:jkCwyyhTIZfTMPJDKcWoC/naacZz0wbksGkrBxZIbJM= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= diff --git a/scripts/build-macos.sh b/scripts/build-macos.sh new file mode 100644 index 00000000..b3537336 --- /dev/null +++ b/scripts/build-macos.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +export GOOS=darwin +export GOARCH=amd64 + +echo "building swapd..." +cd cmd/daemon +if ! go build -o swapd-amd64-darwin ; then + exit 1 +fi +mv swapd ../.. +echo "done building swapd." + +echo "building swapcli..." +cd ../client +if ! go build -o swapcli-amd64-darwin ; then + exit 1 +fi +mv swapcli ../.. +echo "done building swapcli." + +if [[ -z "${ALL}" ]]; then + exit 0 +fi + +echo "build swaprecover..." +cd ../recover +if ! go build -o swaprecover-amd64-darwin ; then + exit 1 +fi +mv swaprecover ../.. +echo "done building swaprecover." + +echo "building swaptester..." +cd ../tester +if ! go build -o swaptester-amd64-darwin ; then + exit 1 +fi +mv swaptester ../.. +cd ../.. +echo "done building swaptester." diff --git a/scripts/build-windows.sh b/scripts/build-windows.sh new file mode 100644 index 00000000..a8fdb587 --- /dev/null +++ b/scripts/build-windows.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +export GOOS=windows +export GOARCH=amd64 + +echo "building swapd..." +cd cmd/daemon +if ! go build -o swapd.exe ; then + exit 1 +fi +mv swapd ../.. +echo "done building swapd." + +echo "building swapcli..." +cd ../client +if ! go build -o swapcli.exe ; then + exit 1 +fi +mv swapcli ../.. +echo "done building swapcli." + +if [[ -z "${ALL}" ]]; then + exit 0 +fi + +echo "build swaprecover..." +cd ../recover +if ! go build -o swaprecover.exe ; then + exit 1 +fi +mv swaprecover ../.. +echo "done building swaprecover." + +echo "building swaptester..." +cd ../tester +if ! go build -o swaptester.exe ; then + exit 1 +fi +mv swaptester ../.. +cd ../.. +echo "done building swaptester." diff --git a/scripts/install-rust.sh b/scripts/install-rust.sh index 8d7728bb..42a0c69e 100755 --- a/scripts/install-rust.sh +++ b/scripts/install-rust.sh @@ -3,4 +3,5 @@ if ! command -v rustup &> /dev/null then curl https://sh.rustup.rs -sSf | sh fi -rustup default stable \ No newline at end of file +rustup default stable +rustup update \ No newline at end of file