Repository navigation
Expand file tree
/
Copy pathMultisig.mk
More file actions
126 lines (110 loc) · 6.05 KB
/
Copy pathMultisig.mk
File metadata and controls
126 lines (110 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Multisig.mk — Global macros for multisig approve / execute workflows.
#
# Every task template should `include ../../Multisig.mk` and define at minimum:
# RPC_URL — the RPC endpoint (typically $(L1_RPC_URL) or $(L2_RPC_URL))
# SCRIPT_NAME — the Forge script class name or .sol file path
#
# The two macros below (MULTISIG_APPROVE, MULTISIG_EXECUTE) are the canonical
# way to invoke multisig operations. Signing is handled externally by the
# task-signing-tool.
#
# ---------- Common fragments ----------
# Forge runs from $(PROJECT_DIR), so for a task sharing a project the relative
# `broadcast` setting in foundry.toml resolves into the shared project rather
# than the task. Anchor it to the task dir so records archive with the task.
# For a task that is its own Forge project this is where records already go.
export FOUNDRY_BROADCAST ?= $(CURDIR)/records
LEDGER_HD_PATH = "m/44'/60'/$(LEDGER_ACCOUNT)'/0/0"
empty :=
space := $(empty) $(empty)
comma := ,
# Join a whitespace-separated list with ", " and normalize whitespace
comma_join = $(subst $(space),$(comma) ,$(strip $(foreach w,$(1),$(w))))
# Validation helper for required variables
require_vars = $(foreach _var,$(2),$(if $(strip $($(_var))),,$(error $(1): required variable $(_var) is not defined)))
# ---------- Procedures ----------
# MULTISIG_APPROVE: $(1)=address list (space-separated), $(2)=signatures (e.g., 0x or $(SIGNATURES))
define MULTISIG_APPROVE
$(call require_vars,MULTISIG_APPROVE,LEDGER_ACCOUNT RPC_URL SCRIPT_NAME) \
cd $(PROJECT_DIR) && $(MISE_EXEC) forge script --rpc-url $(RPC_URL) $(SCRIPT_NAME) \
--sig "approve(address[],bytes)" "[$(call comma_join,$(1))]" $(2) \
--ledger --hd-paths $(LEDGER_HD_PATH) --broadcast -vvvv
endef
# MULTISIG_EXECUTE: $(1)=signatures for run(bytes) (e.g., 0x or $(SIGNATURES))
define MULTISIG_EXECUTE
$(call require_vars,MULTISIG_EXECUTE,LEDGER_ACCOUNT RPC_URL SCRIPT_NAME) \
cd $(PROJECT_DIR) && $(MISE_EXEC) forge script --rpc-url $(RPC_URL) $(SCRIPT_NAME) \
--sig "run(bytes)" $(1) \
--ledger --hd-paths $(LEDGER_HD_PATH) --broadcast -vvvv
endef
# ---------- Validation file generation ----------
# GEN_VALIDATION: Generate a validation JSON file for multisig signing.
# $(1)=script_name, $(2)=safe_addr (comma-separated, or empty for []),
# $(3)=sender, $(4)=output_file, $(5)=env_vars (optional prefix)
#
# NOTE: The embedded `--forge-cmd` uses the bare literal `mise exec --` rather
# than `$(MISE_EXEC)`. The latter expands at Makefile parse time to either
# `mise exec --` (mise on PATH) or `$(HOME)/.local/bin/mise exec --` (fallback),
# which would bake a machine-specific absolute path into the generated validation
# JSON's `cmd` field — and that JSON is committed to the repo and re-hashed at
# verification time on other machines. By keeping the literal token, the
# committed file is portable; the trade-off is that `mise` must be discoverable
# on the signer-tool subprocess's PATH (see the bootstrap-mise warning and the
# README "Toolchain (mise)" section for the PATH requirement).
VALIDATIONS_DIR ?= $(CURDIR)/validations
define GEN_VALIDATION
$(call require_vars,GEN_VALIDATION,RPC_URL LEDGER_ACCOUNT) \
cd $(SIGNER_TOOL_PATH) && \
$(MISE_EXEC) npx tsx scripts/genValidationFile.ts \
--rpc-url $(RPC_URL) \
--workdir $(PROJECT_DIR) \
--forge-cmd '$(if $(5),$(5) )mise exec -- forge script --rpc-url $(RPC_URL) $(1) --sig "sign(address[])" "[$(2)]" --sender $(3)' \
--ledger-id $(LEDGER_ACCOUNT) \
--out $(VALIDATIONS_DIR)/$(4) $(if $(strip $(TASK_NETWORK)),&& python3 $(REPO_ROOT)/scripts/validation-drift.py stamp --task-dir "$(CURDIR)" --network "$(TASK_NETWORK)" "$(VALIDATIONS_DIR)/$(4)")
endef
# Regeneration needs internal RPC access; public CI only checks input fingerprints.
# Indirection keeps make -n from executing comparisons without regenerated files.
validation_drift_make = $(MAKE)
validation_drift_targets = $(shell sed -n 's/^\(gen-validation[^ :]*\):.*/\1/p' Makefile | sort -u)
.PHONY: check-validations
check-validations:
@test "$(origin TASK_NETWORK)" = "command line" && test -n "$(TASK_NETWORK)" || { echo 'check-validations: TASK_NETWORK is required on the command line'; exit 1; }
@set -eu; \
targets='$(validation_drift_targets)'; \
test -n "$$targets" || { echo 'check-validations: no gen-validation targets found'; exit 1; }; \
committed="$(CURDIR)/config/$(TASK_NETWORK)/validations"; \
test -d "$$committed" || { echo "check-validations: missing committed validations directory $$committed"; exit 1; }; \
tmp=$$(mktemp -d "$${TMPDIR:-/tmp}/validation-drift.XXXXXX"); \
trap 'rm -rf "$$tmp"' EXIT HUP INT TERM; \
for target in $$targets; do \
$(validation_drift_make) TASK_NETWORK="$(TASK_NETWORK)" VALIDATIONS_DIR="$$tmp" "$$target"; \
done; \
status=0; \
for file in "$$committed/"*.json "$$committed/".*.json; do \
test -e "$$file" || continue; name=$${file##*/}; \
if test ! -f "$$tmp/$$name"; then \
echo "check-validations: extra committed validation $$name"; status=1; \
else \
python3 "$(REPO_ROOT)/scripts/validation-drift.py" compare --network "$(TASK_NETWORK)" "$$file" "$$tmp/$$name" || status=1; \
fi; \
done; \
for file in "$$tmp/"*.json "$$tmp/".*.json; do \
test -e "$$file" || continue; name=$${file##*/}; \
if test ! -f "$$committed/$$name"; then echo "check-validations: missing committed validation $$name"; status=1; fi; \
done; \
if test "$$status" -ne 0; then echo "Regenerate with the task's gen-validation targets on an internal machine, then review the diff."; fi; \
exit "$$status"
# ---------- Helpers ----------
# GET_NONCE: Fetch the current nonce of a Safe contract.
# $(1)=safe_address
define GET_NONCE
$(shell $(MISE_EXEC) cast call $(1) "nonce()" --rpc-url $(RPC_URL) | $(MISE_EXEC) cast to-dec)
endef
# ADDR_UPPER: Convert an address to uppercase (for env var construction).
# Used to build per-Safe nonce override env vars passed to forge scripts,
# e.g. SAFE_NONCE_$(call ADDR_UPPER,$(SAFE_ADDR))=$(NONCE_VALUE)
# See mainnet/2026-02-19-superchain-separation for real-world usage.
# $(1)=address
define ADDR_UPPER
$(shell echo "$(1)" | tr '[:lower:]' '[:upper:]')
endef