Skip to content
Business logic Audit finding Intermediate

_notSameBlock() can be circumvented in bondToAccount()

The bondToAccount() function uses a per-address same-block check that can be bypassed by calling through an intermediary smart contract, because the check keys on msg.sender. An attacker could therefore perform multiple actions in the same block that the protocol intended to prevent.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon, also found by leastwood and ScopeLift

The function bondToAccount() of Bonding.sol has a check based on _notSameBlock() _notSameBlock() makes sure the same msg.sender cannot do 2 actions within the same block.

However this can be circumvented in this case: Suppose you call bondToAccount() via a (custom) smart contract, then the msg.sender will be the address of the smart contract. For a pseudo code proof of concept see below.

I’m not sure what the deeper reason is for the _notSameBlock() in bondToAccount(). But if it is important then circumventing this check it will pose a risk.

Proof of Concept

call function attack1.attack()

contract attack1 {
   function attack(address account, uint256 amount) {
         call attack2.forward(account, amount);
         call any other function of malt
  }
}

contract attack2 {
   function forward(address account, uint256 amount) {
       call bonding.bondToAccount(account, amount); // uses msg.sender of attack2
   }
}

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/Bonding.sol#L81-L92

function bondToAccount(address account, uint256 amount) public {
    if (msg.sender != offering) {
         _notSameBlock();
    }
    ...

https://github.com/code-423n4/2021-11-malt/blob/d3f6a57ba6694b47389b16d9d0a36a956c5e6a94/src/contracts/Permissions.sol#L135-L141

function _notSameBlock() internal {
    require( block.number > lastBlock[_msgSender()],"Can't carry out actions in the same block" );
    lastBlock[_msgSender()] = block.number;
  }

Recommended Mitigation Steps

Add access controls to the function bondToAccount() An end-user could still call bond()

0xScotch (sponsor) confirmed

Alex the Entreprenerd (judge) commented:

notSameBlock is effectively being used as the nonReentrant modifier, without the same security guarantees, as such, in spite of not having a specific attack vector, because the warden showed how to side step this security feature of the protocol, am going to raise the severity to Medium

The original report as published on Code4rena, by gpersoon. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Root cause

Likely the same-block restriction is keyed on msg.sender, which can be changed by routing calls through a new smart contract, so the restriction does not bind the actual user.

Impact

The same-block restriction can be bypassed, potentially allowing actions the protocol intended to limit to one per block; the judge noted no specific attack vector was demonstrated but raised severity because a security feature was side-stepped.

What the attacker needed

Ability to deploy a smart contract; the bondToAccount function is callable

The fix

Add access controls to bondToAccount() so that only authorised callers can invoke it, rather than relying on the same-block check.

How it was found

  1. Deploy a helper contract that forwards calls to the bonding contract.
  2. From another contract, call the helper so that the bonding contract sees the helper as msg.sender.
  3. Because the helper's address has no recorded last block, the same-block check passes.
  4. Perform other actions in the same block through different helper contracts or addresses.

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.

A smart contract can call another contract, and when it does, the called contract sees the caller's address as the intermediary contract, not the original user. The protocol tried to stop the same user from doing two things in one block by remembering the caller's address, but using a middleman contract gives a different address each time, so the check is fooled.

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.

More by gpersoon

View all

47 more disclosed reports, best first.

More from Malt Protocol - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.