3

Sure. To deploy smart contract one needs to publish a transaction with empty to address and with data containing contract initialization code concatenated with values of constructor parameters. Initialization code usually consists of constructor byte code and contract's byte code to be deployed. So, deployed byte code does not contain constructor and ...


3

You'll have a much easier time of this if you can use a recent version of Solidity. Starting with 0.5.x, you can get back the return value as a byte array and then decode it yourself depending on its length. Here's some code that handles both return values (a single uint256 or a pair of them) and returns a 0 as the second value if it wasn't returned from ...


3

Yes, checkReturnData() will be able to read the return data from originalContractInterface and will return 1. For context, returndata is the data returned from the last function call. returndatasize is the size of the return data from that call. In the example given in the question, mainFunction() calls originalFunction(), which then sets the returndata ...


3

From the docs: calldata is a special data location that contains the function arguments, only available for external function call parameters. Every reference type, i.e. arrays and structs, has an additional annotation, the “data location”, about where it is stored. There are three data locations: memory, storage and calldata. Calldata is only valid ...


2

Your issue is with the location you're passing to mload. The memory addressing of inBytes is 32 bytes for the length, then the rest is the data. Since you're storing a uint256 at the 32 bytes after the length, the memory map is going to look something like this: 0x00 00 00 00 00 00 00 00 0x00 00 00 00 00 00 00 20 0x00 00 00 00 00 00 00 00 0x00 00 00 00 5C ...


2

Each storage variable has its own storage slot whose address is a sequential number of this variable within contract: contract Foo { uint internal x; // Storage slot #0 mapping (uint => uint) internal y; // Storage slot #1 uint [] internal z; // Storage slot #2 } For atomic variables, such as x, this slot holds variable value. For mapping ...


2

Is that correct? If yes, why do we do this and where can I find some further documentation? Yes, you are correct. Transactions are encoded based on the Contract ABI Specification. It is hard to get through, but these docs have all the answers to your question. The transaction in question is passing in a dynamic parameter (bytes) as opposed to a static one ...


2

Couldn't find an answer so ran following example in remix. while reusing code from here. And conclusion is, address should be padded to 32 bytes. pragma solidity 0.4.18; contract TestAddress { function isSameAddress(address a, address b) returns(bool){ //Simply add the two arguments and return if (a == b) return true; return false; ...


2

OK, I ran a simple test and found out that in a dynamic array, the length of the array is located at the first 32 bytes relatively to the beginning of the array: Smart Contract: pragma solidity 0.4.25; contract MyContract { function read1() external pure returns (uint a, uint b, uint c) { uint[3] memory arr; arr[0] = 111; arr[1]...


2

What have I done wrong in the above code? With inline assembly the log3 function organizes the stack according to the given parameters and then executes the LOG3 opcode. The stack inputs for an event, top to bottom, are as follows: memory location where the unindexed event data begins length of the unindexed event data within the memory indexed topic(s) ...


2

Abdul! There is a typo in your call function arguments. You should remove a space from test function signature, i.e. abi.encodeWithSignature("test(address,address)") Every symbol in the string is important since the whole string is hashed in encodeWithSignature function.


2

This will get the job done: pragma solidity ^0.5.1; contract Encoding { function encode(address _address1, address _address2) public pure returns (bytes memory output) { return abi.encodePacked(_address1, _address2); } function decode(bytes memory _encoded) public pure returns (address x, address y) { assembly { x :...


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); ...


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

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


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 answer lie in this article: https://link.medium.com/7oxDTDmKpZ tl;dr: they are the same but the order of method_id make func1 more expensive than func2 Update: So i have try to my theory it seem like somehow it is the solidity function name problem. The reverse code: pragma solidity ^0.5.0; contract Test { uint public value; function func2(...


1

You are deploying a new instance before every test so any changes will be ignored in following tests beforeEach(async function () { this.base = await Base.new(); })


1

You need to write the following: (bool success, ) = dest.call(data); As the docs says: In order to interface with contracts that do not adhere to the ABI, or to get more direct control over the encoding, the functions call, delegatecall and staticcall are provided. They all take a single bytes memory parameter and return the success condition (as ...


1

Reading the comments, maybe you are looking for something like the following. I've changed the values to see more easily the outputs. To test, you need to pass the address of NotMyContract1 or NotMyContract2 as a parameter of the getValue() function. pragma solidity ^0.4.25; contract NotMyContract1 { uint256 a = 721; function func() external view ...


1

It explained a little later in the same documentation: Solidity manages memory in a very simple way: There is a “free memory pointer” at position 0x40 in memory. If you want to allocate memory, just use the memory starting from where this pointer points at and update it accordingly. An array always use the first slot to store its length and it always ...


1

OpenZeppelin's one is the most generic and addresses contract upgrade scenario. It forwards msg.data as is to called contracts, and returns what called contract returned. MakerDAO's is also generic but it allows passing arbitrary bytes as parameters and packs returned value into bytes as well. Simple version allows arbitrary bytes as parameters but only ...


1

function readData (bytes memory data) public pure returns (bytes32 a, bytes memory b) { require (data.length == 0x80); assembly { a := mload (add (data, 0x20)) // A b := mload (0x40) // Free memory pointer mstore (0x40, add (b, 0x80)) // Advance free memory pointer mstore (b, 0x60) // B length mstore (add (b, 0x20), mload (add (data, ...


1

If you're using Remix, this should only give you the following warning, not an error. It gives you an idea as to why you should avoid assembly (presumably unless you know what you're doing). The Contract uses inline assembly, this is only advised in rare cases. Additionally static analysis modules do not parse inline Assembly, this can lead to wrong ...


1

You do not have to complicate it using assembly, using shift and type cast should work. pragma solidity >=0.4.22 <0.6.0; contract A { function test(bytes32 r) public pure returns (bytes8 i, bytes8 j, bytes8 k, bytes8 m) { uint256 rr = uint256(r); i = bytes8(uint64(rr >> 64*3)); j = bytes8(uint64(rr >> 64*2)); ...


1

The confusion here is probably because unlike traditional processors, EVM has several different “memories” accessed via different opcodes: General memory accessed via MSTORE, MLOAD, MSTORE8, and MLOAD8. It is used to store non atomic data structures such as strings, arrays, and structs. Stack memory accessed via PUSH*, DUP*, SWAP*, POP. It is used for ...


1

@benjaminion's answer is fantastic, but I wanted to leave my tuppence and make the assembly code easier to understand: assembly { let ithpos := mul(add(i, 0x01), 0x20) let ithnumber := mload(add(_data, ithpos)) o_sum := add(o_sum, ithnumber) } What I did: Instead of adding 0x20 to the memory location of _data, I simply increment i by add(i, ...


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