Skip to content
Business logic Write-up Intermediate

Mt Pelerin

The cancelOnHoldTransfers function failed to check if a transaction was already cancelled, allowing an attacker to pass an array of identical transactions and drain the contract's funds. The bug was fixed and a $10,000 bounty was paid.

medium.com

Published on medium.com

Mt Pelerin

Immunefi, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

Mt Pelerin's bridge-protocol-v2 includes a ComplianceRegistry.sol smart contract. The registry stores all identity information linked to an address and the history of transfers linked to an address. It is managed by trusted intermediaries, the KYC/AML providers: each trusted intermediary has its own space within the registry to update its own address-related information, and based on the token's trusted intermediaries the registry returns the compliance information updated by one of them.

The feature at the centre of this report is the on-hold transfer. The Bridge Protocol's processor detects non-compliant token transfers and places them on hold until compliance staff review the transaction and approve or reject it. A function named cancelOnHoldTransfer lets any user cancel transfers for a specific trusted intermediary to get their tokens back. It requires three things from the caller:

  1. the address of the trusted intermediary,
  2. an array of transactions to be cancelled, and
  3. skipMinBoundaryUpdate, which determines whether or not to skip the minBoundary, an index used to limit iterations to avoid an out of gas exception.

Setup

The report describes an anonymous whitehat working against Mt Pelerin's bridge-protocol-v2 through Immunefi. No accounts, tooling or versions are given beyond the contract and function names.

Finding it

The whitehat found that cancelOnHoldTransfers failed to verify whether a transaction was repeated or had already been marked as cancelled. The function has a for loop over the array of transactions the user asked to cancel. For each element it verifies that transfer.from and msg.sender are the same, changes the transaction's status to cancel, transfers the token to the recipient, and emits a TransferCancelled event. Nothing in that loop checks whether the entry has already been cancelled, so the same transaction can appear in the array many times and each occurrence is processed as if it were fresh.

Exploitation

Step 1: call the cancellation function with a repeated array

The attacker calls cancelOnHoldTransactions() with an array of identical transactions to be cancelled.

Step 2: the sender check passes

The contract loops through the user-supplied transaction array and ensures that the sender of each transaction matches msg.sender.

Step 3: the transfer is cancelled and paid out

Once it confirms the transaction was initiated by the same user, the contract cancels the transfer but does not check whether it has previously been cancelled. It simply transfers the token and emits the TransferCancelled event.

Step 4: the loop repeats on the same transaction

The function moves to the next array element, which is again the same transaction. There is no check that it has already been cancelled, so the payout happens again. The loop proceeds through the array without ever detecting the repetition, until all funds have been drained.

Root cause

The mistake is a missing state check in cancelOnHoldTransactions(). The function validates ownership (transfer.from == msg.sender) but not the current status of the transfer before paying out. Because the status change to cancelled is not used as a guard on subsequent iterations, a duplicated array element is treated as a new cancellation each time.

Impact

A malicious hacker could provide an array containing the same transaction several times and drain the contract, because instead of reverting on an already-cancelled transaction the contract sends additional funds to the user. The bug was reported as critical severity and could have allowed an attacker to drain the contract of funds. No user funds were lost: Mt Pelerin acknowledged the vulnerability, fixed it, and paid a $10,000 bounty.

Fix

Mt Pelerin fixed the vulnerability by adding a check which verifies that the status of the transfer is on hold and not already cancelled.

GitHub Commit From the original on medium.com

Variants to test

  • Look for other cancellation or refund functions that take an array of identifiers and pay out per element. A positive result is a function that validates ownership but never re-reads the item's status inside the loop, so a duplicated identifier produces a second payout.
  • Check whether status updates are written before or after the external token transfer. A positive result is a payout that happens before the status is persisted, allowing a repeat within the same call or across calls.
  • Test the skipMinBoundaryUpdate style flags on similar loops: a caller-controlled switch that skips iteration bounds may allow a larger array than intended. A positive result is a call that processes more entries than the boundary was meant to permit.
  • Try arrays mixing valid and already-cancelled entries to see whether the whole call reverts or only the invalid entries are skipped. A positive result is partial processing that still pays out for entries that should have been rejected.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

Mt Pelerin runs a service that moves tokens (digital money on a blockchain) between people, and it has a set of rules about who is allowed to send tokens to whom. Sometimes a transfer breaks those rules, so the system does not complete it straight away. Instead it puts the transfer "on hold" and a human compliance officer looks at it later and decides whether to approve or reject it.

While a transfer is on hold, the person who sent it is allowed to cancel it and get their tokens back. That is a normal, useful feature. The problem was in the code that performs the cancellation: it never checked whether a particular transfer had already been cancelled. So if someone asked to cancel the same transfer many times in a single request, the code happily paid out each time, as if each copy were a brand new cancellation. That could have emptied the contract of its funds.

An anonymous security researcher (a "whitehat", someone who looks for bugs in order to report them rather than exploit them) found this and reported it through Immunefi, a platform that runs bug bounty programmes. Mt Pelerin confirmed the problem, fixed it, and paid a $10,000 reward. No user money was lost.

