Multichain (Previously Anyswap)
Two bugs were found in Multichain's staking contracts: incorrect checkpoint calculations could break reward distribution and cause loss of unclaimed rewards, and the merge function did not decrease token supply. An attacker could exploit these to disrupt rewards or inflate supply.
medium.com
Published on medium.com
Blockchain
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.
Context
Multichain (previously Anyswap) runs staking contracts across several chains. The staking contract in scope was forked from the vote escrow contract of the Solidly exchange, so the same code, and the same bugs, exist on both. The contract had previously been audited by Blocksec and Peckshield. The author found two bugs in it and was paid as a whitehat hacker.
The feature at the centre of the first bug is the checkpoint history: the contract records points in point_history so that the voting power of veMulti NFTs can be calculated at* a specific time. The second bug concerns the merge function, which lets a user combine two NFTs into one.
Setup
The work was done against the staking contract source, with tests run from the author's GitHub repository, grGred/Anyswap-staking. The relevant contract file is contracts/ve.sol, and a fixed version with console logs is in contracts/veFixed.sol. No accounts, roles or tool versions are described beyond this.
Finding it
The author's starting point is that an audit is not a guarantee of safety. Reading the checkpoint logic, the problem line is L826 of contracts/ve.sol. The checkpoint internal function contains a for loop, and before the loop the latest checkpoint is saved into a variable called initial_last_point:
// initial_last_point is used for extrapolation to calculate block number// (approximately, for *At methods) and save them// as we cannot figure that out exactly from inside the contractPoint memory initial_last_point = last_point;
This does not create a new variable holding a copy of the last point. It creates a pointer to the latest point, so any change to initial_last_point also changes last_point. The author states this as a proof in the report, with a contract and a test.
The consequence appears when the contract has 0 checkpoints in a week. In that case the checkpoint internal function writes multiple checkpoints to point_history with the same block number and different timestamps, and the extrapolation of time is broken. The author notes that, because Multichain has multiple stakings on different chains and the market was bearish, it is very likely that people will not interact with one of the contracts for more than a week.
Exploitation
Step 1: Run the checkpoint test
The author points to the test "Rewards after withdraw disappears for expired locks" in the GitHub repository. Running it shows multiple checkpoints written with the same block number and different timestamps:

Step 2: Observe the effect on rewards
With the history points wrong, the amount of pending reward is broken. In some cases this leads to the loss of all unclaimed reward for a specific NFT, which is why the author classifies this as a critical bug. People with expired locks cannot claim their rewards if there are any, and those rewards disappear. If a person with an expired lock claims their rewards and withdraws their funds, all other users with active NFTs lose a significant amount of pending rewards, up to 50%. Reward distribution therefore works incorrectly and voting power is wrong.
Step 3: Merge two NFTs
For the second bug, the author looks at the merge function, which lets a user merge two NFTs into one. _burn burns the NFT but does not decrease the supply amount, so it is possible to increase the supply by the merging amount indefinitely. The test logs the supply amount before and after the merge, and the supply amount increases and no longer equals the amount of tokens:

