The Basics
Posted on Wed 07 August 2024 in ctf
This is a writeup of the blockchain challenge The Basics in the n00bz CTF 2024.
The attached file evm.txt
contained the following hash:
5f346113370265fdc29ff358a314601257ff00
Using https://evmd.xyz/ we are able to decompile the bytecode which results in the following results:
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
/// @title Decompiled Contract
/// @author Jonathan Becker <jonathan@jbecker.dev>
/// @custom:version heimdall-rs v0.8.3
///
/// @notice This contract was decompiled using the heimdall-rs decompiler.
/// It was generated directly by tracing the EVM opcodes from this contract.
/// As a result, it may not compile or even be valid solidity code.
/// Despite this, it should be obvious what each function does. Overall
/// logic should have been preserved throughout decompiling.
///
/// @custom:github You can find the open-source decompiler here:
/// https://heimdall.rs
contract DecompiledContract {
fallback() external payable {
if (0xfdc29ff358a3 == (0x1337 * msg.value)) {
selfdestruct(0);
}
}
}
To retriev the flag we need to resolve the if clause for msg.value
e.g. with JavaScript:
// 0xfdc29ff358a3 == (0x1337 * msg.value)
flag = '0x' + (0xfdc29ff358a3 / 0x1337).toString(16);
console.log('n00bz{' + flag + '}');
This gives us the flag: n00bz{0xd34db33f5}