Hot answers tagged

2

Here's an example of how to set a storage array's length using sstore: pragma solidity ^0.6.0; contract Tata { uint256[] public testArray; function getLength() external view returns (uint256) { return testArray.length; } function setLength(uint256 newLength) external { assembly { sstore(testArray_slot, newLength) } ...


2

Solidity 0.6.0 and Greater (Updated Jan 2020) As of Solidity 0.6.0, there is array slice functionality built into Solidity. The syntax is similar to existing languages in that the array takes the following parameters x[start:end]. Here, start and end are ints that represent the starting and ending index to be sliced. If start is greater than end or if end ...


1

nested hell Yup. This is circular: struct B { B[] as; } B contains arrays of B? The dynamic array of a struct inside a struct pushes the limits of what the compiler can handle. You would have to construct a memory instance of the struct and use the push method, which isn't present and then copy the works into storage. As a general suggestion, ...


1

Ah I think I figured it out! My error -- if p is the "location" of the array, then keccak(p) is the location of the data, so keccak(p) + 0 would give the first data value. I incorrectly interpreted keccak(p) as the place where the array length is stored (i.e. [length, val0, val1, ...]), while in reality we have something more along the lines of length at ...


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