✅Shop
view functions
Description
Сan you get the item from the shop for less than the price asked?
Things that might help:
Shop
expects to be used from aBuyer
Understanding restrictions of view functions
Code Audit
This challenge is similar to "Elevator", but with a little tweak. In "Elevator", we distinguish 1st and 2nd call by defining a counter
state variable. In this challenge, we are in a restricted environment (like a sandbox) because price()
is defined as a view function. In short, we can only read but not write on state variables.
This is not a problem. Note that the isSold
state variable flips from false
to true
, and it is just like the counter
we defined in "Elevator". Since isSold
is public, we can read its content through the getter isSold()
that is automatically generated by the Solidity compiler.
Solution
Deploy the exploit contract and feed in the address of the target contract:
Call the buy
function.
Summary
Contracts can manipulate data seen by other contracts in any way they want.
It's unsafe to change the state based on external and untrusted contracts logic.
Last updated