Calculating tax amount does not include taxes in `WasmMsg::Execute` messages
The function `get_tax_amount()` only counts tax amounts in `BankMsg::Send` messages, ignoring those in `WasmMsg::Execute` messages. This can cause payment transfers to fail or allow payers to skip taxes when fee recipients have a custom message set.
Source: https://github.com/sherlock-audit/2024-05-andromeda-ado-judging/issues/37
The protocol has acknowledged this issue.
Found by
g
Summary
get_tax_amount() fetches the amount of tax to be paid by totaling the amounts in the message transfers generated by the on_funds_transfer() hook. However, it only counts CosmosMsg::Bank(BankMsg::Send) messages and not the WasmMsg::Execute messages. This either fails the transfer or allows payors to skip paying taxes.
Vulnerability Detail
The issue lies in get_tax_amount()'s mapping logic over the messages generated by on_funds_transfer().
ref: std/src/common/rates.rs::get_tax_amount()
pub fn get_tax_amount(
msgs: &[SubMsg],
base_amount: Uint128,
remaining_amount_after_royalties: Uint128,
) -> Uint128 {
let deducted_amount = base_amount - remaining_amount_after_royalties;
msgs.iter()
.map(|msg| {
if let CosmosMsg::Bank(BankMsg::Send { amount, .. }) = &msg.msg {
amount[0].amount
} else {
Uint128::zero()
}
})
Only taxes wrapped in BankMsg::Send are included. However, fee recipients with a msg set will get generated a WasmMsg::Execute message instead.
ref: std/src/amp/recipient.rs::generate_direct_msg()
Ok(match &self.msg {
Some(message) => SubMsg::new(WasmMsg::Execute {
contract_addr: resolved_addr.to_string(),
msg: message.clone(),
funds,
}),
None => SubMsg::new(CosmosMsg::Bank(BankMsg::Send {
to_address: resolved_addr.to_string(),
amount: funds,
})),
})
Any taxes sent to recipients with a msg set will not be counted by get_tax_amount().
Impact
The following effects will take place:
- When at least one royalty is wrapped in a
WasmMsg::Execute,get_tax_amount()will fail. Payment transfers for non-fungible ADO contracts will fail since non-fungible ADO contracts useget_tax_amont(). - When there are no royalties and at least one tax is in a
WasmMsg::Executemsg, the tax wrapped in aWasmMsg::Executemessage will be ignored. Payers can skip paying theWasmMsg::Executetaxes in these cases.
In effect, fee recipients with msg can not be used or it will lead to failures in non-fungible ADO contracts.
Code Snippet
- https://github.com/sherlock-audit/2024-05-andromeda-ado/blob/main/andromeda-core/packages/std/src/common/rates.rs#L16-L33
- https://github.com/sherlock-audit/2024-05-andromeda-ado/blob/main/andromeda-core/packages/std/src/amp/recipient.rs#L55-L59
Tool used
Manual Review
Recommendation
Consider modifying get_tax_amount() to count the taxes in WasmMsg::Execute messages.
Discussion
gjaldon
Escalate
This valid issue shows that not all taxes will be counted. Only taxes wrapped in BankMsg::Send will be counted even though some taxes will be wrapped in WasmMsg::Execute. This causes either valid payment transactions to fail or allows payers to skip paying some taxes.
std/src/common/rates.rs::get_tax_amount() is also in-scope.
sherlock-admin3
Escalate
This valid issue shows that not all taxes will be counted. Only taxes wrapped in
BankMsg::Sendwill be counted even though some taxes will be wrapped inWasmMsg::Execute. This causes either valid payment transactions to fail or allows payers to skip paying some taxes.std/src/common/rates.rs::get_tax_amount() is also in-scope.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
cvetanovv
Indeed, not all fees are counted when get_tax_amount() is called. So, I plan to accept the escalation and make the issue a valid Medium.
gjaldon
Thank you ππΌ
WangSecurity
@gjaldon @MxAxM are there any duplicates?
WangSecurity
Result: Medium Unique
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- gjaldon: accepted
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
When at least one royalty is wrapped in a `WasmMsg::Execute`, `get_tax_amount()` will fail, causing payment transfers for non-fungible ADO contracts to fail; when there are no royalties and at least one tax is in a `WasmMsg::Execute` message, the tax will be ignored, allowing payers to skip paying those taxes.
What the attacker needed
A fee recipient with a msg set; a non-fungible ADO contract using get_tax_amount()
The fix
The function `get_tax_amount()` should be modified to also count taxes in `WasmMsg::Execute` messages.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In blockchain smart contracts, when a payment is made, the contract may send funds to multiple recipients. Some recipients receive funds directly via a bank send, while others receive funds by executing a contract call. The function that calculates the total tax only looks at the direct bank sends, so it misses taxes that are sent via contract calls. This can cause the payment to fail or let people avoid paying some taxes.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.