From the original on medium.com

The image above is the header of the published bugfix review, showing the title "Mt Pelerin Double Transaction Bugfix Review" and the publication date, 23 November 2022.

The pieces involved

Before the bug makes sense, a few ideas need explaining from scratch.

Smart contract. A smart contract is a program that lives on a blockchain. Once deployed, anyone can call its functions, and the code runs exactly as written. Think of it as a vending machine: you press a button, it follows its internal rules, and it either gives you the item or refuses. Nobody can reach inside and change the rules while it is running.

Token. A token is a digital unit of value recorded on the blockchain. It behaves a bit like a balance in an online account, except the balance is stored publicly and moved by smart contract code rather than by a bank.

Address. An address is a long string of characters that identifies an account on the blockchain, similar to an account number. Every user and every contract has one.

Bridge protocol. A bridge moves tokens or information from one place to another. Mt Pelerin's bridge-protocol-v2 is the set of contracts that handles this movement.

Compliance registry. Mt Pelerin's ComplianceRegistry.sol smart contract stores all identity information linked to an address, and the history of transfers linked to an address. It is managed by trusted intermediaries, the KYC/AML providers. KYC means "know your customer" and AML means "anti money laundering": these are the checks financial services must perform to confirm who a customer is and where their money comes from. Each trusted intermediary has its own space within the registry to update its own address-related information, and based on the token's trusted intermediaries the registry returns the compliance information updated by one of them. In everyday terms, the registry is like a shared filing cabinet where several authorised clerks each have their own drawer, and the token asks the cabinet whether a given person is cleared to receive funds.

On-hold transfer. The Bridge Protocol's processor detects non-compliant token transfers and places them on hold until compliance staff review the transaction and approve or reject it. Picture a parcel that the post office holds at the counter because the paperwork is incomplete: it is neither delivered nor returned until a clerk looks at it.

The cancellation function. A function named cancelOnHoldTransfer lets any user cancel transfers for a specific trusted intermediary to get their tokens back. It requires three things from the caller:

  1. the address of the trusted intermediary,
  2. an array of transactions to be cancelled, and
  3. skipMinBoundaryUpdate, which determines whether or not to skip the minBoundary, an index used to limit iterations to avoid an out of gas exception.

An array is simply an ordered list. If you ask a friend to buy three things, you hand them a list; an array is the same idea in code, a list of items passed together in one request. An index is a position in that list, like the number of a house on a street. Out of gas is what happens when a blockchain program runs for longer than the network allows: every step costs a small fee called gas, and if the steps run out of the allowance, the whole operation stops. The minBoundary exists to keep loops short enough to avoid that.

Setting the scene

The report describes an anonymous whitehat working against Mt Pelerin's bridge-protocol-v2 through Immunefi. No accounts, tooling or versions are given beyond the contract and function names.

Finding the bug

The whitehat found that cancelOnHoldTransfers failed to verify whether a transaction was repeated or had already been marked as cancelled. The function has a for loop over the array of transactions the user asked to cancel. A for loop is code that repeats the same steps once for each item in a list, like a cashier scanning each item in your basket one by one. For each element it verifies that transfer.from and msg.sender are the same, changes the transaction's status to cancel, transfers the token to the recipient, and emits a TransferCancelled event.

transfer.from is the address that originally sent the transfer, and msg.sender is the address of whoever is calling the function right now. Comparing them is an ownership check: it confirms you are cancelling your own transfer and not somebody else's. An event is a public note that the contract writes to the blockchain log so that other software and observers can see that something happened; it is like a receipt printed and filed automatically.

Nothing in that loop checks whether the entry has already been cancelled, so the same transaction can appear in the array many times and each occurrence is processed as if it were fresh. This class of mistake is often called a business logic flaw: the code does exactly what it was written to do, but the rules it enforces are incomplete. It is not a broken lock; it is a door with a perfectly working handle that was never told to stay shut after the first person walked through.

How the attack would work

Step 1: call the cancellation function with a repeated array

The attacker calls cancelOnHoldTransactions() with an array of identical transactions to be cancelled. Instead of a list of three different transfers, the list contains the same transfer three times, or thirty times. The contract has no reason to expect that, so it does not reject the request on sight.

Step 2: the sender check passes

The contract loops through the user-supplied transaction array and ensures that the sender of each transaction matches msg.sender. The ownership check is doing its job correctly; it is simply answering a different question from the one that matters here. It confirms "is this yours?" but never asks "have you already been paid for this one?".

Step 3: the transfer is cancelled and paid out

Once it confirms the transaction was initiated by the same user, the contract cancels the transfer but does not check whether it has previously been cancelled. It simply transfers the token and emits the TransferCancelled event. So the first copy in the list produces a genuine, correct payout.

Step 4: the loop repeats on the same transaction

