Questions tagged [storage]

all questions regarding data and storage on the ethereum blockchain

Filter by
Sorted by
Tagged with
0 votes
1 answer
47 views

Any help to resolve this error? much appreciated! from solidity: SimpleStorage.sol:28:4: ParserError: Expected primary expression

How do I solve this error? I keep getting Expected primary expression. when compiling using pragma solidity ^0.6.0. Here is my code. Thanks! pragma solidity ^0.6.0; contract SimpleStorage { ...
BHUNTX.eth's user avatar
2 votes
0 answers
72 views

Upgradable contracts - proxy storage allocation

So in general, for fixed size fields, storage is allocated (reserved) at time of contract deployment - as per my undestanding. Now, we deploy a Proxy contract, and separately a couple versions of ...
almondandapricot's user avatar
1 vote
1 answer
676 views

Is Nonce Stored in State?

I read these paragraphs from the Whitepaper and Mastering Ethereum book. And I'm confused. Is nonce stored at state, or not? Whitepaper says: If the value transfer failed because the sender did not ...
Fatih Furkan's user avatar
0 votes
1 answer
13 views

Methods that only return arrays are very common. But, in the 'returns' argument, do I use memory or storage? and why?

// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; contract MyContract{ address[] public myAddresses; function getMyAddresses() public view returns(address[] [[...
Amit N's user avatar
  • 3
2 votes
1 answer
2k views

mapped struct storage layout (slots) and collsions

I want to establish a pattern that ensures no storage slot collisions between current and future (compliant) versions of a contract behind a transparent proxy. In particular, contracts that are meant ...
Rob Hitchens's user avatar
  • 55.2k
2 votes
0 answers
67 views

I don't understand this part of the Ethereum Documentation (storageRoot)

This is from the account part of the Ethereum Docs, 4 fields of an account were described of which i am unable to understand this one. (storageRoot)
ameymeow's user avatar
  • 115
0 votes
1 answer
55 views

Does a view function use gas if called by another function which access the same storage variable?

Let's say I have a view function that accesses a storage mapping like so: function performCalculation(uint256 _id) public view returns(uint256) { uint256 memory someValue = someMapping[_id]; ...
luxo's user avatar
  • 208
3 votes
0 answers
48 views

Why does a STORAGEADD op (SSTORE) add 80 bytes to state rather than 32?

According to this spreadsheet that Vitalik has referenced before, stating that it's what they used to determine gas fees for each opcode, a STORAGEADD opcode (presumably renamed to SSTORE) is ...
Paul DeLucia's user avatar
1 vote
1 answer
65 views

Why does Ethereum state storage cost more than history storage?

According to this spreadsheet that Vitalik has referenced before, stating that it's what they used to determine gas fees for each opcode, state storage costs around 190 gas per byte while history ...
Paul DeLucia's user avatar
0 votes
1 answer
205 views

Write to storage with assembly inline

I have this contract where I use inline assembly to add two numbers. pragma solidity ^0.8.0; contract Test { function add(uint a, uint b) external { assembly { let sum := add(...
Emrah's user avatar
  • 1,654
1 vote
1 answer
64 views

Max storage a mapping can hold

If I have a mapping that lets users store strings in a mapping ( by index). How many strings could the contract hold? Not worried about gas this will be on an L2
degendeveloper's user avatar
0 votes
2 answers
1k views

How to push elements in an array within a function?

Can anyone help me figure out the issue with this function in the code? function getVerifiedProposals(uint index) public returns (string[] memory, string[][] memory, address, uint[] memory) { ...
Bigbunny's user avatar
1 vote
1 answer
2k views

Storage, Memory and Calldata

1- Why is it only memory when using Value Types as parameters in functions? For example, would it be absurd to set it as calldata? 2- When we define state variables, they are stored in storage. Why ...
Whisrambol's user avatar
2 votes
1 answer
104 views

Decentralized Storage for sensitive data

As the title says, is there any decentralized storage technology for storing sensitive data like the personal information of users? Concretely, I am developing a Dapp on blockchain, where users have ...
Hoang Nguyen's user avatar
2 votes
1 answer
780 views

sstore struct within mapping, inline assembly

I'm trying to read from and write to a mapping of structs using inline assembly. getValues() is an example of how I'm able to read something from storage. I can read the first two values using and() ...
normal_human's user avatar
0 votes
1 answer
153 views

Cheapest way to access and modify a struct

I am using solidity 0.8.10. In my contract I have a state variable struct: struct Product { uint id_prod; address payable producer_addr; address payable owner_addr; bool onSale; } ...
sono's user avatar
  • 113
2 votes
1 answer
3k views

How to read contents of a deployed contract's storage slot via web3?

If I had an address of a deployed contract, would it be possible to read the contents of any particular storage slot location directly via web3?
Ahmed Ihsan Tawfeeq's user avatar
1 vote
4 answers
728 views

What is the most efficient way to compare items in 2 different arrays using Solidity?

Within a Solidity Smart Contract, I have 2 arrays that need to be compared. I would like the output to be 3 different arrays that can be used for other logic within the contract. Example of the arrays:...
mattblack's user avatar
0 votes
2 answers
217 views

Why can't I initialize storage array right away?

Why can't I initialize storage arrays when declaring them rather than initializing them in function or constructor? example: this does not work, it amounts to [0, 0, 0, 0] contract Example { ...
mmmmdev's user avatar
1 vote
1 answer
86 views

Can we find previous balance values of state trie

I know that in the block is included the StateRoot of the state trie. Also, i know that the entire state trie is saved locally on disk for each node and periodically be updated based on new upcoming ...
Mixalis Navridis's user avatar
1 vote
2 answers
403 views

Why does this function not update my storage array?

Since reference types such as arrays are passed by reference by in Solidity, they pass a reference (pointer) to the value. Any change to that value will reflect on original value. If this is the case, ...
Emrah's user avatar
  • 1,654
1 vote
0 answers
29 views

Is it wrong to read or trust historical information from logs in client side?

I noticed one thing while learning Events/Logs from some sources. If I understand these sources correctly nodes can remove logs for effective memory usage. If my client tries to read logs that do not ...
Murad Sofi's user avatar
0 votes
0 answers
24 views

What is main reason Events/Logs exist in solidity [duplicate]

When I started learning Solidity I saw Event/Log functionality. After a little bit of research, it got me a little confused. As far as I understand Event/Log (I use these words interchangeably because ...
Murad Sofi's user avatar
1 vote
1 answer
284 views

Loading an array into memory, does it call `SLOAD` many times?

Let's say I have an array in storage: // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; contract Test { uint256[] s_array = [1,2,3,4,5,6,7,7,8,8,8,8,8,8,8,8,8,8,8]; function doStuff() ...
Patrick Collins's user avatar
0 votes
1 answer
32 views

return array of size n

I need a function that willl return an array of size n and have each element be a 1. How do I write this in solidity? I need something like uint256[] a = makeOnesArray(5) => [1, 1, 1, 1, 1]
degendeveloper's user avatar
0 votes
1 answer
317 views

Using a dynamic array for an index vs a fixed array

I'm going to be using a smart contract to add data to an array, so I'll be using array.push (fixed gas). The data added is an address and the purpose of the array is just to keep a list of all ...
Ryan Detzel's user avatar
0 votes
1 answer
502 views

Accessing and storing a Struct from external contract

I was trying to access and store a Struct from an external contract. Is there a way with which this is possible. This would be a simple PoC where I am trying to access a Struct from Student contract ...
Cule219's user avatar
  • 25
1 vote
2 answers
2k views

What is the gas cost to read a member of a global struct?

Say I have a global state variable struct MyStruct that has multiple members/attributes/fields, what is the gas cost for reading a specific member? Is it equivalent to the gas cost of reading the ...
MShakeG's user avatar
  • 1,633
0 votes
1 answer
481 views

How do I parse a bytes32 in solidty?

I have a bytes32 object in memory or storage and I want to parse it into little chunks, for example into one uint8, followed by a bool, followed by uint10, followed by address. How can one do that? I ...
Marlo's user avatar
  • 329
1 vote
0 answers
15 views

Is storage being passed to this newly created contract?

I'm looking at uniswapv3 code and noticed something peculiar. When uniswap creates a pool, it lays out parameters in storage and then immediately deletes them after the contract is created. Is this ...
user1099123's user avatar
0 votes
1 answer
343 views

Using assembly to store more values per word

I need to store 1250 numbers 16 bits elements in an array. Storing unit256 cost 20.000 gas units each (SSTORE opcode), which at 200gwei gas price, will cost around 4.5 ETH. My understanding is that I ...
Sam Quinn's user avatar
  • 103
2 votes
1 answer
394 views

Why are functions that access immutable variables not pure?

My understanding is that immutable variables are basically equivalent to constant variables however the former is initialised in the constructor whereas the later at declaration, however both are ...
MShakeG's user avatar
  • 1,633
1 vote
1 answer
422 views

UniswapV3 PoolDepolyer (variables overriding throught slots)

I cant understand Pool deployment using variables transfering throught slots. How it works and why developers choosed that way of initialization(guess it's cheaper)? Pool contract snippet(simplified): ...
4rgon4ut's user avatar
3 votes
2 answers
3k views

How to initialize an array inside the function and push items into it?

How to initialize an array inside the function and push items into it? I'm not gonna initialize outside the function. Here's my code: function tokenOfOwner(address owner) public virtual returns (...
leojail's user avatar
  • 177
0 votes
1 answer
384 views

Why does changing a storage slot's value from zero to non-zero cost more than non-zero to non-zero in the sstore opcode?

Why does changing a storage slot's value from zero to non-zero cost more than changing from non-zero to non-zero, zero to zero, or non-zero to zero?
Paul DeLucia's user avatar
1 vote
0 answers
12 views

Concept Check: Data Server Nodes, Fetch Nodes

I had this idea for a way to make it possible to run a MUCH MUCH smaller node but still mine on a chain. I don't know if there is anything useful in it, but decided I would post it here for feedback ...
Saveer Jain's user avatar
2 votes
1 answer
2k views

Is the gas cost for constant and immutable about equal?

According to this question the Solidity 0.5.0 Compiler cannot compute a constant state variable that invokes a function, however I'm also experiencing this issue on Solidity 0.8.10 using the ...
MShakeG's user avatar
  • 1,633
0 votes
1 answer
1k views

How to declare getter function signature in interface for a mapping?

I have a contract that implements an interface, the contract has a state variable mapping(address => bytes32[]) public usersLists, I defined a getter function signature in the interface for this ...
MShakeG's user avatar
  • 1,633
0 votes
1 answer
71 views

How does an NFT marketplace give a verified badge?

I am trying to build an NFT marketplace. I see that Opensea provides a verifiable account badge. Here is the link for documentation I wonder how Opensea uniquely identifies the user if it is qualified ...
Yilmaz's user avatar
  • 1,580
0 votes
1 answer
452 views

How to copy all items of an array to a dynamic array of a different size?

I have a problem when I try to store an array in another array. I get as error when running store: transact to MyContract.store errored: VM error: revert. I need the second array, because in the next ...
Paul's user avatar
  • 3
1 vote
1 answer
525 views

Gas costs of multiple Writes / Reads to same slot in transaction

I know that the EVM wants to charge for reading from slots, and even more for writing to those slots. That all makes sense. My question is, whether the EVM is smart enough to store in memory the ...
Gregory Magarshak's user avatar
2 votes
0 answers
146 views

Solidity array has no SLOAD optimization

Suppose a function writes to storage, and then reads from the same storage location before it has been overwritten. In solidity 0.8.11 in these cases the SLOAD gets optimized away (there is 1 SSTORE ...
Jesbus's user avatar
  • 10.5k
1 vote
1 answer
272 views

How to use window.ethereum to read from EVM storage slots since window.web3 got deprecated in latest metamask update?

I was playing Capture the Ether challenge and in one of the challenge we had to read data from storage slot in the EVM. I referred this medium article: https://medium.com/@saurfang/lets-play-capture-...
Satyartha S's user avatar
1 vote
2 answers
490 views

Value assignment for storage variable (in declaration VS in constructor)

What difference does it make if I assign the value of a storage variable in the same line where it is declared vs if I assign its value in the constructor? Which would be the preferred approach? And ...
Ahmed Ihsan Tawfeeq's user avatar
1 vote
0 answers
435 views

The storage in EVM

I have 2 questions about the storage in the diagram bellow. 1- What is exactly content ? 2- Is it the same Storage which is store in the Account State under Hash form ("storage root hash")? ...
Bracko's user avatar
  • 21
2 votes
2 answers
156 views

Are storage values copied or referenced?

Given this contract contract C { struct Product { uint price } Product[] storage products; function doSomething() { products.push(Product({price: 100})); products.push(...
Luke Hutchison's user avatar
1 vote
1 answer
153 views

Can you use a local `storage` value after it is deleted from a mapping or array?

In Solidity, if you delete a value from a mapping or shorten an array, are local storage references to the deleted item still valid? Case 1: contract Case1 { mapping(uint256 => Widget) private ...
Luke Hutchison's user avatar
1 vote
0 answers
103 views

Why is it more expensive to declare storage variables in a proxy?

I want to deploy many contracts with the same functionality, so I decided to use delegatecalls. I have my contract ActualContract that contains all the functionality and a contract ProxyContract that ...
UTF-8's user avatar
  • 518
0 votes
1 answer
80 views

Implement saving a number in a secure way on chain

There are a lot of questions like this, but before you close this one look closely. Please have a look at this smart contract contract StoreWithSecret { uint256 private secretNumber; ...
grisVladko's user avatar
8 votes
1 answer
2k views

How does Ethereum fit a mapping into storage?

Probably a silly question, but how does Ethereum fit a mapping into storage? I am used to simple types like arrays, so I don't understand how "Solidity's mapping uses the entire 256-bit ...
Sam Lincoln's user avatar

1 2
3
4 5
13