go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

accounts/usbwallet: use updated hid (only) library

Open holiman opened this issue 1 year ago • 7 comments

Replaces https://github.com/ethereum/go-ethereum/pull/28901

  • [x] Ledger-devices on Linux (Nano X, Nano S, Nano S Plus)
  • [x] Ledger-devices on Mac
  • [ ] Ledger-devices on windows
  • [ ] Trezor on Linux
  • [ ] Trezor on Max
  • [ ] Trezor on Windows

holiman avatar Feb 07 '24 08:02 holiman

Right, we need libudev on the CI-builds.

Waiting for command "build/cache/golangci-lint-1.55.2-linux-amd64/golangci-lint"
accounts/usbwallet/hub.go:29:2: could not import github.com/karalabe/hid (-: # github.com/karalabe/hid
In file included from ../../.gvm/pkgsets/go1.20.7/global/pkg/mod/github.com/karalabe/[email protected]/hid_enabled.go:47:
./hidapi/linux/hid.c:43:10: fatal error: libudev.h: No such file or directory
   43 | #include <libudev.h>
      |          ^~~~~~~~~~~
compilation terminated.) (typecheck)
	"github.com/karalabe/hid"
	^
util.go:48: exit status 1

holiman avatar Feb 07 '24 10:02 holiman

Ugh, this might have been one of the root issues. You need an extra lib installed locally, so Geth's code becomes non-portable...

Another quote from the USB lib:

For HID-only devices, a previous self-contained package was created at github.com/karalabe/hid, which worked well for hardware wallet uses cases in go-ethereum. It's a simple package that does its thing well. Unfortunately, hid is not capable of talking to generic USB devices. When multiple different devices are needed, eventually some will not support the HID spec (e.g. WebUSB). Pulling in both hid and gousb will break down due to both depending internally on different versions of libusb on Linux.

karalabe avatar Feb 08 '24 10:02 karalabe

You need an extra lib installed locally,

Isn't that only for building?

holiman avatar Feb 08 '24 10:02 holiman

No idea, throw a docker build at it and see if it chokes on the result

karalabe avatar Feb 08 '24 10:02 karalabe

make geth && ldd ./build/bin/geth
go run build/ci.go install ./cmd/geth
>>> /usr/local/go/bin/go build -ldflags "-X github.com/ethereum/go-ethereum/internal/version.gitCommit=6513641729ea56dc0cb1a01396f3b5b78a9a6d53 -X github.com/ethereum/go-ethereum/internal/version.gitDate=20240207 -extldflags '-Wl,-z,stack-size=0x800000'" -tags urfave_cli_no_docs,ckzg -trimpath -v -o /home/user/go/src/github.com/ethereum/go-ethereum/build/bin/geth ./cmd/geth
Done building.
Run "./build/bin/geth" to launch geth.
        linux-vdso.so.1 (0x00007ffdaa881000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007e4bef4dc000)
        libudev.so.1 => /lib64/libudev.so.1 (0x00007e4bef4a8000)
        libc.so.6 => /lib64/libc.so.6 (0x00007e4bef2ca000)
        libcap.so.2 => /lib64/libcap.so.2 (0x00007e4bef2c0000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007e4bef29c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007e4bef4fe000)

$ go run build/ci.go install github.com/ethereum/go-ethereum/cmd/geth
>>> /usr/local/go/bin/go build -ldflags "-X github.com/ethereum/go-ethereum/internal/version.gitCommit=6513641729ea56dc0cb1a01396f3b5b78a9a6d53 -X github.com/ethereum/go-ethereum/internal/version.gitDate=20240207 -extldflags '-Wl,-z,stack-size=0x800000'" -tags urfave_cli_no_docs,ckzg -trimpath -v -o /home/user/go/src/github.com/ethereum/go-ethereum/build/bin/geth github.com/ethereum/go-ethereum/cmd/geth
[user@work go-ethereum]$ ldd /home/user/go/src/github.com/ethereum/go-ethereum/build/bin/geth 
        linux-vdso.so.1 (0x00007ffeaf5fa000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x000079c36b7ed000)
        libudev.so.1 => /lib64/libudev.so.1 (0x000079c36b7b9000)
        libc.so.6 => /lib64/libc.so.6 (0x000079c36b5db000)
        libcap.so.2 => /lib64/libcap.so.2 (0x000079c36b5d1000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000079c36b5ad000)
        /lib64/ld-linux-x86-64.so.2 (0x000079c36b80f000)

Yeah I guess that's a bummer

holiman avatar Feb 08 '24 10:02 holiman

So, when trying to build it statically:

[user@work go-ethereum]$ go run build/ci.go install -static  github.com/ethereum/go-ethereum/cmd/geth
>>> /usr/local/go/bin/go build -ldflags "-X github.com/ethereum/go-ethereum/internal/version.gitCommit=6513641729ea56dc0cb1a01396f3b5b78a9a6d53 -X github.com/ethereum/go-ethereum/internal/version.gitDate=20240207 -extldflags '-Wl,-z,stack-size=0x800000 -static'" -tags urfave_cli_no_docs,ckzg,osusergo,netgo -trimpath -v -o /home/user/go/src/github.com/ethereum/go-ethereum/build/bin/geth github.com/ethereum/go-ethereum/cmd/geth
...
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -ludev: No such file or directory
/usr/bin/ld: cannot find -lc: No such file or directory
collect2: error: ld returned 1 exit status

holiman avatar Feb 08 '24 10:02 holiman

I've now updated karalabe/hid, so that it uses a locally built libusb instead of requiring libudev on the target. PR here.

This PR now contains the update lib. I tested the change locally, via go mod replace, to see if it still works on linux. And yes, the device-path is different, but it still opens and derives addresses, so all good

INFO [02-09|11:03:13.477] New wallet appeared                      url=ledger://1-1:1.0 status="Ethereum app v1.9.19 online"

holiman avatar Feb 09 '24 12:02 holiman