diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1431c7e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "sys-asm"] + path = sys-asm + url = https://github.com/wemeetagain/sys-asm.git diff --git a/Makefile b/Makefile index 81e806a..bfa3f40 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -.PHONY: build build-gpu build-metal build-cuda-lib build-cuda clean test list-gpus help +.PHONY: build build-gpu build-metal build-cuda-lib build-cuda clean test list-gpus help \ + initcode initcode-deposit initcode-exit mine-deposit .sys-asm-ref BINARY_NAME=nick GOBUILD=go build @@ -73,6 +74,84 @@ clean: rm -f $(BINARY_NAME) rm -f miner/kernel/*.o miner/kernel/*.a +# --------------------------------------------------------------------------- +# Contract init code (assembled from the sys-asm submodule) +# +# The predeploy contracts are geas assembly in the `sys-asm` submodule. +# Assembling ctor.eas yields `ctor ++ runtime` = the deployment init code, +# whose bytes determine the vanity address. These targets emit it 0x-prefixed, +# ready for `./nick search --initcode`. +# +# REF selects the sys-asm revision (a SHA is used from the local clone; a +# branch is fetched at runtime). Default = the pinned commit below. +# make initcode-deposit # pinned default (offline) +# make initcode-deposit REF= # any commit +# make initcode-deposit REF= # latest branch tip (fetches) +# TODO: when the contracts land on sys-asm main, point +# SYS_ASM_REMOTE=https://github.com/ethereum/sys-asm.git and REF=main. +# --------------------------------------------------------------------------- +GEAS ?= $(shell command -v geas 2>/dev/null || echo "$$(go env GOPATH)/bin/geas") +SYS_ASM_DIR ?= sys-asm +SYS_ASM_REMOTE ?= https://github.com/wemeetagain/sys-asm.git +REF ?= 537b9c17d14705e77bc3f512e17dd253ad69b020 +DEPOSIT_CTOR := $(SYS_ASM_DIR)/src/builder_deposits/ctor.eas +EXIT_CTOR := $(SYS_ASM_DIR)/src/builder_exits/ctor.eas + +# Vanity search parameters (override on the command line). The target address +# is 0x0000-leading with a 00 suffix; sig-r spells the EIP number too. +# EIP has no default -- set it, or pass SUFFIX/SIG_R explicitly. +# make mine-deposit EIP= # suffix 0x00, sig-r 0x +# make mine-deposit SUFFIX=0xdead SIG_R=0xdead # override directly +EIP ?= +PREFIX ?= 0x0000 +SUFFIX ?= $(if $(EIP),0x00$(EIP)) +SIG_R ?= $(if $(EIP),0x$(EIP)) +SCORE ?= 10 +GPU_BACKEND ?= cuda +GPU_DEVICES ?= all +BATCH ?= 67108864 + +# Ensure the sys-asm submodule is present, checked out at $(REF), and that geas +# is available. Run as a prerequisite of the init code / mining targets. +.sys-asm-ref: + @test -e $(DEPOSIT_CTOR) || git submodule update --init $(SYS_ASM_DIR) >/dev/null 2>&1 || { \ + echo "ERROR: sys-asm submodule missing; run: git submodule update --init $(SYS_ASM_DIR)"; exit 1; } + @if echo "$(REF)" | grep -qE '^[0-9a-fA-F]{7,40}$$'; then \ + git -C $(SYS_ASM_DIR) checkout -q $(REF) 2>/dev/null || { \ + git -C $(SYS_ASM_DIR) fetch -q $(SYS_ASM_REMOTE) $(REF) && \ + git -C $(SYS_ASM_DIR) checkout -q FETCH_HEAD; }; \ + else \ + git -C $(SYS_ASM_DIR) fetch -q $(SYS_ASM_REMOTE) $(REF) && \ + git -C $(SYS_ASM_DIR) checkout -q FETCH_HEAD; \ + fi + @command -v $(GEAS) >/dev/null 2>&1 || test -x $(GEAS) || { \ + echo "ERROR: geas not found; run: go install github.com/fjl/geas/cmd/geas@latest"; exit 1; } + +## initcode-deposit: Print 0x-prefixed builder-deposit init code (pipeable) +initcode-deposit: .sys-asm-ref + @printf '0x%s\n' "$$($(GEAS) $(DEPOSIT_CTOR))" + +## initcode-exit: Print 0x-prefixed builder-exit init code (pipeable) +initcode-exit: .sys-asm-ref + @printf '0x%s\n' "$$($(GEAS) $(EXIT_CTOR))" + +## initcode: Show both init codes with byte sizes and the assembled sys-asm commit +initcode: .sys-asm-ref + @echo "sys-asm @ $$(git -C $(SYS_ASM_DIR) rev-parse --short HEAD) (REF=$(REF))" + @dep=$$($(GEAS) $(DEPOSIT_CTOR)); echo "deposit ($$(( $${#dep}/2 )) bytes): 0x$$dep" + @ext=$$($(GEAS) $(EXIT_CTOR)); echo "exit ($$(( $${#ext}/2 )) bytes): 0x$$ext" + +## mine-deposit: Assemble the deposit init code and run the GPU vanity search +mine-deposit: .sys-asm-ref + @test -n "$(SUFFIX)" -a -n "$(SIG_R)" || { \ + echo "ERROR: which EIP do you want to mine for? Set EIP=, e.g.:"; \ + echo " make mine-deposit EIP="; \ + echo " (or override SUFFIX=0x... SIG_R=0x... directly)"; exit 1; } + @test -x ./$(BINARY_NAME) || { echo "ERROR: ./$(BINARY_NAME) not built; run: make build-cuda"; exit 1; } + ./$(BINARY_NAME) search --gpu --gpu-backend $(GPU_BACKEND) --gpu-devices $(GPU_DEVICES) \ + --batch-size $(BATCH) --initcode 0x$$($(GEAS) $(DEPOSIT_CTOR)) \ + --prefix $(PREFIX) --suffix $(SUFFIX) --sig-r $(SIG_R) --score $(SCORE) + ## help: Show this help help: @echo "Usage: make [target]" diff --git a/sys-asm b/sys-asm new file mode 160000 index 0000000..537b9c1 --- /dev/null +++ b/sys-asm @@ -0,0 +1 @@ +Subproject commit 537b9c17d14705e77bc3f512e17dd253ad69b020