4

This contract is quite "old" (pragma solidity ^0.4.15;). The logic is actually taken from the solidity compiler. When targeting older versions of the evm it was not possible to send along all gas. The solidity code still exists even now: https://github.com/ethereum/solidity/blob/develop/libsolidity/codegen/ExpressionCompiler.cpp#L2343 Solidity changed this ...


2

This is because memory variables are treated as pointers from in solidity assembly - and that pointer points to the start in memory of the variable. The way arrays are stored in memory in Solidity is with the first 0x20 (32) bytes being the length of the data in the array, and then the actual data directly following, which is why add(bytecode, 0x20) is ...


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) = ..., ...


2

This worked for CREATE2. Maybe it also works on CREATE? abi.encodePacked(bytecode, abi.encode(arg1, arg2)) Example (CREATE2) pragma solidity ^0.5.11; contract Wallet { address public owner; uint public foo; constructor(address _owner, uint _foo) public { owner = _owner; foo = _foo; } } contract Factory { event ...


2

You need to abi-encode the input arguments, and then append the result at the end of the bytecode before passing it to the create function. Suppose you have input arguments arg1, arg2 and arg3. I believe that you can more or less achieve that by changing this: bytes memory bytecode = _bytecode; To this: bytes memory bytecode = abi.encode(_bytecode, arg1,...


2

As @Ismael said, it is possible by using mload(data), here is an example you can test in remix: Simple struct pragma solidity ^0.5.0; contract Test { struct MyStruct { uint256 x; uint256 y; } function testFunc() public pure returns (uint, uint) { MyStruct memory data1 = MyStruct(5,7); return myFunc(data1); ...


2

Well, it's pretty obvious when looking into the set of input arguments passed in each case. For the non-assembly call, you pass: Destination address (addr) Amount of ether (value) Executable code (data) For the assembly call, you pass: Number of gas units Destination address Amount of ether Executable code (data buffer + data length) Output address (data ...


2

Check out the fallback function. https://github.com/rob-Hitchens/TrustlessUpgrades/blob/master/contracts/Proxy.sol function () external payable { address implementationAddress = userImplementation(msg.sender); //solium-disable-next-line security/no-inline-assembly assembly { let ptr := mload(0x40) ...


2

If I'm not mistaken, that is a pointer (start) and a length. The syntax differs from Solidity because the latter gets the location as well as the length from the bytes argument. Hope it helps.


2

You can try, but my intuition tells me that it will revert, because your non-constant function will be executed with 0 gas. For example, suppose that your function is: function myFunc(address x, uint256 y) public returns (uint256); Then you can use: bytes4 private constant MY_FUNC_SELECTOR = bytes4(uint256(keccak256("myFunc(address,uint256)") >> (...


1

The storage in Solidity is a mapping of bytes32 to bytes32 and a slot under the hood is represented by bytes32. I did not fully understand the code you provided but here are my two cents. When you declare a byte[] in storage of the contract, it is packed. Which means the data against one index in that array would occupy one byte rather than full slot of 32 ...


1

A couple of things you should be aware of: Don't need to copy memory to the free pointer, you can use any memory pointer. The EVM will copy the memory to the target so it will not be modified. The first 32 bytes from payload is the array's length. When passing that memory probably want to skip those bytes. That is the reason behind add(payload, 32). ...


1

I suggest you look the existing proxy contracts like OpenZeppelin's Proxy as an example: https://github.com/OpenZeppelin/openzeppelin-labs/blob/master/upgradeability_using_eternal_storage/contracts/Proxy.sol


1

This contract seems to have no methods : https://etherscan.io/address/0xf6ab4331fb8dde0bb10f58bd0cc818514736a74f#code I'm afraid that your ETH will be stuck there forever.


1

function testStuff( uint256 x1, // 3735928559 -> "0xdeadbeef" uint256 x2, // 3735928559 -> "0xdeadbeef" uint256 x3 // 3735928559 -> "0xdeadbeef" ) public returns (bytes memory b) { b = new bytes(40); assembly { mstore(add(b, 12), x1) mstore(add(b, 8), x2) mstore(add(b, 4), x3) mstore(b, ...


1

Solution function getStorageValue(uint num, uint slot) public view returns (address result) { assembly { // Store num in memory scratch space (note: lookup "free memory pointer" if you need to allocate space) mstore(0, num) // Store slot number in scratch space after num mstore(32, slot) // Create hash from ...


1

This guide explained it fairly well. The storage pointers for nested arrays are organized as nested hash functions. At level one, keccak256(foo_slot), are the lengths for all first order arrays, foo[0], foo[1], foo[2], etc. The length of each individual subarray is, correspondingly, keccak256(foo_slot), keccak256(foo_slot) + 1, keccak256(foo_slot) + 2, etc. ...


1

We solved this by having a one time init function. For full source, see ThingFactory.sol and Thing.sol. Basically, what you do is have this one time init function on your target contract (in the example, it would be Thing.) Then your factory contract calls the init function directly after creating the clone. The ...


1

The ecrecover address is: 0x01 Without assembly you can call the ecrecover function like that: function recoverEC_Method1 (bytes32 _hash, bytes32 _r, bytes32 _s, uint8 _v) public pure returns (address) { bytes memory prefix = "\x19Ethereum Signed Message:\n32"; bytes32 prefixedHash = keccak256(abi.encodePacked(prefix, _hash)); return ecrecover(...


1

The fully working modern solution from Consensys dude can be found here: https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol The accepted answer's code is not compiling in Solidity >0.5; with implicit type conversion error.


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