Level 4 - Telephone ⏺
Level Setup
Generating random numbers in solidity can be tricky. There currently isn't a native way to generate them, and everything you use in smart contracts is publicly visible, including the local variables and state variables marked as private. Miners also have control over things like blockhashes, timestamps, and whether to include certain transactions - which allows them to bias these values in their favor.
To get cryptographically proven random numbers, you can use Chainlink VRF, which uses an oracle, the LINK token, and an on-chain contract to verify that the number is truly random.
Some other options include using Bitcoin block headers (verified through BTC Relay), RANDAO, or Oraclize).
Level Contract
Exploit
The contract is vulnerable because the msg.sender
is the address that sent the transaction to interact with the contract, but this is only the final address if the transaction involved multiple contracts.
Create a middleman contract so that
x.origin != msg.sender
.
Submit instance... 🥳
Completion Message
While this example may be simple, confusing tx.origin
with msg.sender
can lead to phishing-style attacks, such as this.
An example of a possible attack is outlined below.
Use
tx.origin
to determine whose tokens to transfer, e.g.
Attacker gets victim to send funds to a malicious contract that calls the transfer function of the token contract, e.g.
In this scenario,
tx.origin
will be the victim's address (whilemsg.sender
will be the malicious contract's address), resulting in the funds being transferred from the victim to the attacker.
Notes
In a simple call chain
A->B->C->D
insideD
msg.sender
will beC
andtx.origin
will beA
.
Last updated