-
Notifications
You must be signed in to change notification settings - Fork 3
Added 5 delegate call vulnerability type smart contracts #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
contract multiowned { | ||
|
||
function Deposit(address sender, uint value) { | ||
if (sender != 0) { | ||
sender.delegatecall(value); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
contract Safe { | ||
|
||
function requireStackDepth(address addr, bytes32 data) { | ||
if (data=='') { throw; } | ||
if (!addr.delegatecall(data)){ throw; } | ||
} | ||
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Apply within this hunk: - function requireStackDepth(address addr, bytes32 data) {
- if (data=='') { throw; }
- if (!addr.delegatecall(data)){ throw; }
- }
+ function requireStackDepth(address addr, bytes calldata data) external {
+ require(data.length != 0, "empty data");
+ (bool ok, ) = addr.delegatecall(data);
+ require(ok, "delegatecall failed");
+ } Add at file top (outside this hunk): // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25; |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
contract StackDepth { | ||
|
||
function dig(uint n) public { | ||
if (!address(this).delegatecall(0x21835af6, n - 1)) throw; | ||
} | ||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Legacy throw/delegatecall + missing base case cause compile errors and potential unbounded recursion Modern compilers reject Apply within this hunk: - function dig(uint n) public {
- if (!address(this).delegatecall(0x21835af6, n - 1)) throw;
- }
+ function dig(uint256 n) public {
+ require(n > 0, "n underflow");
+ (bool ok, ) = address(this).delegatecall(
+ abi.encodeWithSelector(this.dig.selector, n - 1)
+ );
+ require(ok, "delegatecall failed");
+ } Add at file top (outside this hunk): // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25; 🤖 Prompt for AI Agents
|
||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,9 @@ | ||||||||||||||||||||||||
contract UpgradeabilityProxy { | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
function withdraw(address _logic, bytes memory _data) public payable { | ||||||||||||||||||||||||
if(_data.length > 0) { | ||||||||||||||||||||||||
bool success = _logic.delegatecall(_data); | ||||||||||||||||||||||||
require(success); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unguarded arbitrary delegatecall is a critical footgun Anyone can execute arbitrary logic in this contract’s context (storage/balance). If this isn’t intentionally vulnerable test code, restrict caller (e.g., onlyOwner) and/or whitelist 🤖 Prompt for AI Agents
Tuple return from On modern Solidity, Apply within this hunk: function withdraw(address _logic, bytes memory _data) public payable {
if(_data.length > 0) {
- bool success = _logic.delegatecall(_data);
- require(success);
+ require(_logic != address(0), "logic=0");
+ (bool success, bytes memory /*ret*/ ) = _logic.delegatecall(_data);
+ require(success, "delegatecall failed");
}
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
contract IERC20 { | ||
|
||
function sellRewardForWeth(address victim, uint256 rewardAmount, address to) external returns(uint256) { | ||
victim.delegatecall(abi.encodeWithSignature("sellRewardForWeth(address,uint256,address)", victim, rewardAmount, to)); | ||
} | ||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declared return value not returned; This fails to compile and swallows failures. Return or remove the return type. Apply within this hunk: - function sellRewardForWeth(address victim, uint256 rewardAmount, address to) external returns(uint256) {
- victim.delegatecall(abi.encodeWithSignature("sellRewardForWeth(address,uint256,address)", victim, rewardAmount, to));
- }
+ function sellRewardForWeth(address victim, uint256 rewardAmount, address to) external returns (uint256) {
+ (bool ok, bytes memory ret) =
+ victim.delegatecall(abi.encodeWithSignature(
+ "sellRewardForWeth(address,uint256,address)", victim, rewardAmount, to));
+ require(ok, "delegatecall failed");
+ if (ret.length >= 32) {
+ return abi.decode(ret, (uint256));
+ }
+ return 0;
+ } Add at file top (outside this hunk): // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25; 🤖 Prompt for AI Agents
|
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
delegatecall(value)
is invalid calldata; missing visibility; zero-address check uses0
This won’t compile on modern Solidity and the calldata is not bytes. Fix to explicit bytes, visibility, and checks.
Apply within this hunk:
Add at file top (outside this hunk):
If you must keep
uint value
for the dataset semantics, minimally wrap it:(bool ok,) = sender.delegatecall(abi.encode(value)); require(ok);
.🏁 Script executed:
Length of output: 6179
Fix delegatecall usage, add visibility, and add SPDX/pragma
audit_engine/smart_contracts/delegate_call/dc41.sol (lines 3–7): won't compile on modern Solidity and is unsafe — apply the patch below.
Add at file top (outside this hunk):
If you must keep
uint value
for dataset semantics, minimally wrap it:(bool ok, ) = sender.delegatecall(abi.encode(value)); require(ok);
.🤖 Prompt for AI Agents