You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Solana allows programs to inspect other instructions in the transaction using the [Instructions sysvar](https://docs.solanalabs.com/implemented-proposals/instruction_introspection). The programs requiring instruction introspection divide an operation into two or more instructions. The program have to ensure that all the instructions related to an operation are correlated. The program could access the instructions using absolute indexes or relative indexes. Using relative indexes ensures that the instructions are implicitly correlated. The programs using absolute indexes might become vulnerable to exploits if additional validations to ensure the correlation between instructions are not performed.
4
+
5
+
## Exploit Scenario
6
+
7
+
A program mints tokens based on the amount of tokens transferred to it. A program checks that `Token::transfer` instruction is called in the first instruction of the transaction. The program uses absolute index `0` to access the instruction data, program id and validates them. If the first instruction is a `Token::transfer` then program mints some tokens.
The program uses absolute index to access the transfer instruction. An attacker can create transaction containing multiple calls to `mint` and single transfer instruction.
31
+
32
+
0.`transfer()`
33
+
1.`mint(, ...)`
34
+
2.`mint(, ...)`
35
+
3.`mint(, ...)`
36
+
4.`mint(, ...)`
37
+
5.`mint(, ...)`
38
+
39
+
All the `mint` instructions verify the same transfer instruction. The attacker gets 4 times more than the intended tokens.
40
+
41
+
## Mitigation
42
+
43
+
Use a relative index, for example `-1`, and ensure the instruction at that offset is the `transfer` instruction.
0 commit comments