Coder Social home page Coder Social logo

cashu-feni's Introduction

cashu-feni

made-with-Go GoReportCard example Docker Github tag codecov

Cashu is a Chaumian Ecash wallet and mint with Bitcoin Lightning support.

Disclaimer: The author is NOT a cryptographer and this work has not been reviewed. This means that there is very likely a fatal flaw somewhere. Cashu is still experimental and not production-ready.

Cashu is an Ecash implementation based on David Wagner's variant of Chaumian blinding. Token logic based on minicash (description) which implements a Blind Diffie-Hellman Key Exchange scheme written down by Ruben Somsen here. The database mechanics and the Lightning backend uses parts from LNbits.

Please read the Cashu documentation for more detailed information.

This project aims to replicate the python mint implementation of cashu.

Install

Source · Download · Docker

From source

These steps will help you installing cashu-feni from source. This project has two parts, a Cashu command line wallet and a mint.

Requirements

Building

git clone https://github.com/cashubtc/cashu-feni && cd cashu-feni

Copy config_example.yaml to config.yaml and update configuration values.

Wallet

go build -o feni cmd/cashu/feni.go && ./feni

Mint

go build -v -o cashu-feni cmd/mint/mint.go && ./cashu-feni

Download

Download the latest binary from releases

Using Docker

Start cashu-feni using docker. Please provide a local volume path to the data folder.

docker pull cashubtc/cashu-feni
docker run -it -p 3338:3338 \
-v $(pwd)/data/:/app/data/ \
cashubtc/cashu-feni

Mounting custom config.yaml to /app/config.yaml

docker run -it -p 3338:3338 \
-v $(pwd)/config.yaml:/app/config.yaml \
-v $(pwd)/data/:/app/data/ \
cashubtc/cashu-feni

Build image

git clone https://github.com/cashubtc/cashu-feni && cd cashu-feni
docker build -t cashu -f Dockerfile .

cashu-feni's People

Contributors

billigsteruser avatar callebtc avatar elnosh avatar gohumble avatar thesimplekid avatar thestack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cashu-feni's Issues

int64 casting returns different result based on `GOARCH`

What version of Go are you using (go version)?

$ go version go1.19.1 darwin/arm64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/humble/Library/Caches/go-build"
GOENV="/Users/humble/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/humble/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/humble/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tt/fs3zvlp53cgf_dtv5hhyc6cc0000gn/T/go-build2158361161=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Found some compatibility issues with arm64 and amd64
Due to this, I have changed all int64 amounts to uint64 to prevent this "bug".

Another solution would be reducing the MAX_ORDER of mints to 63

Script

package main

import (
	"fmt"
	"math"
)

func main() {
	pow := math.Pow(float64(2), float64(64))
	inti := int64(pow)
	fmt.Println(inti)
}

Casting int64 returns different results based on GOARCH.

~/go/src/github.com/gohumble/cashu-feni arm_amd*                                                                                                                                                       14:58:24
❯ go run cmd/cashu/test.go 
9223372036854775807
~/go/src/github.com/gohumble/cashu-feni arm_amd*                                                                                                                                                       14:58:34
❯ GOARCH=amd64 go run cmd/cashu/test.go
-9223372036854775808

What did you expect to see?

amd64 build should return the same int64 value

What did you see instead?

amd64 builds return different int64 values

UNIQUE constraint failed

What version of Go are you using (go version)?

$ go version
go version go1.22.0 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\user\AppData\Local\go-build
set GOENV=C:\Users\user\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\user\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\user\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\user\scoop\apps\go\current
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\user\scoop\apps\go\current\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.0
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\cashu-feni\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\user\AppData\Local\Temp\go-build2494365836=/tmp/go-build -gno-record-gcc-switches

What did you do?

$ go build -o feni cmd/cashu/feni.go && ./feni
time="2024-03-03T04:08:47+01:00" level=info msg="Loading default configuration"

2024/03/03 04:08:47 D:/cashu-feni/db/sql.go:54 UNIQUE constraint failed: key_sets.id
[0.510ms] [rows:0] INSERT INTO key_sets (id,derivation_path,mint_url,valid_from,valid_to,first_seen,active) VALUES ("47DEQpj8HBSa","","https://8333.space:3339","0000-00-00 00:00:00","0000-00-00 00:00:00","2024-03-03 04:08:47.512",false)

