Recently, using X-Ray we identified a vulnerability in an on-chain Solana smart contract (jet-v1) and have been awarded a bug bounty through Immunefi. We thank the Jet Protocol team and Immunefi for their quick responses and generous support. The fix has been applied in this commit.
This article shares our bug hunting experience with X-Ray.
X-Ray is an automated verification tool powered by the GreenCore technology. It scans the contract source code and looks for common pitfalls such as missing ownership check, missing signer check, Solana account confusions, arbitrary signed program invocation, and integer overflow/underflows.
X-Ray is currently under active development and checkers for more vulnerabilities are being added. More details and a tutorial could be found in [X-Ray — A vulnerability scanner for Solana smart contracts].
X-Ray is integrated with the contract build process. Getting a list of potential defects is as simple as one command line.
Suppose we have already obtained a fresh copy of a contract. We just need to invoke X-Ray . or x-ray -analyzeAll . in the Solana program’s directory where the build configuration file Xargo.toml exists.
The analysis is pretty fast and X-Ray will report a list of issues, which we may want to take a closer look at. In our scenario, among the four issues reported by X-Ray, the following two are particularly interesting.
In the above, X-Ray reports the issue types, issue locations, and the stack traces demonstrating how the issues may happen. The next step is to review the code and figure out if those issues can lead to security exploits.
The types of collaterals and loans are both usize . If there are too many loans in the list, the indicated add operation can overflow. So, this is a true positive in theory. However, the exploit depends on the state instead of user input. Since it's not (directly) user-controllable, it's not an ideal candidate for exploit PoC (Proof of Concept) creation.
In borrow.rs, the computation of the total token amount Y for a borrow request of amount X can overflow. The possible consequences of this overflow are
In particular:
Finding the appropriate inputs and satisfying all sanity checks in the contract are the main challenges for the PoC creation. In our scenario, we have to prepare appropriate deposit and collateral amounts to make the smart contract happy. After a few attempts, we found the magic numbers, and the following screenshot demonstrates the overflow and the loss of the holdings in the reserve total_deposits.
We reported our findings together with a PoC to the developers. The developers acknowledged our findings with a reward and commented
“…although this is not exploitable in our program as deployed, and in general requires an improbable concentration of token supply in Jet’s reserves, it is a problem in principle, that we will patch, and review the rest of the codebase for other instances of.
We genuinely appreciate the time spent analyzing our code.”
The issue has been patched shortly after the report.
For all blogs by X-Ray, Please visit https://www.sec3.dev/blog