EVM¶
EVM support targets Safe accounts with execTransaction. The library builds and
verifies the Safe transaction, the EIP 712 digest, owner approvals, and the final
calldata.
Supported Safe versions¶
SafeVersion.V1_3_0SafeVersion.V1_4_1
The Safe operation is fixed to CALL. safeTxGas, baseGas, gasPrice,
gasToken, and refundReceiver are fixed to zero. Batched MultiSend calls,
delegate calls, and arbitrary contract calls are not supported.
Addresses¶
Use EvmAddress for checksummed EVM addresses.
from multisig_escrow.evm import EvmAddress
owner = EvmAddress.parse("0x1111111111111111111111111111111111111111")
An all lowercase or all uppercase address is normalized to a checksum address. A mixed case address must already have a valid checksum.
Safe account¶
SafeAccount describes the deployed Safe. Its owners must match the escrow
signer keys exactly, and its threshold must match the escrow threshold.
from multisig_escrow.evm import EvmAddress, SafeAccount, SafeVersion
safe = SafeAccount(
address=EvmAddress.parse(safe_address),
chain_id=1,
owners=(
EvmAddress.parse(buyer_address),
EvmAddress.parse(seller_address),
EvmAddress.parse(arbiter_address),
),
threshold=2,
version=SafeVersion.V1_4_1,
)
The optional deployment field can hold a SafeDeployment for counterfactual
address prediction and setup call construction. It is not required for an
already deployed Safe.
Chain object¶
Assets¶
Native ETH:
ERC20:
from multisig_escrow.evm import Erc20Asset, EvmAddress
asset = Erc20Asset(
chain_id=1,
address=EvmAddress.parse(token_address),
symbol="USDC",
decimals=6,
)
The application is responsible for the token allowlist. The library verifies
that the asset is a NativeAsset or Erc20Asset on the same chain and that the
transfer calldata matches the asset and amount.
Payouts¶
from multisig_escrow.evm import EvmAddress, EvmPayout
payout = EvmPayout(
address=EvmAddress.parse(seller_address),
chain_id=1,
)
Both payouts must be on the same chain as the Safe.
Build terms¶
from datetime import UTC, datetime, timedelta
from multisig_escrow import (
ConfirmationPolicy,
EscrowId,
EscrowTerms,
FeePolicy,
Role,
Signer,
SignerId,
)
now = datetime.now(UTC)
terms = EscrowTerms.create(
escrow_id=EscrowId.generate(),
chain=chain,
asset=asset,
amount=1_000_000,
signers=(
Signer(SignerId("buyer"), Role.BUYER, EvmAddress.parse(buyer_address)),
Signer(SignerId("seller"), Role.SELLER, EvmAddress.parse(seller_address)),
Signer(SignerId("arbiter"), Role.ARBITER, EvmAddress.parse(arbiter_address)),
),
threshold=2,
buyer_payout=EvmPayout(EvmAddress.parse(buyer_address), 1),
seller_payout=EvmPayout(EvmAddress.parse(seller_address), 1),
funding_deadline=now + timedelta(days=1),
settlement_deadline=now + timedelta(days=30),
confirmation_policy=ConfirmationPolicy(12, 12),
fee_policy=FeePolicy(0, 0),
now=now,
)
EVM terms require FeePolicy(0, 0). The Safe transaction does not pay a protocol
fee. Gas is paid by the account that submits the outer transaction.
Funding target¶
escrow = EvmEscrow.create(terms, store=store)
target = escrow.funding_target()
print(target.safe.value)
print(target.chain_id)
print(target.asset)
print(target.amount)
print(target.confirmations)
Fresh context¶
EVM funding requires an EvidenceContext with a ChainTip.
from multisig_escrow import ChainTip, EvidenceContext
context = EvidenceContext(
now=now,
tip=ChainTip(
height=tip_height,
hash=tip_hash,
timestamp=tip_time,
),
)
The tip must not be in the future and must not be older than one hour. If the funding evidence includes a block height, the library checks that the declared confirmation count does not exceed the depth implied by the tip.
Funding evidence¶
from multisig_escrow.evm import SafeFundingEvidence
evidence = SafeFundingEvidence(
safe=safe.address,
chain_id=1,
asset=asset,
txid=funding_txid,
amount=1_000_000,
confirmations=12,
block_height=funding_block,
)
escrow.fund(evidence, context)
The library verifies the target Safe, chain ID, asset, amount, confirmation count, and block depth. It cannot prove that the transaction is in the best chain. Supply evidence from a trusted node or independent verifier.
Release proposal¶
from multisig_escrow import SignerId
from multisig_escrow.evm import EvmReleaseParams
proposal = escrow.propose_release(
SignerId("buyer"),
EvmReleaseParams(nonce=7),
)
The nonce is the Safe nonce, not an Ethereum account nonce. The library does
not query the Safe. Read the current Safe nonce from a trusted source and pass
it explicitly. A stale or future nonce produces calldata that the Safe will
reject or execute at an unintended time.
proposal.plan is a SafeTransferPlan. Its signing_hash is the EIP 712 Safe
transaction digest.
Approvals¶
A Safe owner signs the 32 byte digest.
from multisig_escrow.evm import SafeApproval
digest = proposal.plan.signing_hash
signature = owner_key.sign_msg_hash(digest).to_bytes()
escrow.approve(SafeApproval(signature))
escrow.approve also accepts raw 65 byte signature bytes. Each call recovers the
owner address and applies one approval. The escrow moves to release_ready when
the policy is satisfied.
The library normalizes v, rejects high s values, rejects duplicate owners,
orders signatures by owner address, and builds the final Safe signature blob. It
does not sign and does not contact the Safe.
Finalize¶
final.outer_to is the Safe address. final.outer_value is zero. final.calldata
is the ABI encoded execTransaction call.
Submit an outer transaction from an account that can pay gas:
The Safe executes the inner transfer when the owner threshold is met.
Broadcast evidence¶
The library cannot query the Safe or the chain. Provide either the raw outer transaction or the Safe execution log.
from multisig_escrow import BroadcastEvidence
escrow.mark_broadcast(
BroadcastEvidence(
txid=outer_txid,
payload_hash=final.payload_hash,
raw_tx=raw_outer_tx,
)
)
If raw_tx is provided, the library parses the outer transaction, extracts the
Safe calldata, and verifies the owner policy and payload binding.
If only the execution log is provided, use the 64 byte or 96 byte form that binds the Safe transaction hash. A 96 byte log must start with the Safe execution success topic.
Confirmation¶
Confirmation evidence is caller supplied. Verify inclusion and depth against a trusted source before calling.
Refund¶
from multisig_escrow import SignerId
from multisig_escrow.evm import EvmRefundParams
proposal = escrow.propose_refund(
SignerId("buyer"),
EvmRefundParams(nonce=safe_nonce),
)
The refund path pays the buyer payout. It follows the same approval and finalization flow as a release.
Disputes¶
When a dispute is opened and the terms require an arbiter, the approval policy also requires at least one arbiter approval. The arbiter must be a Safe owner and an escrow signer.
Operational notes¶
- Verify the Safe address, Safe version, owner set, and threshold against a trusted source.
- Verify the Safe nonce before proposing.
- Verify the inner transfer target, amount, and asset on the signing device.
- Confirm the token contract and decimals if you use ERC20.
- Use a confirmation policy appropriate to the chain and value at risk.
- EVM has no native timelock. Deadline enforcement is in the escrow state machine, not in the Safe.
- Keep the trusted terms hash outside the store.