(cashu-feni)>

What did you expect to see?

no error

What did you see instead?

db error

panic in send command

What version of Go are you using (go version)?

$ go version
go version go1.21.0 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
go env GOOS
linux
go env GOARCH
amd64

What did you do?

Running mint locally along with wallet.
Pay lightning invoice to mint tokens. After paying invoice, ran balance command and getting expected balance.
After confirming wallet had a balance, send command panicked. It seems it tried to access filteredKeySets slice which is not initialized.

in wallet:
~ balance
You have balances in 1 keysets:
Keysets: [MhH6M+GDd1/l] Balance: 76 sat URL: http://localhost:3338

~ send 10 MhH6M+GDd1/l
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/cashubtc/cashu-feni/cmd/cashu/feni.send(0xc000259100?, {0xc000424560, 0x4?, 0xb2b9c2?})
/home/elnosh/Documents/cashu-feni/cmd/cashu/feni/send.go:126 +0x2f2
github.com/spf13/cobra.(*Command).execute(0x1054600, {0xc000424500, 0x2, 0x2})
/home/elnosh/go/pkg/mod/github.com/spf13/[email protected]/command.go:920 +0x863
github.com/spf13/cobra.(*Command).ExecuteC(0x10531e0)
/home/elnosh/go/pkg/mod/github.com/spf13/[email protected]/command.go:1040 +0x38d
github.com/spf13/cobra.(*Command).Execute(...)
/home/elnosh/go/pkg/mod/github.com/spf13/[email protected]/command.go:968
github.com/cashubtc/cashu-feni/cmd/cashu/feni.CobraPrompt.Run.func1({0xc00015af18, 0x14})
/home/elnosh/Documents/cashu-feni/cmd/cashu/feni/prompt.go:75 +0x1a5
github.com/c-bata/go-prompt.(*Prompt).Run(0xc00009c1b0)
/home/elnosh/go/pkg/mod/github.com/c-bata/[email protected]/prompt.go:84 +0x73f
github.com/cashubtc/cashu-feni/cmd/cashu/feni.CobraPrompt.Run({0x10531e0, {0x109fa00, 0x3, 0x3}, 0xc26b70, 0x1, 0x0, 0x1, 0x0, 0x0, ...})
/home/elnosh/Documents/cashu-feni/cmd/cashu/feni/prompt.go:90 +0x18f
main.main()
/home/elnosh/Documents/cashu-feni/cmd/cashu/feni.go:59 +0x17f

What did you expect to see?

serialized token to be sent

What did you see instead?

wallet panic trying to access empty slice.

General Implementation Guideline

Implementation requirements
A list of the requirements for a successful implementation.

*Example of a fully configured yaml file
mint:
host: 0.0.0.0
port: 3338
private_key: veryverysecretkey
derivation_path: 0/0/0/0
tls:
enabled: false
key_path: /home/tls.key
cert_path: /home/tls.crt
lightning:
enabled: false
lnbits:
lightning_fee_percent: 1.0
lightning_reserve_fee_min: 4000
admin_key: 1234567897894531351ab513154
url: https://legend.lnbits.comc

For instance mint: private_key: [ just make some shit up?]
mint: derivation_path: 0/0/0/0 [What?]

Lightning: guess one needs LNBits lightning wallet.

outputs constructed when doing split can tell mint the intended payment amount vs change

When sending from wallet, the way outputs are constructed in the request for /split they could be telling the mint which is the intended payment amount vs which is the change.

Code in wallet constructing output

	total := SumProofs(proofs)
	frstAmt := total - amount
	scndAmt := amount
	frstOutputs := mint.AmountSplit(frstAmt)
	scndOutputs := mint.AmountSplit(scndAmt)
	amounts := append(frstOutputs, scndOutputs...)

So if user has a balance of 100 and tries a send 20 the output amounts when requesting a split to the mint could look like [16, 64, 4, 16]

Describe the solution you'd like
Maybe sort the outputs slice before sending request to mint.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.