Closed jimpick closed 3 months ago
@Stebalien suggested it might be possible to replace the cgo library with a pure go implementation (used by libp2p):
This shouldn't affect gas because "FVM uses https://github.com/paritytech/libsecp256k1 and message inclusion charges for storage, not signature verification"
Fwiw this same library has been used for over a year in https://pkg.go.dev/github.com/jsign/go-filsigner
Awesome! I looks like we may be able to borrow the glue code from that library as well (I'd depend on it directly, but that would introduce a cycle).
If we want to eliminate the problematic ipsn/go-secp256k1
dependency from Lotus, the following modules would need to be updated to use the replacement implementation. (from go mod graph
in Lotus)
github.com/ipsn/go-secp256k1@v0.0.0-20180726113642-9d62b9f0bc52
github.com/filecoin-project/go-address@v1.1.0
github.com/filecoin-project/filecoin-ffi@v0.30.4-0.20220519234331-bfd1f5f9fe38
github.com/filecoin-project/go-fil-markets@v1.28.3
github.com/filecoin-project/go-state-types@v0.13.1
github.com/filecoin-project/test-vectors/schema@v0.0.7
github.com/ipni/index-provider@v0.12.0
github.com/filecoin-project/go-state-types@v0.11.2-0.20230712101859-8f37624fa540
github.com/filecoin-project/filecoin-ffi@v0.30.4-0.20200910194244-f640612a1a1f
github.com/filecoin-project/go-commp-utils@v0.1.3
github.com/filecoin-project/go-commp-utils/nonffi@v0.0.0-20220905160352-62059082a837
github.com/filecoin-project/go-crypto@v0.0.1
github.com/filecoin-project/go-crypto@v0.0.0-20191218222705-effae4ea9f03
github.com/filecoin-project/go-address@v0.0.5
github.com/filecoin-project/specs-actors@v0.9.15
github.com/filecoin-project/specs-actors/v3@v3.1.2
github.com/filecoin-project/specs-actors/v4@v4.0.2
github.com/filecoin-project/specs-actors/v5@v5.0.6
github.com/filecoin-project/specs-actors/v6@v6.0.2
github.com/filecoin-project/specs-actors/v7@v7.0.1
github.com/filecoin-project/specs-actors/v8@v8.0.1
github.com/filecoin-project/go-state-types@v0.1.10
github.com/filecoin-project/go-state-types@v0.1.6
github.com/filecoin-project/specs-actors@v0.9.15-0.20220514164640-94e0d5e123bd
github.com/filecoin-project/go-address@v0.0.3
github.com/filecoin-project/specs-actors/v2@v2.3.6
github.com/filecoin-project/go-state-types@v0.0.0-20201102161440-c8033295a1fc
github.com/filecoin-project/specs-actors@v0.9.13
github.com/filecoin-project/go-state-types@v0.1.0
github.com/filecoin-project/go-state-types@v0.0.0-20200928172055-2df22083d8ab
It was easier to fork go-ethereum and rename the symbols there. I experimented with that approach here, and it worked:
Because there is no longer a replace directive in go.mod
, we can now use go install
:
$ go install github.com/glifio/cli@2c22d4e4f1164d9f3e2448f38828065ebdcd86c1
$ cli
Usage:
glif [command]
Available Commands:
agent Commands for interacting with the Glif Agent
completion Generate the autocompletion script for the specified shell
help Help about any command
ifil Commands for interacting with the Infinity Pool Liquid Staking Token (iFIL)
infinity-pool Commands for interacting with the Infinity Pool
info Prints information about the CLI
pools Commands for interacting with the GLIF Pools Protocol
wallet Manage Glif wallets
wfil Commands for interacting with Wrapped Filecoin tokens
Flags:
--config-dir string config directory
-h, --help help for glif
-t, --toggle Help message for toggle
Use "glif [command] --help" for more information about a command.
The downside to this approach is that you have to use the forked go-ethereum, which is probably a turn-off for most developers.
If we want to eliminate the problematic ipsn/go-secp256k1 dependency from Lotus, the following modules would need to be updated to use the replacement implementation. (from go mod graph in Lotus)
Those are transitive dependencies through go-crypto (with maybe a few exceptions).
I.e., updating go-crypto in the root module to a version that doesn't depend on the ipni package should be sufficient.
That sounds great. I didn't understand that go modules would work that way.
I did make a jimpick/go-crypto
package here that uses glifio/go-secp256k1
instead of ipsn/go-secp256k1
: https://github.com/jimpick/go-crypto/tree/glifio_secp256k1
It's still the same native library, just with renamed symbols.
Without using a replace directive, I can't really test it as a replacement for the filecoin-project/go-crypto
package ... as I don't have the ability to write to that repo.
The Jon
branch in this repository will fix this issue
Developers who are building applications in go that use both go-ethereum and go-crypto will encounter a build error that looks like this:
This happens because go-crypto is using https://github.com/ipsn/go-secp256k1 .. which consists of a cgo based library extracted from go-ethereum.
So when go-crypto is used at the same time as go-ethereum in a binary, both cgo libraries get built, but both have the same symbol names, so it won't link.
For the glif binaries, we've developed a workaround using a replace directive in go.mod and a forked version of go-secp256k1:
This workaround only works if the replace directive is used in go.mod. Unfortunately that means that the glif cli can't be distributed using
go install
: