Skip to content

Latest commit

 

History

History
21 lines (13 loc) · 1.61 KB

SWC-112.md

File metadata and controls

21 lines (13 loc) · 1.61 KB

Title

Delegatecall to Untrusted Callee

Relationships

CWE-829: Inclusion of Functionality from Untrusted Control Sphere

Description

There exists a special variant of a message call, named delegatecall which is identical to a message call apart from the fact that the code at the target address is executed in the context of the calling contract and msg.sender and msg.value do not change their values. This allows a smart contract to dynamically load code from a different address at runtime. Storage, current address and balance still refer to the calling contract.

Calling into untrusted contracts is very dangerous, as the code at the target address can change any storage values of the caller and has full control over the caller's balance.

Remediation

Use delegatecall with caution and make sure to never call into untrusted contracts. If the target address is derived from user input ensure to check it against a whitelist of trusted contracts.

References