Use of Solidity version 0.8.13 which has two known issues applicable to PuttyV2
The smart contract project PuttyV2 used Solidity version 0.8.13, which contains two known compiler bugs: one in ABI encoding and one in the optimiser's handling of inline assembly. An attacker could potentially exploit these bugs to cause incorrect behaviour in the contract, though the report does not demonstrate a concrete exploit.
Submitted by hubble, also found by horsefacts
The solidity version 0.8.13 has below two issues applicable to PuttyV2
-
Vulnerability related to ABI-encoding.
ref : https://blog.soliditylang.org/2022/05/18/solidity-0.8.14-release-announcement/ This vulnerability can be misused since the function hashOrder() and hashOppositeOrder() has applicable conditions. “…pass a nested array directly to another external function call or use abi.encode on it.”
-
Vulnerability related to ‘Optimizer Bug Regarding Memory Side Effects of Inline Assembly’
ref : https://blog.soliditylang.org/2022/06/15/solidity-0.8.15-release-announcement/ PuttyV2 inherits solidity contracts from openzeppelin and solmate, and both these uses inline assembly, and optimization is enabled while compiling.
Recommended Mitigation Steps
Use recent Solidity version 0.8.15 which has the fix for these issues.
outdoteth (Putty Finance) confirmed and commented:
Great catch.
Report: Use of Solidity 0.8.13 with known issues in ABI encoding and memory side effects.
outdoteth (Putty Finance) resolved:
PR with fix: https://github.com/outdoteth/putty-v2/pull/6.
hyh (warden) reviewed mitigation:
Fixed by bumping the solidity version.
Context
Putty is a peer-to-peer options protocol, and PuttyV2 is the contract set at the centre of this report. The finding is not a logic flaw in the option flow itself: it is a compiler-version issue. PuttyV2 was compiled with Solidity 0.8.13, and that release is affected by two known bugs that the Solidity team documented and fixed in later versions. The researcher, hubble, argued that both bugs are applicable to PuttyV2, with horsefacts independently reaching the same conclusion.
The two issues are:
- A vulnerability related to ABI-encoding, fixed in Solidity 0.8.14.
- A vulnerability related to the optimizer and memory side effects of inline assembly, fixed in Solidity 0.8.15.
The report links the official Solidity release announcements as references for both.
Setup
The relevant precondition is simply the compiler version used to build PuttyV2: Solidity 0.8.13. For the second issue there is an additional precondition, because the optimizer bug only matters when optimisation is enabled during compilation. The report states that optimisation is enabled while compiling PuttyV2, so that condition is met.
No accounts, roles, tooling or deployed endpoints are described in the report. The analysis is about the source and its build configuration.
Finding it
The researcher checked which known Solidity issues apply to the version in use. Two of the fixed issues were judged applicable to PuttyV2.
Issue 1: ABI-encoding
The first issue is the ABI-encoding vulnerability fixed in 0.8.14. The report quotes the condition from the Solidity announcement under which it can be triggered:
“…pass a nested array directly to another external function call or use abi.encode on it.”
The researcher notes that this vulnerability can be misused since hashOrder() and hashOppositeOrder() have applicable conditions.
Issue 2: optimizer and inline assembly
The second issue is the optimizer bug regarding memory side effects of inline assembly, fixed in 0.8.15. PuttyV2 inherits Solidity contracts from OpenZeppelin and Solmate, and both of those libraries use inline assembly. Combined with optimisation being enabled at compile time, the conditions for this bug are present in the build.
Exploitation
The report does not include a proof-of-concept transaction, payload or reproduction steps. It is an analysis of compiler-version applicability: the argument is that the two documented compiler bugs have reachable conditions in PuttyV2 (the two hash functions for the ABI-encoding issue, and the inherited OpenZeppelin and Solmate assembly code under optimisation for the second), not a demonstrated end-to-end exploit. The report therefore does not show what an attacker would send or what would come back.
Root cause
The root cause is the choice of compiler version. Solidity 0.8.13 predates the fixes for both bugs, so any code compiled with it carries the risk wherever the triggering conditions are met. In PuttyV2 those conditions are met in two places:
- The ABI-encoding bug is relevant because
hashOrder()andhashOppositeOrder()have applicable conditions, per the researcher's reading of the Solidity advisory. - The optimizer bug is relevant because the inherited OpenZeppelin and Solmate contracts use inline assembly and optimisation is enabled during compilation.
Existing defences did not help here: the issue is in the compiler and in the build configuration, not in application logic that a contract-level check could catch.
Impact
It does not quantify the impact, describe a concrete attack path, or state which assets or users could be affected. What it establishes is that two known compiler bugs are applicable to PuttyV2 given its code and build settings, and the Putty Finance team confirmed the finding..
Fix
Use a recent Solidity version, 0.8.15, which contains the fixes for both issues. That is the mitigation the researcher recommended.
The Putty Finance team confirmed the finding (outdoteth: "Great catch.") and resolved it with a pull request. The warden hyh reviewed the mitigation and noted that it was fixed by bumping the Solidity version.
Variants to test
- Check the pragma and the actual compiler version used in the build for every contract in scope, not just the top-level one. A positive result is a version below the fix for a bug whose triggering conditions exist in the code.
- Look for functions that pass nested arrays to external calls or use
abi.encodeon them, and check whether the compiler version predates the 0.8.14 ABI-encoding fix. A positive result is such a function compiled with an affected version. - Look for inherited library code that uses inline assembly (OpenZeppelin and Solmate are named in the report) combined with optimisation enabled, and check whether the compiler version predates the 0.8.15 optimizer fix. A positive result is that combination in the build configuration.
- Cross-check the compiler version against the Solidity release announcements for every known bug, and map each one to the conditions present in the target's code.
Hunting notes
This kind of bug hides in build configuration rather than in application logic: the pragma line, the compiler version pinned in the build tooling, and whether the optimizer is enabled. During recon, the signals are a pinned older compiler version and dependencies that use inline assembly. The researcher showed applicability by tying each known compiler bug to conditions in the code: the two hash functions for the ABI-encoding issue, and the inherited assembly code plus optimisation for the other.
What happened, in plain words
Putty is a service that lets two people agree on a financial deal with each other, without a middleman. The deal is written as a small computer program, called a smart contract, that runs on a blockchain. PuttyV2 is the collection of these programs that this report is about.
A smart contract is not written in the language a normal computer uses. It is written in a language called Solidity, and then a program called a compiler translates it into the form the blockchain can actually run. Think of the compiler as a translator: you hand it your text, and it hands back a version the machine understands. If the translator has a known mistake, every text it translates can carry that mistake, even if your own text is perfect.
That is exactly what this report is about. PuttyV2 was translated with version 0.8.13 of the Solidity compiler. Two known mistakes in the Solidity compiler affect version 0.8.13. Both were fixed in later versions. The researcher, hubble, reported that both mistakes are applicable to PuttyV2. Another researcher, horsefacts, reached the same conclusion independently.
The two compiler mistakes are:
- A problem with how the compiler packs data when one part of a program calls another, fixed in Solidity 0.8.14.
- A problem with the optimiser, a part of the compiler that makes the finished program faster and smaller, fixed in Solidity 0.8.15.
The report links the official Solidity announcements for both, which are the public write-ups the Solidity team publishes whenever they release a new version.
This is not a bug in the business logic of Putty. Nobody wrote a wrong calculation. The risk comes from the tool used to build the code, which is why the fix is simply to build it again with a newer tool.
The starting conditions
The first thing that has to be true for this report to matter is the compiler version: PuttyV2 was built with Solidity 0.8.13. That single fact opens the door to both known bugs, because both were still present in that release.
The second bug needs one more condition. The optimiser is an optional part of the compiler: you can switch it on or off when you build. The optimiser bug only matters if the optimiser was switched on. The report states that optimisation is enabled while compiling PuttyV2, so that condition is met too.
The report does not describe any user accounts, special roles, tools or live servers. The whole analysis is about the source code and the settings used to build it. In everyday terms: nobody had to log in anywhere or send a request to anything; the researcher read the recipe and the oven settings, not the cake.
How the researcher found it
Two of the fixed issues passed that test for PuttyV2. The sections below take them one at a time.
Issue 1: the data-packing problem
The first issue is the one about how data is packed when it is handed from one function to another. This packing format has a name, ABI encoding. When one part of a program calls another, the arguments have to be laid out in a standard shape so both sides agree on what is where. Think of it as packing a parcel to a fixed postal standard: the receiver expects the label in a certain corner, and if the sender puts it somewhere else, the contents get misread.
The Solidity team described the exact situation in which the bug can bite. The report quotes that description:
“…pass a nested array directly to another external function call or use abi.encode on it.”
Line by line, in plain words:
pass a nested array directly to another external function call: a nested array is a list inside a list, like a shopping list where one item is itself a list of ingredients. An external function call is one contract asking another contract to do something. The bug appears when such a list-inside-a-list is handed straight over in that call.or use abi.encode on it:abi.encodeis the built-in instruction that performs the packing described above. The bug also appears when that instruction is used on a nested array.
The researcher then points at two functions in PuttyV2, hashOrder() and hashOppositeOrder(), and says they have applicable conditions. In plain terms: the researcher says those two functions have applicable conditions for the bug. A function is a named block of code that does one job; .
Issue 2: the optimiser and inline assembly
The second issue is about the optimiser. When you switch the optimiser on, the compiler rewrites your program to make it cheaper and faster to run, while trying to keep the behaviour identical. It is like an editor tightening your sentences without changing what they mean. Occasionally the editor tightens a sentence so much that the meaning shifts, and that is what this bug is.
The specific area is inline assembly. Most of Solidity is high-level and readable, but a programmer can drop down to raw machine-level instructions inside a Solidity file; that block is called inline assembly. It is powerful and fast, and it is also where the compiler has the least room to reason safely about what the code does. The bug concerns memory side effects of inline assembly: the optimiser could misjudge what such a block does to the computer's working memory and reorder or remove things incorrectly.
Why does this apply to PuttyV2? Because PuttyV2 inherits code from two widely used libraries, OpenZeppelin and Solmate. Inheriting means building on top of someone else's ready-made code rather than writing everything yourself, the way a house can be built on a standard foundation. Both of those libraries use inline assembly. And the report states that optimisation is enabled while compiling. So the ingredients of the bug are all present: assembly code from the libraries, plus the optimiser switched on.
What an attacker could actually do
The report does not include a proof of concept. There is no example transaction, no payload, no set of steps to reproduce, and no description of what an attacker would send or what would come back. It is an analysis of whether the two documented compiler bugs can be reached in PuttyV2, not a demonstration of an end-to-end attack.
That distinction matters for a beginner. A finding like this says: the faulty tool was used, and the code contains the patterns the fault reacts to. It does not say: here is a working exploit. The argument rests on reachability, meaning the triggering conditions exist in the code, in two places:
- The data-packing bug is reachable because
hashOrder()andhashOppositeOrder()contain the pattern described in the Solidity announcement. - The optimiser bug is reachable because the inherited OpenZeppelin and Solmate code uses inline assembly and the optimiser was on during the build.
The root cause
The root cause is the choice of compiler version. Solidity 0.8.13 was released before either fix, so any code built with it carries the risk wherever the triggering conditions are met. In PuttyV2 those conditions are met in the two places above.
It is worth being clear about why the usual defences did not help. Smart contracts often contain checks written by their authors: only this person may call that function, this number must be positive, and so on. Those checks live in the application logic. This problem lives one level below, in the tool that turns the logic into runnable code. A check written in Solidity cannot catch a mistake made by the thing translating Solidity. It is like proofreading a letter carefully while the photocopier adds a smudge to every copy.
Impact
It does not put a number on the impact, does not lay out a concrete attack path, and does not say which assets or which users could be affected. What it establishes is that two known compiler bugs are applicable to PuttyV2 given its code and its build settings, and the Putty Finance team confirmed the finding..
The fix
The recommended mitigation is to use a recent Solidity version, 0.8.15, which contains the fixes for both issues.
The Putty Finance team confirmed the finding. outdoteth replied "Great catch." and later resolved it with a pull request. The warden hyh reviewed the mitigation and noted that it was fixed by bumping the Solidity version.
Variants to test
If you want to look for the same class of problem in other projects, these are the checks the report's reasoning suggests:
- Check the pragma and the actual compiler version used in the build for every contract in scope, not just the top-level one. The pragma is the line at the top of a Solidity file that states which compiler versions are acceptable. A positive result is a version below the fix for a bug whose triggering conditions exist in the code.
- Look for functions that pass nested arrays to external calls or use
abi.encodeon them, and check whether the compiler version predates the 0.8.14 data-packing fix. A positive result is such a function compiled with an affected version. - Look for inherited library code that uses inline assembly, with OpenZeppelin and Solmate named in the report, combined with optimisation enabled, and check whether the compiler version predates the 0.8.15 optimiser fix. A positive result is that combination in the build configuration.
- Cross-check the compiler version against the Solidity release announcements for every known bug, and map each one to the conditions present in the target's code.
Hunting notes
This kind of bug hides in build configuration rather than in application logic. The places to look are the pragma line, the compiler version pinned in the build tooling, and whether the optimiser is enabled. During recon, the early signals are a pinned older compiler version and dependencies that use inline assembly. The researcher made the case by tying each known compiler bug to specific conditions in the code: the two hash functions for the data-packing issue, and the inherited assembly code plus optimisation for the other. The researcher tied each known compiler bug to conditions in the code: the two hash functions for the data-packing issue, and the inherited assembly code plus optimisation for the other.
Glossary
- Smart contract: a small program stored and run on a blockchain, which carries out an agreement automatically.
- Solidity: the programming language used to write smart contracts.
- Compiler: the program that translates source code into the form the machine runs; a faulty compiler can affect every program it builds.
- Compiler version: the specific release of the compiler used for a build, such as 0.8.13.
- Pragma: the line at the top of a Solidity file declaring which compiler versions are acceptable.
- Optimiser: an optional compiler stage that rewrites code to be smaller and faster while trying to keep behaviour the same.
- Inline assembly: raw low-level instructions written inside a Solidity file, giving speed and control at the cost of safety checks.
- Memory side effects: changes a piece of code makes to the computer's working memory, which the optimiser must account for correctly.
- ABI encoding: the standard way arguments are packed when one function or contract calls another.
- Nested array: a list that contains other lists as items.
- External function call: one contract asking another contract to run a function.
abi.encode: the Solidity instruction that performs ABI encoding on given values.- Function: a named block of code that performs one job.
- Hash: a fixed-length fingerprint computed from data, used to identify it compactly.
- OpenZeppelin and Solmate: widely used libraries of ready-made Solidity code that projects build on.
- Inheritance: building your contract on top of existing code rather than writing everything from scratch.
- Proof of concept: a working demonstration that a vulnerability can actually be triggered.
- Payload: the data an attacker sends to try to trigger a vulnerability.
- Reachability: whether the conditions that trigger a bug actually exist in the target code.
- Root cause: the underlying reason a vulnerability exists.
- Mitigation: the change that removes or reduces a vulnerability.
- Severity: the rating given to a finding to express how serious it is; this one is medium.
- Warden: in a code competition, the reviewer who checks findings and mitigations.
- Bumping a version: raising a dependency or tool to a newer release.