diff --git a/flake.lock b/flake.lock index e222e83036..b8f75f5018 100644 --- a/flake.lock +++ b/flake.lock @@ -23,6 +23,59 @@ "type": "github" } }, + "babylon": { + "flake": false, + "locked": { + "lastModified": 1736163423, + "narHash": "sha256-GtPuPFwjbxMx/fY+FXO8V3L+soYhA29ak8XbWBWO5Mk=", + "owner": "babylonlabs-io", + "repo": "babylon", + "rev": "b5646552a1606e38fcdfa97ed2606549b9a233f7", + "type": "github" + }, + "original": { + "owner": "babylonlabs-io", + "ref": "v1.0.0-rc.3", + "repo": "babylon", + "type": "github" + } + }, + "bls-eth-go": { + "flake": false, + "locked": { + "lastModified": 1704351134, + "narHash": "sha256-PpBs308170CHZt809QIdyy93D5x+5WTL7hlPytJrpXM=", + "ref": "refs/tags/v1.33.0", + "rev": "eb66a90ff51d7c982d668d6942e89815a8f7e323", + "revCount": 335, + "submodules": true, + "type": "git", + "url": "https://github.com/herumi/bls-eth-go-binary" + }, + "original": { + "ref": "refs/tags/v1.33.0", + "submodules": true, + "type": "git", + "url": "https://github.com/herumi/bls-eth-go-binary" + } + }, + "blst": { + "flake": false, + "locked": { + "lastModified": 1691598027, + "narHash": "sha256-oqljy+ZXJAXEB/fJtmB8rlAr4UXM+Z2OkDa20gpILNA=", + "owner": "supranational", + "repo": "blst", + "rev": "3dd0f804b1819e5d03fb22ca2e6fac105932043a", + "type": "github" + }, + "original": { + "owner": "supranational", + "repo": "blst", + "rev": "3dd0f804b1819e5d03fb22ca2e6fac105932043a", + "type": "github" + } + }, "cometbls": { "flake": false, "locked": { @@ -548,6 +601,9 @@ "root": { "inputs": { "arion": "arion", + "babylon": "babylon", + "bls-eth-go": "bls-eth-go", + "blst": "blst", "cometbls": "cometbls", "cosmosproto": "cosmosproto", "cosmossdk": "cosmossdk", diff --git a/flake.nix b/flake.nix index 73d78b741c..5512358835 100644 --- a/flake.nix +++ b/flake.nix @@ -51,6 +51,15 @@ url = "github:cosmos/ics23"; flake = false; }; + # for chains that require blst (babylon) + blst = { + url = "github:supranational/blst?rev=3dd0f804b1819e5d03fb22ca2e6fac105932043a"; + flake = false; + }; + bls-eth-go = { + url = "git+https://github.com/herumi/bls-eth-go-binary?ref=refs/tags/v1.33.0&submodules=1"; + flake = false; + }; cosmosproto = { url = "github:cosmos/cosmos-proto?ref=refs/tags/v1.0.0-beta.5"; flake = false; @@ -77,6 +86,10 @@ url = "github:osmosis-labs/osmosis/v24.0.0-rc0"; flake = false; }; + babylon = { + url = "github:babylonlabs-io/babylon/v1.0.0-rc.3"; + flake = false; + }; public-awesome-launchpad = { type = "github"; @@ -215,6 +228,7 @@ ./tools/tools.nix ./tools/wasm-light-client.nix ./tools/libwasmvm/libwasmvm.nix + ./tools/libblst/libblst.nix ./tools/tidy/tidy.nix ./tools/rust/rust.nix ./tools/rust/crane.nix @@ -228,6 +242,7 @@ ./networks/simulation/simd.nix ./networks/stargaze.nix ./networks/osmosis.nix + ./networks/babylon.nix ./e2e/all-tests.nix ./e2e/e2e.nix ./devnet-compose/devnet-compose.nix diff --git a/networks/babylon.nix b/networks/babylon.nix new file mode 100644 index 0000000000..7730ac4181 --- /dev/null +++ b/networks/babylon.nix @@ -0,0 +1,51 @@ +{ inputs, ... }: +{ + perSystem = + { + pkgs, + goPkgs, + self', + crane, + system, + ensureAtRepositoryRoot, + dbg, + ... + }: + { + packages = { + babylond = goPkgs.pkgsStatic.buildGo123Module ( + { + name = "babylond"; + src = inputs.babylon; + vendorHash = "sha256-wfvcbBdWBo2jYTiRymHDxL5f6X9RXr2scGuKNc5OaAY="; + doCheck = false; + doInstallCheck = false; + meta.mainProgram = "babylond"; + # CGO_ENABLED = 0; + subPackages = [ "./cmd/babylond" ]; + buildTags = [ "netgo" ]; + } + // ( + let + CGO_CFLAGS = "-I${self'.packages.libblst}/include -I${self'.packages.libblst.src}/src -I${self'.packages.libblst.src}/build -O"; + CGO_LDFLAGS = "-z noexecstack -static -L${goPkgs.musl}/lib -L${self'.packages.libwasmvm-2_1_3}/lib -s -w"; + in + if pkgs.stdenv.isLinux then + { + inherit CGO_CFLAGS; + inherit CGO_LDFLAGS; + # Statically link if we're on linux + nativeBuildInputs = [ + pkgs.musl + ]; + ldflags = [ + "-linkmode external" + ]; + } + else + { } + ) + ); + }; + }; +} diff --git a/tools/libblst/libblst.nix b/tools/libblst/libblst.nix new file mode 100644 index 0000000000..42fd681282 --- /dev/null +++ b/tools/libblst/libblst.nix @@ -0,0 +1,71 @@ +{ inputs, ... }: +{ + perSystem = + { pkgs, ... }: + let + enableShared = !pkgs.stdenv.hostPlatform.isStatic; + in + with pkgs; + { + packages.libblst = stdenv.mkDerivation rec { + pname = "blst"; + version = inputs.blst.shortRev; + src = inputs.blst; + buildPhase = + '' + ./build.sh + '' + + lib.optionalString enableShared '' + ./build.sh -shared + ''; + installPhase = '' + mkdir -p $out/{lib,include} + for lib in libblst.{a,so,dylib}; do + if [ -f $lib ]; then + cp $lib $out/lib/ + fi + done + cp bindings/{blst.h,blst_aux.h} $out/include + + for lib in blst.dll; do + if [ -f $lib ]; then + mkdir -p $out/bin + cp $lib $out/bin/ + fi + done + + mkdir -p $out/lib/pkgconfig + cat < $out/lib/pkgconfig/libblst.pc + prefix=$out + exec_prefix=\''${prefix} + libdir=\''${exec_prefix}/lib + includedir=\''${prefix}/include + + Name: libblst + Description: ${meta.description} + URL: ${meta.homepage} + Version: ${version} + + Cflags: -I\''${includedir} + Libs: -L\''${libdir} -lblst + Libs.private: + EOF + ''; + # ensure we have the right install id set. Otherwise the library + # wouldn't be found during install. The alternative would be to work + # lib.optional stdenv.isDarwin "LDFLAGS=-Wl,-install_name,$(out)/lib/libblst.dylib"; + # into the setup.sh + postFixup = lib.optionalString (stdenv.isDarwin && enableShared) '' + install_name_tool -id $out/lib/libblst.dylib $out/lib/libblst.dylib + ''; + enableParallelBuilding = true; + doCheck = true; + meta = with lib; { + description = "Multilingual BLS12-381 signature library"; + homepage = "https://github.com/supranational/blst"; + license = licenses.isc; + platforms = platforms.all; + }; + }; + }; +}