We have an issue with delegatecall method.
We want to call contract C2 from C1 (which is supposed to be a pass through contract for the user wallet). When we are calling C2 via C1 even using delegatecall or assembly instruction, the allowance of C1 is getting amended, but not that of the calling wallet. Eventlogs are appended below the code. Both delegatecallSetNum and delegatecallSetNumAssembly methods are behaving in an identical manner.
Code:
pragma solidity ^0.5.16;
contract C1 {
uint public num;
address public sender;
function c2setNum(address _c2, uint _num) public{
C2 c2 = C2(_c2);
c2.setNum(_num);
}
function delegatecallSetNum(address c2, uint _num) public {
c2.delegatecall(abi.encodeWithSignature("setNum(uint256)",_num));
}
function delegatecallSetNumAssembly(address c2, uint _num) public {
address _target = c2;
bytes memory _data = abi.encodeWithSignature("setNum(uint256)",_num);
bytes32 response;
// call contract in current context
assembly {
let succeeded := delegatecall(sub(gas, 500000), _target, add(_data, 0x20), mload(_data), 0, 32)
response := mload(0) // load delegatecall output
switch iszero(succeeded)
case 1 {
// throw if delegatecall failed
revert(0, 0)
}
}
}
function getAddr1(address _c2) public view returns (address){
C2 c2 = C2(_c2);
return c2.getAddr();
}
}
contract C2 {
uint public num;
address public sender;
event AddedValuesByDelegateCall(uint256 a, address addr, bool success);
function setNum(uint256 _num) public {
num = _num;
sender = msg.sender;
emit AddedValuesByDelegateCall(_num, msg.sender, true);
}
function getAddr() public view returns (address){
return msg.sender;
}
}
Kovan Deployment addresses: C2 : 0xa1891c26352742Cc9d9E0ec3B34C3690D1dEB2E3 C1 : 0x2fC788e36B6B844c4B9a61804ee41fe6128A9901