前言:找Ver👴想复现下qwb final的区块链。Ver👴给我发了这个比赛下面的一道题,发现这个比赛里面有很多高质量的智能合约题。从这里开始写一些不错的题目。
babysandbox
看到题目名字就知道了题目考点: 沙盒
给出合约
BabySandbox.sol
pragma solidity 0.7.0;
contract BabySandbox {
function run(address code) external payable {
assembly {
// if we're calling ourselves, perform the privileged delegatecall
if eq(caller(), address()) {
switch delegatecall(gas(), code, 0x00, 0x00, 0x00, 0x00)
case 0 {
returndatacopy(0x00, 0x00, returndatasize())
revert(0x00, returndatasize())
}
case 1 {
returndatacopy(0x00, 0x00, returndatasize())
return(0x00, returndatasize())
}
}
// ensure enough gas
if lt(gas(), 0xf000) {
revert(0x00, 0x00)
}
// load calldata
calldatacopy(0x00, 0x00, calldatasize())
// run using staticcall
// if this fails, then the code is malicious because i

本文介绍了在CTF比赛中遇到的一道关于智能合约安全的题目——babysandbox,主要考察沙盒机制的理解。通过分析合约代码,作者发现可以通过特定的调用顺序,利用delegatecall和staticcall在不同阶段执行不同的操作,最终实现合约的自毁。文章详细解释了绕过沙盒限制的思路,包括尝试利用全局变量、交易特征和外部合约调用来改变调用状态,最终成功破坏合约。这是一个学习智能合约安全和opcode的好例子。
最低0.47元/天 解锁文章
1040

被折叠的 条评论
为什么被折叠?