Because the supply amount is not used for reward distribution, the author identifies this bug as medium.
Root cause
For the first bug, the root cause is the assignment Point memory initial_last_point = last_point;. In Solidity, memory does not copy a struct that already lives in storage; the local variable references the same data, so writing through initial_last_point mutates last_point. The for loop that follows then writes checkpoints into points_history with one block number and multiple timestamps, breaking the time extrapolation used by the at* methods.
For the second bug, the root cause is that _burn does not decrease the supply amount, so the merge path inflates supply by the merged amount each time.
Impact
For the first bug, the impact is on reward accounting and voting power. Holders of expired locks can lose all unclaimed rewards, and a single claim and withdrawal by such a holder can cost other users with active NFTs up to 50% of their pending rewards. The condition is that the contract goes a week without checkpoints, which the author considers likely given multiple stakings on different chains and low activity.
For the second bug, the impact is limited to the supply figure, which the author says is not used for reward distribution, hence the medium rating.
Fix
For the first bug, the author recommends redeploying the contract with a real copy of the last point:
// Copy all the data of last pointPoint memory initial_last_point = Point({ bias: last_point.bias, slope: last_point.slope, ts: last_point.ts, blk: last_point.blk});
The fixed contract with console logs is in contracts/veFixed.sol at L828-L833. An alternative is a backend that calls the checkpoint function every day, so the for loop is never reached and rewards are not broken. Multichain took this second route and now has a backend that calls checkpoint.
The report does not describe a fix for the merge supply bug.
The author closes by saying that no matter how many security audits you have, you must cover your code with unit tests properly, especially if the contract locks a large amount of tokens.
Variants to test
- Look for
Point memory x = last_point;style assignments in forked vote escrow contracts and check whether the local is later mutated. A positive result is a test that writes several entries topoints_historywith the same block number and different timestamps. - Check whether any contract in scope can go a week without a checkpoint call, for example low-activity stakings on secondary chains. A positive result is a checkpoint run after a quiet period that produces duplicate block numbers.
- Exercise the merge path and compare total supply before and after. A positive result is supply that grows by the merged amount while the token count stays the same.
- Review
_burnimplementations in similar NFT staking contracts for missing supply accounting. A positive result is any burn path that leaves the supply counter unchanged.
What happened, in plain words
A security researcher looked at the code behind Multichain, a service that lets people lock up cryptocurrency tokens and earn rewards for doing so. Multichain used to be called Anyswap. The particular code he examined was a "staking contract": a program that lives on a blockchain and holds people's locked tokens. The contract had been checked by two professional security firms, Blocksec and Peckshield, before he looked at it. Those checks are called audits. An audit is like having a building inspected by an engineer before you move in: it catches many problems, but it does not prove the building is perfect.
The researcher found two mistakes in the contract and reported them. Multichain paid him for the report, which makes him what people call a whitehat hacker: someone who finds weaknesses and tells the owner instead of abusing them.
The contract was not written from scratch. It was copied, or "forked", from a contract used by another exchange called Solidly. Because the code is the same, the same two mistakes exist in both places.
To follow the rest of this article you only need a browser and some patience. We will explain each idea as it comes up.
The two features involved
Feature one: checkpoint history and voting power
When you lock tokens in this contract you receive something called an NFT. NFT stands for non-fungible token: a unique digital item on the blockchain, a bit like a numbered receipt that only you own. In this contract the NFT is called a veMulti NFT, and it carries "voting power". Voting power is a number that says how much say you have in the system, usually based on how many tokens you locked and for how long.
The contract needs to be able to answer the question "what was this NFT's voting power at a particular moment in time?". To do that it keeps a running record, a list of snapshots called checkpoints, stored in a place named point_history. Each snapshot records things like a block number and a timestamp. A block number is the position of a block in the blockchain, roughly a counter of how many batches of transactions have been processed. A timestamp is the date and time. The functions that answer the "at a particular time" question have names ending in at*, for example a function that returns the voting power at a given moment.
Between snapshots the contract has to estimate, or extrapolate: it takes the last known point and projects it forward in time. Extrapolation is like guessing where a moving car will be in ten minutes based on where it is now and how fast it is going. If the starting point is wrong, the guess is wrong.
Feature two: merging NFTs
The contract also has a merge function. It lets a user combine two NFTs into one, the way you might combine two small gift cards into a single larger one. When that happens, one of the two NFTs has to be destroyed. Destroying a token in this way is called burning, and the internal function that does it is named _burn.
The contract also keeps a figure called the supply amount: the total number of tokens that exist. Burning something should reduce that total. The second bug is that it does not.
Setting up
The researcher worked directly with the source code of the staking contract. Source code is the human-readable text that a program is written in, before it is compiled and put on the blockchain. He ran tests from his own copy of the code on GitHub, a website where people store and share code. His repository is named grGred/Anyswap-staking. The main contract file is contracts/ve.sol, and a corrected version that prints extra diagnostic messages (console logs) is in contracts/veFixed.sol. A console log is a line of output a program prints so you can see what it is doing internally, like a shop till printing a receipt for every sale.
A test, in this context, is a small program that runs part of the contract and checks the result. Running tests is how you demonstrate a bug without touching real money.
Finding the first bug
The researcher's starting attitude was simple: an audit is not a guarantee. He read through the checkpoint logic and found the problem on line 826 of contracts/ve.sol. Line numbers are just positions in the file, like page numbers in a book.
The checkpoint function contains a for loop. A for loop is a way of telling a computer to repeat a set of instructions several times, like a recipe step that says "stir ten times". Before the loop starts, the code saves the latest checkpoint into a variable named initial_last_point:
// initial_last_point is used for extrapolation to calculate block number// (approximately, for *At methods) and save them// as we cannot figure that out exactly from inside the contractPoint memory initial_last_point = last_point;
Line by line, in plain words:
- The lines beginning with
//are comments. The computer ignores them; they are notes for humans. They explain thatinitial_last_pointis used to estimate block numbers for the*Atmethods, and that the contract cannot work those numbers out exactly from the inside. Point memory initial_last_point = last_point;is the actual instruction.Pointis the name of a small bundle of data (a struct) holding the fields of a snapshot.memoryis a keyword about where the data lives while the program runs.initial_last_pointis the new name being introduced.last_pointis the existing snapshot the contract already holds.
The crucial point is what this instruction really does. It does not make a photocopy of the last point. It creates a second name that points at the very same data, like two people holding the two ends of one rope rather than each holding their own rope. So if anything later changes initial_last_point, it also changes last_point. The researcher states this as a proof in his report, with a contract and a test.
The visible damage happens when the contract has 0 checkpoints in a week. In that case the checkpoint function writes several checkpoints into point_history that share the same block number but carry different timestamps. Since the block number is supposed to identify a moment, having several different times attached to one block number breaks the time extrapolation described earlier.
Why would a week pass with no checkpoints? Multichain runs several staking contracts on different chains. A chain here means a separate blockchain network. At the time the market was "bearish", meaning prices were falling and people were less active. The researcher judged it very likely that nobody would interact with one of the contracts for more than a week.
Exploitation
Step 1: Run the checkpoint test
The researcher points to a test named "Rewards after withdraw disappears for expired locks" in his GitHub repository. Running it shows several checkpoints being written with the same block number and different timestamps:

