Batch: resolve issues #3187, #3158, #3063, #2703
Resolve #3187 Resolve #3158 Resolve #3063 Resolve #2703 This MR implements the changes described in issues #3187, #3158, #3063, #2703.
I'll examine the current diff to verify the description's accuracy.
Summary
All four issues share one root cause: the authz keeper was given the
application msg service router, so a message wrapped in authz.MsgExec
reached its handler having skipped the THORChain ante handler - the only place
several messages are authorized, gated and charged. The authz module was
removed from the app in d517826a, which closes every reported exploit path.
What this MR does is stop treating the ante handler as the only place those
rules live, so the same class of bypass cannot come back through another
dispatcher, and keep authz out.
#3187 - x/denom is contract-only, enforced by the Msg server. The keeper
takes a new ContractKeeper (the app wires in the wasm keeper), and the Msg
server now checks that the sender of MsgCreateDenom, MsgMintTokens,
MsgBurnTokens and MsgChangeDenomAdmin is an instantiated CosmWasm contract,
returning ErrUnauthorized otherwise. Nothing legitimate changes - wasmd
already requires a dispatched message to be signed by the contract that
dispatched it. Also fixes the non-canonical denom conversion deduplicated into
that issue: getDeposit parsed a bank denom into an asset that the deposit
path converts back, and the conversion is not injective (x/rune and RUNE
both parse to THOR.RUNE, whose denom is rune), so the balance debited could
be a denom other than the one sent. Coins that do not survive the round trip
are rejected; zero amount coins, which only carry a memo, are exempt. A test in
app asserts authz messages have no route in the application router.
#3158 - the outer tx memo no longer runs with someone else's authority. A
send to the THORChain module address becomes a MsgDeposit whose memo comes
from the transaction body and whose signer is the send's FromAddress; those
are the same account only when the sender signed the transaction. The ante
handler now records the transaction body's signers in the context alongside the
memo (keyed by raw address bytes, deliberately not bech32 - those bytes are
unverified at that point), and getDeposit refuses to convert a send whose
sender is not among them. A dispatcher that wants a deposit must use
MsgDeposit, which carries its own memo as part of the message being
authorized.
#3063 - the bank send gate and the send origin are enforced in the handler.
BankSendEnabled and the native tx fee are applied by the ante handler, which
only sees top level messages. MsgSendValidate now applies the
BankSendEnabled gate itself and requires every send to be either signed by
its sender or dispatched by a CosmWasm contract, via a new
WasmManager.HasContract. Contracts are deliberately exempt from the gate -
they move funds on behalf of their users while executing an already
permissioned contract, and pay through the fee of the wrapping transaction.
BankSendHandler.MultiSend, which returned success without transferring
anything, now refuses the message.
#2703 - regression tests for the ante fee path. AnteHandle is now tested
end to end with authz messages, asserting the transaction is rejected and the
next decorator is never reached, and a companion test covers the recorded
signer set. WasmExecuteAnteDecorator's switch - which authz messages left
along with the module - now documents why a message that executes other
messages must not be added back to it.
Note on the signer-set fallback
TxSignedBy reads a context with no recorded signer set as "every address is a
signer", because such a context never ran the ante handler: InitGenesis, unit
and regression tests that build a context directly, and the block lifecycle
(notably x/scheduler's EndBlocker contract executions). Nothing on those paths
dispatches a MsgSend from an address that is not the executing contract, and
a send reaching getDeposit from a block hook carries no memo either. The
function carries a TODO: marking trusted internal contexts explicitly would be
a safer default than reading a missing signer set as authorization.
Not addressed
The POL Reserve whitelist mimir classification deduplicated into #3187 is
deliberately left alone: POLRESERVEWHITELIST was added to the operational
partial matches by ef72482b ("Classify POL Reserve whitelist Mimirs as
operational"), which flipped the corresponding unit test at the same time. That
is a governance decision to revisit on its own, not an unintended bypass.
Testing
go test -tags mocknet ./x/thorchain/... ./x/denom/... ./app/...passes, including new tests for each change.- 37 regression suites re-run locally (send, deposit, wasm, rujira, secured-assets, trade-accounts, node, switch, tcy, core), all passing.
send/bank-sendgained a case covering the aliasing denom send; its fixtures are regenerated.