Questions tagged [delegatecall]
https://docs.soliditylang.org/en/v0.8.12/introduction-to-smart-contracts.html?highlight=delegatecall#delegatecall-callcode-and-libraries
64 questions with no upvoted or accepted answers
3
votes
0
answers
69
views
`delegatecall` in batch call stops working as expected when changing the code slightly
I have the following function for batching multiple calls, which returns the result (success or not) and the return data for each corresponding call.
function callBatch(bytes[] calldata calls) public ...
3
votes
0
answers
705
views
Anything like a static delegatecall from a view function?
let's say there are two contracts A and B, where A calls methods in B. I understand that A can modify and read storage in B with B.call() and B.staticcall(), ie. A can execute B's methods in the ...
3
votes
0
answers
55
views
Delegatecall Scope - Correct me if I'm wrong
When any contract function is called - delegatecall or otherwise - the EVM loads the requisite pointers & values into that call frame's volatile stack/memory.
Example:
Let's say we have contract ...
3
votes
0
answers
392
views
delegatecall on library always run out of gas
I'm trying to replicate the Dynamic Library attack of this paper under a recent version of solidity and the EVM.
Streamlining down the code, I've created this very simple contract (which is, in ...
2
votes
0
answers
23
views
Why is `delegatecall` not working with simple example on quorum node?
Deploying these two contracts:
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.0;
// NOTE: Deploy this contract first
contract B {
// NOTE: storage layout must be the same as contract A
...
2
votes
0
answers
557
views
How to interact with proxy contract with ethers and wagmi
I have an upgradable proxy contract that points to a specific contract. This is the contract in mumbai polygonscan => https://mumbai.polygonscan.com/address/...
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 ...
2
votes
1
answer
581
views
Exception while processing transaction: reverted with reason string 'Address: low-level delegate call failed'
I have the following function inside my Registry.sol contract:
function createOrganizerProxy(bytes32 organizationName)
public
payable
returns (address)
{
require(!isTaken[...
2
votes
1
answer
182
views
Preserve msg.sender but not storage
In this particular scheme, we pass the address of the Attacker contract in Victim.foo.
By using delegatecall, we maintain the msg.sender field, but we are not using the storage of Storage but Attacker'...
2
votes
0
answers
564
views
Proxy contract DELEGATECALL to pass a DYNAMIC array to a function in the target contract
I'm trying to get a Proxy contract to correctly do a delegatecall to a function in another 'target' contract. The problem is, that I need to pass a dynamic array as the parameter to this function.
Q: ...
2
votes
0
answers
669
views
How would you use a proxy erc20 contract if you cannot preserve msg.sender?
Let's say I use a proxy contract which allows me to make an ERC20 token transfer from my account.
At the moment the only way to do so is to use tx.origin which gets the original EOA address of the ...
2
votes
0
answers
102
views
What's the value of `this` inside a library function when called via a delegatecall?
Imagine a contract C that makes a delegatecall to a library L.
C -> L
What's the value of this inside L: address(C) or address(L) ?
If now that L makes a normal call to another contract D.
C ->...
2
votes
0
answers
1k
views
Using delegatecall to forward eth
The following code snippet is designed to forward all funds to a single destination, but where multiple contract D's will exist, allowing differentiation of the original source of the funds.
pragma ...
2
votes
0
answers
718
views
Call vs Delegate Call call data format
I'm using both call and delegatecall within an assembly block and i've noticed that when issuing a call I need to provide 4 bytes (sig) + any arguments, whereas for delegatecall I need to provide 4 ...
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 ...
1
vote
1
answer
90
views
Read value from DelegateCall
I would like to implement a whitelist using AccessControl of openzeppelin. Let's say I have the following setup:
Contract A: It's doing some stuff but only for users that are whitelisted.
// SPDX-...
1
vote
0
answers
46
views
How can timeZone1Library value be changed to address of Attack code? (Ethernaut #16 Preservation)
I've been practicing Ethernaut #16 Preservation. Everything is okay and I understood what delegatecall is. But, I don't get why timeZone1Library can be changed when we pass deployed attack address as ...
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
0
answers
258
views
UUPS upgradeable contract call fails with delegatecall error when calling newly added functions
I created an upgradeable contract adhering to the UUPS standard following this guide here. I then added some new functions, deployed the upgrade using the upgrades plugin upgrades.prepareUpgrade() ...
1
vote
1
answer
66
views
How can i foward funds swaped from 0x api quotes in the same transaction
ideally i will like to add more logic (like fowarding funds or fees) to the quote.data before letting a user send the transaction to the blockchain.
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?
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 ...
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() ...
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;
...
1
vote
0
answers
316
views
Why is delegatecall returning 0 and erroring?
I'm working with OpenZeppelin upgradable proxies, as well as their governance. I have a propose function that looks like:
function propose(
address[] memory targets,
uint256[] memory ...
1
vote
0
answers
399
views
How to call the super contract function where msg.sender should be same in solidity?
I am trying to call contract A.fun_A() via Contract C
contract A{
function fun_A(address tenant, uint itemId){
//Here the msg.sender should be msg.sender in C
require(msg.sender == ...
1
vote
0
answers
54
views
How to transfer a contract address to ContractRef type(ContractRef is a reference to the contract's backing object) in Go-ethereum
I want to call DelegateCall(caller ContractRef, addr common.Address, input []byte, gas uint64) in geth, but it can only be triggered by the opcode. So I want to convert address of deployed contract ...
1
vote
0
answers
79
views
What are "if" and "this" in this function?
function() public {
if(delegate.delegatecall(msg.data)) {
this;
What are the requirements for "if" to execute "this" and what does "this" refer to in this function?
1
vote
0
answers
94
views
How dangerous is this: number of contracts contain a function like "approveandcall" which lets anyone call any contract (some thoughts?)
The most common implementation is as follows:
function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
tokenRecipient spender = tokenRecipient(...
1
vote
0
answers
275
views
delegatecall (assembly) didn't change state variable in Remix with Web3 Provider
I am trying to test proxy pattern in Remix, which connected to my private chain with Web3 Provider. By the way, miner is working all the time. After invoking add function of Proxy contract, the state ...
1
vote
1
answer
746
views
pass storage through interface to library
Here is what am i doing:
There is a library, accept storage argument as parameter, then do some math and return the result.
And there is a contract to call the function in the library, and an extra ...
1
vote
0
answers
253
views
Subtraces of delegatecall in Parity trace
I'm investigating transactions using Parity trace which provides useful data over a transaction flow. Among this data is the Subtraces field which allows me to understand how many sub-calls each ...
1
vote
0
answers
75
views
Replaying the Bad Parity Hack
On a locally hosted instance of Ethererum I am trying to replay and understand the Bad Parity hack. I have a Wallet and a Wallet Library Contract.
Wallet.sol
constructor(address lib) public payable {...
1
vote
0
answers
117
views
delegatecall for Smart Contract versioning
I've a state variable
address public current;
which stores the address of the latest updated contract. This value can be modified with a function.
Then, I've a function of this kind
function ...
1
vote
0
answers
246
views
What happens when contract is making delegatecall to deleted contract?
I read the whole Suicide Parity Multi-sig hack. One thing I don't understand is what happens when you call delegate call on deleted contract?
I thought that contract should throw an exception but due ...
1
vote
0
answers
799
views
delegatecall executes but does not change state
I am trying to make use of delegatecall function in solidity.
function delegateTokens(uint256 _value) returns (bool result) {
tokens[msg.sender] = _value;
return token.delegatecall(bytes4(...
1
vote
0
answers
297
views
out of gas error by assembly delegatecall
I want to get a return value from current contract call other contract by delegatecall, but got a error of out-of-gas. I try to add gas limit to 3000000000, but it doesn't work. please help me. And i ...
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 ...
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
14
views
Can a contract call a proxy via delegatecall in a function?
I suppose this is not possible as the proxy contract code would try to retrieve the implementation code from the original contract storage.
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
39
views
How to build a 3 contract structure with delegatecall
I'm looking for help to build an intermediate contract using delegatecall. My challenge would be with 3 contracts.
I need contract A to be the owner of Contract B, and contract B to have a ...
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 ...
0
votes
1
answer
90
views
Using delegateCall without knowing the called contract's address
I am fairly new to Solidity and slowly starting to grasp its ecosystem :-)
I have a question about using delegateCall: How do I ensure that I call exactly the contract I want to call?
Let's assume I ...
0
votes
0
answers
33
views
Low level delegatecall to a lib does not change state in calling contract
In the code bellow when calling foo the storage of TestContract gets not changed. Expected behaviour to my understanding is that state.a is set to 5. The arg passed to the library function foo is a ...
0
votes
0
answers
63
views
How to delegate call from one contract to another contract in different blockchain
My proxy contract and implementation contract are in different blockchains. Can i use delegate call?
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 ...
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
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 (...