108

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 that the receiving contract will treat the storage well. DELEGATECALL was a new opcode that was a bug fix for CALLCODE which did not preserve msg.sender and ...


4

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.


3

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 with the STATIC flag set to true for the execution of the child. Once this call returns, the flag is reset to its value before the call.


3

So basically the gas is specified as how much gas the sender willing to pay to send the money to the "msg.sender" This claim is not correct. To understand what's going on, you need to have a basic understanding of how a low-level call is executed (the yellow paper or this paper) are good starting points. Essentially, when a call is performed (implicitly, ...


3

So there is some unexpected behavior in the solidity compiler: https://github.com/ethereum/solidity/issues/2999 Works on pragma experimental "v0.5.0"; with compiler 0.4.18.


3

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 contract through a function which will not set the caller's value but sets the callee's value. And sender in this will be the caller only CallCode : When called ...


3

The general answer is that it follows the conventions of the ABI. You can work it out based on those rules. In this particular case, the encoding of data will start at position 36. The first four bytes will be the message signature, and the next 32 will be a pointer to the location of data's representation. Note that the first 32 bytes of data will give ...


2

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; contract D { uint public n; address public sender; function callSetN(address _e, uint _n) public { _e.call(abi.encode(bytes4(keccak256("...


2

You can use the manually-maintained directory at https://www.4byte.directory to search for the method given the signature. Here is the lookup for your example 0x3ccfd60b. There are further plans for the use of this directory like moving the lookup table into a smart contract - see https://github.com/ethereum/mist/issues/955.


2

No, means that if you use delegate call in your contract and the code at the target address contains a line with selfdestruct(someaddress), this code will be executed in your contract context, effectively destroying your contract. This means you should be careful when using delegatecall and only use it in contracts that you wrote or that you know well. ...


2

The problem has to do with how variables arranged in the storage. The storage of the called and the calling contract should match. The answer to this question can be found here https://github.com/ethereum/solidity/issues/944


2

Starting from solc 0.5, call returns two values: bool success, which indicates whether or not the function completed successfully bytes memory data, which is the actual data returned from the function The comma in (bool success, ) = ... implies that you are already using solc 0.5 or higher. So simply change it to (bool success, bytes memory data) = ..., ...


1

The call method can be used to send arbitrary data to another contract. If no data is sent this normally triggers the fallback data, but it is also possible to trigger any other function of the target contract. When a function returns data or reverts with an error message then this data will be returned in the bytes memory See https://solidity-by-example.org/...


1

Try this: pragma solidity ^0.5.0; contract A { function a() public returns(uint256) { return 2; } } contract B { address addrOfA; constructor (address _addrOfA) public { addrOfA = _addrOfA; } function b() public returns(uint256) { (bool success, bytes memory result) = address(addrOfA).delegatecall(abi....


1

You are simply missing the bytes parameter for call: pragma solidity 0.5.9; contract Testing { function participate() public payable{ uint winner = 9; require(msg.value == 0.1 ether); if (winner == 9) { (bool success, ) = msg.sender.call.value(address(this).balance)(""); require(success, "...


1

The problem is you are using uint when calculating the selector. You should use the full type uint256. function useCall() public{ require(address(a).call(bytes4(sha3("checkMe(uint256)")), 2)); } function useDelegateCall() public{ require(address(a).delegatecall(bytes4(sha3("checkMe(uint256)")), 3)); } useCall should work without problems. ...


1

While you have knowledge about the code of Contract1 you can call the function directly. You can declare the return arguments (arg1, arg2) with the call. pragma solidity ^0.5.1; contract Contract1 { function func(uint256 x, uint8 y) public returns (uint32, uint32) { return (uint32(x), uint32(y)); } } contract ...


1

Simple way uint private constant MAGIC = ...; // Your birthday here uint private magic = MAGIC; function isDelegated () internal view return (bool) { return magic != MAGIC; } The idea is that MAGIC is compile-time constant, so it will be embedded into the byte code by Solidity, but magic is state variable. When contract is called normally, magic == ...


1

Unfortunately a contract can't handle raw transactions. We would face all sorts of new issues if it was possible (such as who pays for the gas). Nothing prevents you from creating your own contract which transfers tokens and triggers another contract. But this way the contract would have to own the tokens itself so they'd need to be transferred to the ...


1

Transactions are included in a block in a specific order. In your example, even if both transactions are in the same block, one will come before the other. In this case, the first tx in the block's tx list will become the super hero, and the price will increase to 2 ETH. When the second tx is executed, it is executed in a version of the smart contract ...


1

I think I found what was the problem: lack of double quotes. When instantiating the Smart Contract using the literal ABI from https://ethereum.github.io/browser-solidity/ everything works! > var greeter = eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"greet","...


1

I don't think so. As I understand it, Solidity takes the first few bytes of the sha3 hash of the contract's signature to identify methods. It can't be done in reverse unless you already had the source code.


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