https://github.com/Cyfrin/2024-07-biconomy/blob/main/contracts/Nexus.sol#L222
Using delegatecall
can potentially introduce vulnerabilities if not used carefully, particularly when dealing with arbitrary inputs or untrusted contracts.
delegatecall
allows a contract to execute code from another contract, maintaining the caller's context (storage, balance, etc.). If the called contract is untrusted or malicious, it can execute arbitrary code within the context of the caller.
I have created a POC for explaining vulnerability with delegatecall. I have considered two contracts: Caller
and Malicious
for POC. The Caller
contract uses delegatecall
to invoke a function in Malicious
. The Malicious
contract is designed to perform a re-entrancy attack to drain funds from Caller
.
This can lead to unauthorized modifications of state variables, including sensitive data or funds. Malicious contracts can exploit this to steal assets, manipulate contract behavior, or escalate privileges.
Manual Review
Avoid using delegatecall
with inputs derived from external or untrusted sources, especially if those inputs can control the contract's behavior or state.
Prefer call
with explicit gas and value limitations (transfer()
or send()
) instead of delegatecall
for sending Ether or invoking functions on other contracts. This restricts the potential for re-entrancy attacks.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.