All Questions
Tagged with delegatecall solidity
135 questions
2
votes
1
answer
21
views
Does delegate calling to a non-payable function result into a revert?
I have a payable function that takes an array of call datas as input, to which it delegate calls one-by-one:
function batch(bytes[] calldata calls) external payable override {
uint256 count = ...
0
votes
1
answer
18
views
Cannot delegatecall a nonpayable function from a payable context?
I'm wondering why it always reverts when I delegatecall a non-payable function from a payable context when the msg.value is not 0.
Simple code below:
contract Trial {
function magicNumber42() ...
1
vote
1
answer
51
views
"DELEGATECALL" with value
How is it possible that "DELEGATECALL" with a non-zero value?
Example:
https://sepolia.etherscan.io/tx/0xd697d2db1494197496a8e6312c8295131a1df66bdeafd29be85361f2318832ad/advanced#internal
...
0
votes
1
answer
58
views
Reason for Checking `msg.sender == _msgSender()` in OpenZeppelin's MulticallUpgradeable Contract
In the OpenZeppelin::MulticallUpgradeable contract, there's a validation that checks msg.sender == _msgSender(). Considering that msg.sender and _msgSender() typically return the same value, why is ...
0
votes
1
answer
28
views
Is delegatecall to another contract really same as calling the function as if it were the part of calling contract?
When a contract makes a delegatecall, the code at the target address is executed in the context of the calling contract. This means that the storage, state variables, and functions of the calling ...
0
votes
1
answer
162
views
Delegatecall failing 'could not coalesce error'
I'm trying to set a message to my Contract setmsg through a proxy contract using delegatecall.Using hardhat.
getting this error:
error: {
code: -32603,
message: "Error: VM Exception ...
1
vote
1
answer
237
views
Payable multi-delegatecall
I have a code of multi-delegatecall like this:
function multicall(bytes[] calldata _data) external payable returns(bytes[] memory _results) {
_results = new bytes[](data.length);
for (uint256 ...
0
votes
1
answer
19
views
Identifying delegatecalls to a target contract
A contract I am auditing (contract A) is being used via delegate call by another contract. I suspect there may be more contracts using this code as well in the same manner but I cannot prove it.
Is ...
0
votes
0
answers
54
views
Access imported contract's function on behalf of another contract using delegatecall
So I have two contracts. the firt one is a contract that imports a token
import {testToken} from "./testToken.sol";
testToken public token;
and has this functionality
AddressUpgradeable....
0
votes
1
answer
35
views
Unable to change the storage using Delegate call
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Preservation {
// public library contracts
address public timeZone1Library;
address public timeZone2Library;
address public ...
1
vote
1
answer
203
views
How to change the storage using Delegate call
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Preservation {
// public library contracts
address public timeZone1Library;
address public timeZone2Library;
address public ...
1
vote
0
answers
28
views
Inheriting a contract to match state layout in a delegatecall
What is the best way to manage the state layout of a contract will exclusively be used via a delegatecall?
Let's say that there is a Parent contract that uses delegatecall on a Child contract. Within ...
0
votes
1
answer
67
views
delegateCall to a function of an upgradeable contract (TransparentUpgradeable)
I have the following TransparentUgradeable contract on ArbitrumOne:
https://arbiscan.io/address/0x4582f67698843Dfb6A9F195C0dDee05B0A8C973F
I want to call the function depositTokenViaUsdc() from a ...
0
votes
1
answer
57
views
Execute ERC20 Approve outside of ERC20 contract
I am rewriting the solidty-by-example.org crowdfunding exercise.
IERC20 public immutable token;
function pledge(uint _id, uint _amount) external {
Campaign storage campaign = campaigns[_id];
...
5
votes
2
answers
713
views
Preserving visibility "view" of a method using delegate call to a view method
I am using a delegate call inside a view function to a view function in the implementation contract
The compiler throws an error meaning that the delegate call can change the state, therefore, can not ...
2
votes
1
answer
2k
views
Who is msg.sender in a nested delegatecall chain?
Who is the msg.sender in emitted event by calling callMe method on contract D?
pragma solidity 0.8.10;
contract A {
event LogMsgSender(address who);
function callMe() public {
emit ...
2
votes
0
answers
598
views
Solidity assembly code - calldatacopy, delegatecall
I have been trying to understand how assembly code works,spending lots of hours, but I could not.
Please help me
Basically, I am digging into a proxy contract, and I do not really understand ...
0
votes
1
answer
85
views
How call() function works in solidity?
Learning call() function in Solidity, I read that we use call() only when we don't know the ABI of the called contract and we don't know its source code.
Below I have an example, but it seems we DO ...
0
votes
2
answers
1k
views
How to ".call" a function of another contract which uses ".call"
So, I'm learning advanced smart contract development. Two days ago, I learned about Reentrancy attacks and then I also created two contracts Protocol.sol (vulnerable contract) + Hacker.sol (attacker ...
1
vote
0
answers
46
views
How to decode DSProxy input data
I'm trying to debug a tx made through a DSProxy deployed on Polygonscan, but I'm having a difficult time since the _data part of the DSProxy function input is ABI-encoded. I would have to comb through ...
1
vote
1
answer
311
views
How to use the factory pattern when the child is ownable?
I'm trying to reason how a factory can make calls to a child contract that is owned by an EOA.
The goal of this project is to make a StoreFactory contract that allows anyone to deploy their own Store ...
3
votes
1
answer
390
views
Delegatecall not working
I have deployed the following smart contract: 0x016d87b8c98e6ad0991d128CddA435FAfbC06792
//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
contract Proxy {
uint256 public count;
address ...
1
vote
1
answer
155
views
Expected primary expression in byte casting
I have a contract (Implementation.sol) which delegatecalls the other contract (Attacker.sol) to selfdestruct. When I try to compile the Implementation.sol on Remix, I receive Expected primary ...
0
votes
0
answers
244
views
EOA delegating call authority to a contract to interact with another contract
Actually, I want my contract (say A) to interact with a project's contract (say B).
But, contract B's author has restricted calls by any contract. So with this, only one option is left i.e. an EOA ...
1
vote
1
answer
1k
views
What exactly is each parameter for assembly delegatecall?
I've been searching everywhere but I'm still not clear what each of the parameters are for delegatecall. What I have found is this delegatecall(g, a, in, insize, out, outsize), where g is gas and a is ...
1
vote
1
answer
1k
views
What is the difference between encodeWithSelector and encode?
I've been messing around with the abi.encode... functions and I think I have a good grasp of the differences, except abi.encode and abi.encodeWithSelector. Because, they give similar but slightly ...
1
vote
2
answers
582
views
Why is delegatecall calling the fallback function?
I made two simple contracts to test delegatecall on remix:
contract Delegate{
uint public x;
function add(uint a, uint b)public{
x = a + b;
}
fallback() external{
...
0
votes
1
answer
854
views
How do I pass a struct as an argument in delegatecall to a proxy library?
I am trying to call the buyAssetsForEth function in the OpenSeaMarketV2 library using delegatecall as follows:
pragma solidity 0.8.4;
contract Owned {
address public owner;
constructor(...
2
votes
1
answer
866
views
Is there a way to check if a call is a call or a delegatecall?
I want to add a modifier to one of my function that checks wether the function call is a call or a delegatecall?
Is there any way to figure that out? May be with some assembly?
0
votes
1
answer
599
views
delegate call from a fallback function using msg.data doesn't work
Please look into the following 3 contracts:
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;
contract implementationProxy {
uint public a;
uint public b;
address owner;
...
0
votes
1
answer
429
views
fallback not executing
I have a test project with proxy pattern (fallback/delegate call). The purpose is to have upgradeable contracts.
Here is the proxy contract:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
...
1
vote
1
answer
285
views
Assembly vs solidity delegatecall
Is there a real difference nowadays, performance-wise, between using assembly delegatecall and the high-level solidity version?
I know that in the past assembly was used so you could get the returned ...
0
votes
1
answer
16
views
Delegatecall reverting after adding a second argument
solidity 0.8.3;
I am trying to implement delegatecall, and I created a simple test within my contracts.
function f(uint256 _testInt) public view returns(uint256 test) {
test = _testInt + 1;
...
1
vote
1
answer
382
views
Contract A delegatecall function in contract B which calls function in contract c. msg.sender for function in contract c?
If Function in contract A delegatecall function in contract B which calls function in contract C. What will be the msg.sender for function in contract C?
0
votes
1
answer
835
views
delegateCall in Solidity understanding case
pragma solidity ^0.8.10;
/*
HackMe is a contract that uses delegatecall to execute code.
It it is not obvious that the owner of HackMe can be changed since there is no
function inside HackMe to do so....
0
votes
1
answer
89
views
Events in Chained Fallback Function Cause VirtualMachineError
I’m working on an upgradeable contract that uses fallback functions with inline assembly delegatecall and call calls (using calldatacopy and returndatacopy) to route internal and external function ...
1
vote
1
answer
1k
views
Delegatecall failing
I have this second-layer delegatecall (delegatecall on a contract that already did delegatecall) that continues to fail even after checking all the main reasons why it could fail (storage layout, uint ...
0
votes
1
answer
260
views
solidity delegatecall Error return value
function queryErc20BaseInfo(address a) public view returns(bool success, bytes memory list )
{
(success , list) = address(a).staticcall(abi.encodeWithSignature("name()"));
return (...
2
votes
2
answers
874
views
Chain of delegatecall and call
Situation is: A calling B delegate calling C calling D
What would be the msg.sender in D?
I performed some test in Remix and it looks like msg.sender in D is C's address. I don't get why it's not A's ...
1
vote
0
answers
223
views
How to manually generate calldata
Here's my code snippet:
function getCalldata(string calldata _func, string calldata _param1, uint256 _param2) public pure returns (bytes memory) {
return abi.encodeWithSignature(_func, _param1,...
1
vote
0
answers
206
views
Best practice for calling function from another contract
I'm a bit of a beginner so I'm sorry if I misphrase anything, but I haven't been able to find a definitive answer on this yet. I'm going through some tutorials which list out a few ways to call ...
3
votes
1
answer
258
views
delegatecall in Brownie
I am trying to perform delegatecall in Brownie solving the Delegation task in the Ethernaut app in order to claim ownership of the Delegate contract (see below).
What is the equivalent of the ...
4
votes
2
answers
4k
views
Why is there significant gas costs associated with call and delegate call?
I've been trying to understanding why Ethereum doesn't have a significant on chain package/library ecosystem despite having the capacity to do so via delegatecall or call to an ImplementationContract ...
1
vote
0
answers
382
views
DelegateCall returning false
I'm learning Solidity and tried to create a couple of contracts on Truffle.
For this, I have created a Shop.sol contract that can "Buy" items using an ERC20 token.
Inside the buyItem() ...
0
votes
1
answer
370
views
Why does this result in an infinite loop?
I am doing this exercise: https://ethernaut.openzeppelin.com/level/0x9451961b7Aea1Df57bc20CC68D72f662241b5493
I expect my contract to call a non existent method in Delegation which then calls the ...
0
votes
1
answer
387
views
Can I delegatecall my own internal function?
I have a contract that uses
address(this).delegatecall(...)
Can I put an internal function inside the delegatecall somehow?
I tried the normal way, public functions worked but internal didn't. Is ...
4
votes
1
answer
129
views
Does `delegatecall` create a new stack frame?
It seems like it was introduced to replace callcode because callcode modified msg.sender and msg.value, and that breaks a lot of use cases.
If the msg fields aren't changed, that leads us to think a ...
0
votes
0
answers
128
views
delegatecall return wrong value
I want to get userInfo which is masterchef's methods.
But I want to call userInfo from another contract, so I'm using delegatecall
address sender = msg.sender;
(bool success, bytes memory result) = ...
3
votes
1
answer
1k
views
What does "caller()" return in Yul when DELEGATECALL is used?
While browsing the Solidity docs, I noticed this instruction available in assembly:
caller(): call sender (excluding delegatecall)
What do the docs mean by "excluding delegatecall"? Is it ...
1
vote
0
answers
654
views
Does a proxy contract need to declare state variables?
There is no variable declaration in the proxy contract. Does the returned data from the delegate call auto-generate the variables for the proxy contract?
contract Logic {
uint256 varA;
...