Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [optimization]

Questions related to the optimization of Ethereum aspects such as gas, storage, compilers, etc.

1
vote
1answer
39 views

How does USDC manage to only cost 25k gas instead of 35k++ for transfer?

I am baffled why Centre's USDC only costs around 25k for token transfer instead of 35k++ like other common ERC20. For example this is Gemini USD: https://etherscan.io/tx/...
2
votes
1answer
48 views

Where can I learn to read a flow of opcodes and learn how to debug transactions?

There are many tools and visualizers to use to read through a transaction, but where can I go to learn how to understand this? Fore example, that first link has a series of opcodes (and their ...
3
votes
2answers
69 views

Why is the Eternal Storage approach still used if it hugely increases gas usage compared to storing data in structs?

I was wondering why is the eternal storage approach (first code snippet) still used? I know it's meant to make contracts upgradable but it seems too expensive to me. contract Storage { mapping(...
1
vote
0answers
64 views

Modifier to only allow access via staticcall

I'm trying to create a modifier that only allows a function to be called using staticcall. Using the view declaration in Solidity 0.5.0 guarantees that a function won't change state, but it still ...
4
votes
2answers
142 views

Do intermediate memory variables cost gas?

Example without an intermediate variable: uint startTime = 9; uint allowedTime = 7; require(now > startTime + allowedTime); Example with an intermediate variable: uint startTime = 9; uint ...
1
vote
0answers
18 views

Manually configure EVM Assembly Tag

I have read that Ethereum during the compilation splits the code into tags. The solc optimizer doesn’t optimize across tags. If we consider “1+1”, it can be optimized to 0x2 if under the same tag: /...
1
vote
1answer
59 views

Why are timestamps stored in a uint (256 bit) when they would fit in a uint64?

A (signed) 64 bit timestamp can store a date much larger than the age of the universe. On many platforms this would be a micro-optimization, but in the context of Ethereum, we want to squeeze every ...
1
vote
0answers
25 views

Does pooling make sense?

It seems that allocating storage elements is 4x as expensive in terms of gas cost than changing them. Does that mean it would make sense to pool structs and arrays, and maybe also strings, rather ...
1
vote
2answers
34 views

Supply gas from contract to execution of function

let's say I have something like this function usuallyCheapFunction() external { ... do something cheap... if(rareCondition == true) { expensiveCleanupFunction(); } } function ...
4
votes
2answers
122 views

Right way to keep track of mapping values

I'm having trouble finding the most cost efficient way to keep trace of what is stored into a mapping. I'm working on a web service that requires, to display, to get the data stored in a mapping This ...
0
votes
0answers
112 views

Identifiyng RX580 memory brand on Linux

When it comes to mining, I'm an absolute beginner. However I'm quite accustomed to linux server administration. I have my brand new PowerColor Red Dragon RX580 8GB and a Debian GNU/Linux sid server ...
0
votes
1answer
156 views

Solidity gas optimisation for loops

I have a function in my contract loops through the current user base (an address[]), within each loop, it performs some logic and writes some data into state user variables. The function starts to ...
1
vote
2answers
116 views

Deleting index of an array in terms of optimization for looping

I have a dapp where an admin can upload a number of cakes (20 to 30). People can come into the site and decide whether they want to buy a cake uploaded by admin. So for smart contract, I made an ...
1
vote
1answer
227 views

Private vs internal cheaper

I know that external is cheaper than public due to how arguments are parsed. Is making a function private or internal cheaper?
0
votes
1answer
30 views

Calling a mapping with array of struct. Optimization or performance recommendation?

I have a struct that has a number of fields and a mapping of StudentInfo array. struct StudentInfo { uint studentId; uint courseId; uint age; string firstName; string ...
0
votes
2answers
74 views

mapping with struct array, gas or performance issue?

I have a question regarding iterating a mapping with struct array. There is a for loop that iterates over a few thousands times trying to find a matching properties inside the struct. Ex: struct ...
0
votes
2answers
22 views

How can a Dapp store seed keys of non-HD wallets?(tumbleweed)

As the title suggests, is there a Dapp that exists to store seed keys of wallet?
2
votes
1answer
82 views

Does an Ethereum client need to download the entire state of a contract in order to use it?

A typical ERC20 token will store account balances in a mapping, something like this: mapping(address => uint) public balances; Does this mean that, to do a transaction or check a balance on this ...
0
votes
0answers
24 views

multi Key shadowing

is there anyway i can implement Multi Key Shadow in ERC20 token Smart Contract ? is there any code/ function to implement in smart contract or so ? Google can only tell me how it can implemented in ...
4
votes
1answer
186 views

Difference between unoptimized and optimized solidity code

I am trying to find a source on what the difference is between optimized and unoptimized code. My main question is what the unoptimized compiler does, especially in the sense of calling the SSTORE ...
1
vote
0answers
59 views

About using Solidity optimization

It is a well known fact that in optimizing mode compilers usually have more bugs than in non-optimizing mode. As such, do you recommend to use the Solidity compiler with or without optimization? My ...
1
vote
1answer
236 views

Loop optimization checking coordinates in a grid

I built a contract where users can set an image in a specific coordinate, that position can only have one image. The grid size is 400 height, and dynamic width (Will grow overtime) and there are 3 ...
0
votes
1answer
71 views

Can I trust Solidity compiler to replace MOD with AND when possible

According to the EVM Gas Cost Yellow Paper (can be found here): The cost of % is 5 The cost of & is 3 When x is a power of 2, the expression a % x is equivalent to a & (x - 1). If x is a ...
0
votes
1answer
747 views

Loop Optimisation for gas usage

for (uint8 i = 0; i < total; i++) { if (myarray[i].my_int >= maximum && my_array[i].my_second_int <= maximum) { result = my_array[i].id; break; } } I've been ...
1
vote
1answer
19 views

Contract Fairness Optimisation

I have designed a lottery contract which allows users to purchase tickets from a ticket pool of a given size. Once all the tickets have been allocated, the lottery is carried out and the winner ...
2
votes
0answers
129 views

Is there a “gas penalty” for using too many asserts in a contract?

I'm at a very puzzling scenario. While using Remix, I noticed that adding a few asserts has caused a significant increase in execution cost (from ~50K to ~59K). And not only did it increase the ...
0
votes
2answers
259 views

Initial sync taking well over half a week [duplicate]

I ran geth --fast --cache=1024 which was the recommended for faster syncing. It goes up to reach the maximum block once, then goes to the beginning and imports chain segments again. This second ...
6
votes
1answer
1k views

Any reason not to use Browser Solidity's “Enable Optimization”?

I found that when I had "Enable optimization" activated while writing a very simple contract with browser Solidity, it reduced a total of two SSTORE opcodes to one. That resulted in 5000 gas saved. ...
2
votes
0answers
237 views

How to setup a high performance parity RPC service?

I'd like to provide the RPC service from a parity daemon hosted in EC2. There're multiple options regarding the instance type, if it's for production, should I choose "compute optimized" or "storage ...
5
votes
2answers
284 views

Why is the jump address calculation so complex in compiled Solidity code?

I have the following simple Solidity contract: pragma solidity ^0.4.0; contract Test { function Test() { intfunc(5); } uint8 store; function intfunc (uint8 a) internal { ...
4
votes
2answers
1k views

Solidity optimizer vs LLVM optimizer

Looking at the evmjit code I noticed that the LLVM optimizer is actually used right before execution of a contract by the virtual machine. I have also noticed that the Solidity compiler has its own ...
4
votes
3answers
843 views

Binary search in Solidity arrays

I have an array that will be subject to lookup and insertion operations. It is likely that it will increase in size considerably. Does solidity offer any means of performing efficient lookup ...
5
votes
1answer
549 views

Is it reasonable to use uint128 or less to save space?

As I understand EVM operates blocks of 256 bits. So uint256 is natural size for in memory calculations. But I can't find in the documentation how it's applied to transactions and for storage. I ...
5
votes
2answers
652 views

Optimizing storage for an array of addresses

When possible, does Solidity optimize a storage array of address? For example, does address[8] take up 5 storage slots (160 bytes), or 8 storage slots? contract C { address[8] arr; } If 8 slots ...
3
votes
1answer
856 views

What optimizations does Geth's --jitvm do?

geth help has: VIRTUAL MACHINE OPTIONS: --jitvm Enable the JIT VM --forcejit Force the JIT VM to take precedence --jitcache "64" Amount of cached JIT VM programs What ...
21
votes
1answer
2k views

How does the solidity optimizer work?

The compiler for solidity supports the flag --optimize which performs some set of optimizations to the compiled solidity code, typically resulting in a reduction of gas costs. How does the optimizer ...
6
votes
2answers
561 views

Are there any best practices for optimizing computations?

As complex computations cost a lot of gas (sometimes more than actually forecasted), so are there any popular ways or techniques where I can optimize a complex computation to a simplified version of ...