The function moves to the next array element, which is again the same transaction. There is no check that it has already been cancelled, so the payout happens again. The loop proceeds through the array without ever detecting the repetition, until all funds have been drained. Each extra copy in the list is another withdrawal from the same original deposit, like photocopying a single receipt and presenting each copy at the till for a separate refund.

Why it happened

The mistake is a missing state check in cancelOnHoldTransactions(). State is the contract's stored memory of how things currently stand: which transfers exist, and whether each one is on hold, approved or cancelled. The function validates ownership (transfer.from == msg.sender) but not the current status of the transfer before paying out. Because the status change to cancelled is not used as a guard on subsequent iterations, a duplicated array element is treated as a new cancellation each time.

A useful comparison is a cloakroom. The attendant checks that the ticket is yours, hands over the coat, and writes "collected" in the book. If the attendant checks the ticket but never reads the book, you can come back with the same ticket all afternoon. The fix is not a better ticket check; it is reading the book before handing anything over.

What could have happened

A malicious hacker could provide an array containing the same transaction several times and drain the contract, because instead of reverting on an already-cancelled transaction the contract sends additional funds to the user. Reverting means the contract refuses the operation and undoes it, which is the safe response to a request that should not be allowed. The bug was reported as critical severity and could have allowed an attacker to drain the contract of funds. No user funds were lost: Mt Pelerin acknowledged the vulnerability, fixed it, and paid a $10,000 bounty.

The fix

Mt Pelerin fixed the vulnerability by adding a check which verifies that the status of the transfer is on hold and not already cancelled.

GitHub Commit From the original on medium.com

The image above shows the GitHub commit where the fix was made, as referenced in the report's Vulnerability Fix section.

The cloakroom attendant now reads the book.

Where else to look

If you want to hunt for similar bugs yourself, these are the patterns worth testing. Each one is a variation on the same theme: a loop that pays out per item without re-reading the item's current state.

  • Look for other cancellation or refund functions that take an array of identifiers and pay out per element. A positive result is a function that validates ownership but never re-reads the item's status inside the loop, so a duplicated identifier produces a second payout.
  • Check whether status updates are written before or after the external token transfer. A positive result is a payout that happens before the status is persisted, allowing a repeat within the same call or across calls.
  • Test the skipMinBoundaryUpdate style flags on similar loops: a caller-controlled switch that skips iteration bounds may allow a larger array than intended. A positive result is a call that processes more entries than the boundary was meant to permit.
  • Try arrays mixing valid and already-cancelled entries to see whether the whole call reverts or only the invalid entries are skipped. A positive result is partial processing that still pays out for entries that should have been rejected.

What to take away

Three lessons stand out for someone new to this field.

  1. A check that answers one question does not answer all of them. Confirming ownership is not the same as confirming eligibility, and code needs both.
  2. Whenever a function pays something out, ask what stops it from paying twice. If the answer is "nothing in the loop", that is the bug.
  3. Reporting a bug responsibly, as this whitehat did, turned a potential loss into a $10,000 reward and a patched contract. Bug bounty programmes exist precisely to make that the better option for everyone.

Glossary

  • Address: a string of characters identifying an account or contract on a blockchain, similar to an account number.
  • AML: anti money laundering, the rules financial services follow to prevent money being moved to hide its origin.
  • Array: an ordered list of items passed together, for example a list of transactions.
  • Blockchain: a shared, public record of transactions that many computers keep in sync and that cannot easily be altered afterwards.
  • Bridge protocol: a set of contracts that moves tokens or information from one place to another.
  • Bug bounty: a programme that pays researchers for reporting security bugs instead of exploiting them.
  • Business logic flaw: a bug where the code works as written but the rules it enforces are incomplete, so it can be used in unintended ways.
  • Compliance registry: a contract storing identity information and transfer history for addresses, managed by trusted intermediaries.
  • Contract: see smart contract.
  • Critical severity: the highest rating for a bug, meaning it could cause severe loss or damage.
  • Event: a public note a contract writes to the blockchain log so others can see that something happened.
  • For loop: code that repeats the same steps once for each item in a list.
  • Gas: the small fee charged for each step a blockchain program runs; running out of it stops the operation.
  • Index: a position in a list, like the number of a house on a street.
  • KYC: know your customer, the checks a service performs to confirm a customer's identity.
  • minBoundary: an index used to limit loop iterations so the code does not run out of gas.
  • msg.sender: the address of whoever is currently calling the function.
  • On-hold transfer: a transfer that broke a compliance rule and is paused until staff approve or reject it.
  • Out of gas: the failure that occurs when a blockchain program runs longer than the network's allowance permits.
  • Revert: to refuse an operation and undo it, the safe response to a request that should not be allowed.
  • Smart contract: a program on a blockchain that anyone can call and that runs exactly as written.
  • State: a contract's stored memory of how things currently stand, such as the status of each transfer.
  • Token: a digital unit of value recorded on a blockchain.
  • transfer.from: the address that originally sent a transfer.
  • Whitehat: a security researcher who finds bugs in order to report them rather than exploit them.

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.