140 votes
Accepted

Difference between CALL, CALLCODE and DELEGATECALL

DELEGATECALL basically says that I'm a contract and I'm allowing (delegating) you to do whatever you want to my storage. DELEGATECALL is a security risk for the sending contract which needs to trust ...
eth's user avatar
  • 85.7k
27 votes
Accepted

How does the delegatecall method work to call to another contract's method?

Here is a snippet of D using delegatecall on E from Difference between CALL, CALLCODE and DELEGATECALL contract D { uint public n; address public sender; function delegatecallSetN(address _e, ...
eth's user avatar
  • 85.7k
12 votes
Accepted

delegatecall and function return values

delegatecall is not supposed to handle return values as it cannot be aware of the length of the other side (unless there would be a dedicated parameter passed to it). Currently, the delegatecall ...
axic's user avatar
  • 2,569
12 votes

What is the difference between the STATICCALL and CALL EVM opcodes?

Additionally, Since byzantium staticcall can be used as well. This is basically the same as call, but will revert if the called function modifies the state in any way.
Smye's user avatar
  • 491
10 votes
Accepted

Delegatecall return values solidity 5.0

You can use abi.decode(...): abi.decode(bytes memory encodedData, (...)) returns (...): ABI-decodes the given data, while the types are given in parentheses as second argument. Example: (...
alberto's user avatar
  • 3,343
9 votes
Accepted

Double delegate call doesn't work

When, in C, you do b.delegatecall(, what happens is that: the code used is that of B the storage used is that of C And B and C have the same storage layout: both the uint value are located on ...
Xavier Leprêtre B9lab's user avatar
9 votes
Accepted

What is the value of "address(this)" when delegate calling?

Remember how DELEGATECALL works: DELEGATECALL basically says that I'm a contract and I'm allowing (delegating) you to do whatever you want to my storage. DELEGATECALL is a security risk for the ...
Paul Razvan Berg's user avatar
8 votes
Accepted

Can I use delegatecall in a transaction?

DELEGATECALL is an instruction interpreted by EVM. So to execute DELEGATECALL you have to have a program (contract) that gets executed on EVM. DELEGATECALL takes six operands, one of them is the ...
Michał Kłeczek's user avatar
8 votes

Difference between CALL, CALLCODE and DELEGATECALL

Showing the difference between the call, callcode and the delegatecall we can consider the example of the following code : Contracts can interact in three ways Call : By directly calling from a ...
CryptoScroller's user avatar
7 votes

Difference between CALL, CALLCODE and DELEGATECALL

An update to @eth's example for solidity v6: function definitions must be public keccak256 in place of sha3 call arguments use abi.encode() address() to get contract address pragma solidity ^0.6.0;...
Lee's user avatar
  • 8,548
7 votes

Difference between CALL, CALLCODE and DELEGATECALL

callcode has been deprecated in favour of delegatecall as per version 0.8.4
abhi3700's user avatar
  • 189
7 votes

Difference in "delegate call via assembly"

OpenZeppelin's one is the most generic and addresses contract upgrade scenario. It forwards msg.data as is to called contracts, and returns what called contract returned. MakerDAO's is also generic ...
Mikhail Vladimirov's user avatar
6 votes
Accepted

Why does DELEGATECALL use 94k gas in my contract in Remix?

Update. I'm leaving the answer below in place as it has some interesting points, but I think I've finally got to the bottom of this. The key point is buried in the Subtleties page: A CALL or ...
benjaminion's user avatar
  • 9,267
6 votes
Accepted

What happens if you chained delegatecalls?

Chains of delegatecall(..) will still retain the original msg.sender, storage, balance, etc values from the calling contract. contract A { function indirect() { B.doit(); } ...
Piper Merriam's user avatar
6 votes
Accepted

Delegatecall: Storing values

if the target variable in the caller contract is in slot 0, the returned value will be the slot 0 of the delegatedcalled contract. For instance: contract caller { uint public number; address ...
Jaime's user avatar
  • 8,340
6 votes
Accepted

Is it possible to send Ether using delegatecall?

Exactly as @smarx mentioned, delegatecall does not do actual actions to the contract that you gave, a.k.a _contractAddress, but rather copy the code of function callMe() and execute in the ...
QYuQianchen's user avatar
6 votes

How to perform delegate call inside of view call (staticall)?

UPDATE: Check out my new answer with 2 different solutions to the similar issue here: https://ethereum.stackexchange.com/a/142712/3032 Yep, but it is tricky: pragma solidity ^0.5.0; contract D { ...
k06a's user avatar
  • 3,016
5 votes
Accepted

Solidity "call" function with array as input

The problem here is that Solidity call encoder have troubles in encoding dynamic arrays. Here is the example to illustrate this, assuming you have an instance of your first contract in web3.eth: ...
Oleksii Matiiasevych's user avatar
5 votes

Contract call from a contract from a contract?

Yes, although obviously each contract has to execute the call itself. You can do this 1024 times until you reached the maximum depth. At that depth all new calls will fail. This even lead to ...
mafrasi2's user avatar
  • 938
5 votes
Accepted

How does delegatecall work from Solidity 0.5.0 onwards?

The delegatecall arguments are incorrect, you should use: function delegatedCalculation(uint firstNumber, uint secondNumber) public { bool status; bytes memory result; (status,...
Jaime's user avatar
  • 8,340
5 votes

Pros and Cons of smart contract upgradable patterns

OpenZeppelin uses the "unstructured storage" proxy pattern. See the documentation for details: https://docs.openzeppelin.com/sdk/2.5/pattern OpenZeppelin in the proxy patterns blog post (https://blog....
abcoathup's user avatar
  • 1,338
5 votes

What is the difference between the STATICCALL and CALL EVM opcodes?

https://eips.ethereum.org/EIPS/eip-214 STATICCALL functions equivalently to a CALL, except it takes only 6 arguments (the “value” argument is not included and taken to be zero), and calls the child ...
Curry's user avatar
  • 51
4 votes
Accepted

How can I get delegatecall to return data?

The issue is that the response variable is not a memory pointer, it's a stack variable. When you use it as the pointer for your out data in the delegatecall, you're actually just writing the data to ...
Tjaden Hess's user avatar
  • 37.1k
4 votes

Out of gas transaction using delegatecall

delegatecall returns true on success, so if(_c.delegatecall(bytes4(sha3("setTestInt(uint")),_testInt )) throw will throw if the call is successfull. Try if(!_c.delegatecall(bytes4(sha3("...
Tjaden Hess's user avatar
  • 37.1k
4 votes

Use of delegatecall with msg.data

The fallback function gets called when no other function matches the calldata signature. In this code, the fallback functions is used as a universal function. This is done by forwarding the calldata ...
Henk's user avatar
  • 4,271
4 votes

delegatecall call internal functions from caller contract

No, it's not possible. Delegatecall simply calls the function inside the context of the current contract. It's like saying "Run function A and do whatever you want in MY storage". It has ...
odysseas lamtzidis's user avatar
4 votes

Set data for call(), delegatecall(), etc, in Yul / inline assembly?

There are several issues with your code : You are not handling memory correctly You are not encoding your parameters correctly You are not computing the data size correctly The delegatecall opcode ...
hroussille's user avatar
  • 7,661
4 votes
Accepted

Why we are using delegatecall?

Delegatecall doesnt send any ETH or anything to the called contract. It just allows you to execute code from a contract in the context of another contract. Like so : Contract Logic { uint a; ...
Foxxxey's user avatar
  • 4,307
3 votes
Accepted

How to make function call through relay / entry level contract

Yes, from Relay you can call Access2 functions, like createEntity. The important code in Relay that makes it happen is its fallback-function: function() { if(!currentVersion.delegatecall(msg....
eth's user avatar
  • 85.7k
3 votes

ERC20 Token tansfer through delegatecall throws

I think you are misunderstanding the purpose of delegatecall(). It executes the called contract in the context of the calling contract. In other words, it will use the code from the called contract, ...
mafrasi2's user avatar
  • 938

Only top scored, non community-wiki answers of a minimum length are eligible