Step 2: Observe the effect on rewards
With the history points wrong, the amount of pending reward is wrong too. Pending reward means tokens earned but not yet collected. In some cases this leads to the loss of all unclaimed reward for a specific NFT, which is why the researcher rates this a critical bug. Critical is the most serious level in the usual severity scale.
People whose lock has expired cannot claim their rewards if there are any, and those rewards disappear. Worse, if a person with an expired lock does claim and withdraws their funds, all the other users with active NFTs lose a significant amount of pending rewards, up to 50%. So reward distribution works incorrectly and voting power is wrong as well.
Step 3: Merge two NFTs
For the second bug the researcher looks at the merge function, which lets a user merge two NFTs into one. The internal function _burn burns the NFT but does not decrease the supply amount. Because of that it is possible to increase the supply by the merged amount indefinitely, every time someone merges.
The test logs the supply amount before and after the merge. The supply amount increases and no longer equals the amount of tokens:

Because the supply amount is not used when rewards are calculated, the researcher rates this bug as medium, one step below critical.
Root cause
For the first bug, the root cause is the assignment Point memory initial_last_point = last_point;. In Solidity, the language these contracts are written in, memory does not copy a struct that already lives in storage. Storage is the contract's permanent data area on the blockchain; memory is temporary working space. The local variable ends up referencing the same data, so writing through initial_last_point mutates last_point. The for loop that follows then writes checkpoints into points_history with one block number and several timestamps, which breaks the time extrapolation used by the at* methods. The contract had earlier been audited by Blocksec and Peckshield.
For the second bug, the root cause is that _burn does not decrease the supply amount, so the merge path inflates supply by the merged amount each time.
Impact
For the first bug, the impact falls on reward accounting and voting power. Holders of expired locks can lose all unclaimed rewards, and a single claim and withdrawal by such a holder can cost other users with active NFTs up to 50% of their pending rewards. The condition is that the contract goes a week without checkpoints, which the researcher considers likely given several stakings on different chains and low activity.
For the second bug, the impact is limited to the supply figure, which the researcher says is not used for reward distribution, hence the medium rating.
Fix
For the first bug, the researcher recommends redeploying the contract with a real copy of the last point:
// Copy all the data of last pointPoint memory initial_last_point = Point({ bias: last_point.bias, slope: last_point.slope, ts: last_point.ts, blk: last_point.blk});
Line by line, in plain words:
- The comment says the aim is to copy all the data of the last point.
Point memory initial_last_point = Point({ ... });builds a brand newPointfrom scratch and fills in each field by hand, instead of pointing at the existing one.bias: last_point.biascopies the first field,bias, from the old point.slope: last_point.slopecopies the second field,slope.ts: last_point.tscopies the timestamp field.blk: last_point.blkcopies the block number field.
Because every field is copied into a fresh object, changing the new variable can no longer affect the original. It is the difference between photocopying a document and handing someone the original to scribble on.
The fixed contract with console logs is in contracts/veFixed.sol at L828-L833. An alternative is a backend that calls the checkpoint function every day, so the for loop is never reached and rewards are not broken. A backend is a program running on the operator's own servers, outside the blockchain, that performs routine tasks automatically. Multichain took this second route and now has a backend that calls checkpoint.
The report does not describe a fix for the merge supply bug.
The researcher closes by saying that no matter how many security audits you have, you must cover your code with unit tests properly, especially if the contract locks a large amount of tokens. Unit tests are small automated checks, one per behaviour, that run every time the code changes.
Variants to test
- Look for
Point memory x = last_point;style assignments in forked vote escrow contracts and check whether the local is later mutated. A positive result is a test that writes several entries topoints_historywith the same block number and different timestamps. - Check whether any contract in scope can go a week without a checkpoint call, for example low-activity stakings on secondary chains. A positive result is a checkpoint run after a quiet period that produces duplicate block numbers.
- Exercise the merge path and compare total supply before and after. A positive result is supply that grows by the merged amount while the token count stays the same.
- Review
_burnimplementations in similar NFT staking contracts for missing supply accounting. A positive result is any burn path that leaves the supply counter unchanged.
Glossary
- Audit: a professional review of code by a security firm, intended to find mistakes before they are exploited. Not a guarantee that none remain.
- Backend: a program running on the operator's own servers, outside the blockchain, that performs routine tasks automatically.
- Bearish: a market where prices are falling and people are less active.
- Block number: the position of a block in a blockchain, roughly a counter of how many batches of transactions have been processed.
- Blockchain: a shared, append-only record of transactions kept by many computers at once.
- Burn: to destroy a token permanently.
- Checkpoint: a saved snapshot of a value at a moment in time, used to answer questions about the past.
- Chain: a separate blockchain network.
- Console log: a line of output a program prints so you can see what it is doing internally.
- Contract (smart contract): a program that lives on a blockchain and runs automatically.
- Critical: the most serious level in the usual severity scale.
- Extrapolate: to estimate a future or in-between value from known points, like guessing where a moving car will be.
- For loop: an instruction to repeat a set of steps several times.
- Fork: a copy of an existing codebase that is then developed separately.
- GitHub: a website where people store and share code.
- Medium: a middle level in the usual severity scale, below critical.
- Memory: temporary working space in a program, as opposed to permanent storage.
- Merge: combining two NFTs into one.
- NFT (non-fungible token): a unique digital item on a blockchain, like a numbered receipt that only you own.
- Pending reward: tokens earned but not yet collected.
- Pointer / reference: a second name that points at the same data rather than a copy of it.
- Redeploy: publish a new version of a contract to the blockchain.
- Repository: a stored collection of code and its history.
- Solidity: the programming language these contracts are written in.
- Source code: the human-readable text a program is written in.
- Staking: locking up tokens in a contract, usually to earn rewards.
- Storage: a contract's permanent data area on the blockchain.
- Struct: a small bundle of named fields grouped together as one value.
- Supply amount: the total number of tokens that exist.
- Test: a small program that runs part of the code and checks the result.
- Timestamp: the date and time attached to an event.
- Unit test: a small automated check, one per behaviour, run every time the code changes.
- Variable: a named place in a program that holds a value.
- veMulti NFT: the NFT this contract issues to represent a locked position and its voting power.
- Voting power: a number saying how much say a holder has in the system.
- Whitehat hacker: someone who finds weaknesses and reports them to the owner instead of abusing them.