Solidity: Document costs of various types.

Created on 11 May 2018  Â·  25Comments  Â·  Source: ethereum/solidity

Does it cost any gas to cast a bytes32 memory value to uint256? What is the assembly op code for this?

Does it cost more gas to use =, >, <. operators with bytes32 than it does with uint256?

Spreadsheets about gas costs say it cost 3 gas for =, >, < operations, so is that true with all types that support those operators? Or is the gas cost for these operators different depending on the type?

I tested some of these things in remix and got mixed results -- sometimes it cost more gas, sometimes less.

Does it make any sense to cast bytes32 to unint256 for doing an operation like this: require(uint256(myvalue) != 0);

If you know the answers to these, can you please tell me how you know?

bounty worthy easy documentation help wanted

Most helpful comment

@itsN1X Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

All 25 comments

In general, bytes32 and uint256 are mostly equivalent with regards to gas and I'm actually surprised you got different results. Did you change the function signature somewhere?

Yes, my two test functions have different names.

From my investigation it seems that there is a gas cost to cast a value if the cast changes the size of the value.

For instance casting bytes32 to uint256 does not cost gas because they are the same size. I wish there were a list of rules about these things somewhere that was easy to read.

Using an operator such as =,>,< will cost more gas if a cast needs to happen for the operation to occur and the cast causes one of the arguments to change size.

Yes, some guidelines about the costs of various types should be added to the documentation.

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


__This issue now has a funding of 0.09 ETH (63.77 USD @ $708.52/ETH) attached to it.__

@chriseth , I had to have a few things debriefed:
Like,

  • [ ] : Type of format for /docs
    e.g., Jekyll, Pandoc, rtm, PDF, html, etc.
  • [ ] : Level of detailing:
    e.g.: I'm planning on covering all opcodes, with child --heads on each /dataType.
    Also, what all are the checkboxes I must tick?

My basic reference is the spresdsheet .1 from the wikipedia footnotes on its eth page.
i.e. .30, .32, and the one tagged in this issue.

Anything , or everything else you'd want me to know?
Any better citations, sources?
Also, my /ETA for the v0.0.1 draft shall be 100,000secs, from now.

cc/ @vs77bb
tysm!
~N1X

@itsN1X this was more meant to be a high level description of the tradeoffs of different types with respect to gas, and not a detailed table with costs per opcode (although that could also be beneficial), since users usually do not know how they code is translated into opcodes (and I guess this is also where most confusion with regards to gas comes from).

Oh and please don't use the spreadsheet but for example an implementation of a compliant client or the yellowpaper.

@itsN1X Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@gitcoinbot Yep, still here! W-I-P.

@itsN1X. :wave: thanks for the atMention, but you need to install @gitcoinbot on this repo for me to be able to respond. More details in the documentation.

:v:
@gitcoinbot

@itsN1X Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


@itsN1X due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

  • [x] warning (3 days)
  • [x] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Hi @itsN1X, would you mind linking to the WIP PR so we know where this issue is?

I have a small wiki I made for self reference that I plan to convert to a online manual. Would require another week to get everything finished.

@itsN1X Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


@itsN1X due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

  • [x] warning (3 days)
  • [x] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Hi @itsN1X do you have any update here? If not, we'll plan to send this back out to 'Open' status. Hope you're doing well!

I'm really sorry for being shoddy in my communications, my bad!
Personally, examinationseason at the University has been taxing much.
I humbly request the Funders to allow me a deadline till 2.7, after which the issue may be re-opened.
Prepared a wireframe for this, hope to get a working prototype soon.
tysm for all the patience,
I apologize for the uncontrollable delays.

@itsN1X Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

I'll upload.

Yes, expire me at 07-07-2018 iff I don't pull-in.

@14BME0133

@itsN1X Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Issue Status: 1. Open 2. Cancelled


__The funding of 0.09 ETH (30.83 USD @ $342.6/ETH) attached to this issue has been cancelled by the bounty submitter__

Yes, some guidelines about the costs of various types should be added to the documentation.

Possibly this should be moved to a new issue.

"bounty" label should be removed

$I need someone to co-do-it ... Please feel free to drop by to team up ( :

@itsN1X I'm happy to help you with this, I am working with the Solidity team on docs, so don't need any GitCoin contributions, but more to help you with submitting a PR, reviewing etc. Let me know if you need anything.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chriseth picture chriseth  Â·  3Comments

area picture area  Â·  3Comments

walter-weinmann picture walter-weinmann  Â·  4Comments

kkagill picture kkagill  Â·  4Comments

madvas picture madvas  Â·  3Comments