728x90
Description
The creator of this contract was careful enough to protect the sensitive areas of its storage.
Unlock this contract to beat the level.
Things that might help:
- Understanding how storage works
- Understanding how parameter parsing works
- Understanding how casting works
Tips:
- Remember that metamask is just a commodity. Use another tool if it is presenting problems. Advanced gameplay could involve using remix, or your own web3 provider.
Code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Privacy {
bool public locked = true;
uint256 public ID = block.timestamp;
uint8 private flattening = 10;
uint8 private denomination = 255;
uint16 private awkwardness = uint16(block.timestamp);
bytes32[3] private data;
constructor(bytes32[3] memory _data) {
data = _data;
}
function unlock(bytes16 _key) public {
require(_key == bytes16(data[2]));
locked = false;
}
/*
A bunch of super advanced solidity algorithms...
,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`
.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,
*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^ ,---/V\
`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*. ~|__(o.o)
^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*' UU UU
*/
}
Scenario
data[2]의 앞 16바이트가 key이다. 컨트랙트의 주소와 슬롯 인덱스 또는 슬롯 주소만 알면 해당 슬롯의 값을 알 수 있다. 솔리디티에서 슬롯의 인덱스는 선언된 순서대로 위치한다. 단, 256비트 이하인 경우에는 스토리지 공간을 절약하기 위해 한 슬롯에 여러 변수 값이 들어갈 수 있다.
locked는 slot[0], ID는 slot[1], flattening, denomination, awkwardness는 slot[2], data[0]는 slot[3], data[1]는 slot[4], data[2]는 slot[5]에 있다.
Exploit
728x90