πΏisContract Manipulation
The concept
There are two types of accounts in the Ethereum world.
EOA Externally Owned Accounts, these are users of wallets
Contracts, these are deployed smart contracts,
Sometimes there is a requirement to check if the caller is a EOA or a Contract. The code for this in solidity is to use inline assembly as below.
The code checks if the address at who_is_calling
has code associated with it.
There is a way to make a malicious contract seem as though there is no code associated with it, and that is by calling the vulnerable contract and function from within the malicious contract's constructor. Below is a vulnerable contract and a test contract to test this concept. We will be using anvil from the Foundry suite to deploy from Remix.
In the testCodeSize
there is a variable called allTheirValue
, this will hold the value that is retrieved from the Vulnerable contract, if the call is able to bypass the check for code size we should see the allTheirValue
variable holding a very large value, however if it fails the value should be "0". In the testCodeSize
contract, the call to VulnerableContract.notcontracts()
is made from within the constructor and an external function called wontWork()
.
Below are screenshots of the value held by allTheirValue
after deployment and then after calling the wontWork()
function.
Last updated