Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for adding OpCode PUSH1BYTE and DUP3RD #3530

Open
Hecate2 opened this issue Oct 12, 2024 · 7 comments
Open

Suggestion for adding OpCode PUSH1BYTE and DUP3RD #3530

Hecate2 opened this issue Oct 12, 2024 · 7 comments
Labels
discussion Initial issue state - proposed but not yet accepted enhancement Type - Changes that may affect performance, usability or add new features to existing modules.

Comments

@Hecate2
Copy link
Contributor

Hecate2 commented Oct 12, 2024

Summary or problem description
For now we push 1 byte of data (typically for storage prefix) with PUSHDATA1 (priced 1<<3 GAS😰), which also has to include the length of data. This is a waste of time, storage and GAS.
Also, for operations involving 3 elements, we are always having trouble copying the 3rd element to the top of stack.

Do you have any solution you want to propose?
Add PUSH1BYTE = 0x06 that pushes 1 byte of ByteString to top of evaluation stack, at a GAS price of no more than LDLOC (1<<1), or preferrably 1<<0. This is for pushing 1-byte prefixes, often used in storage.
Add DUP3RD = 0x4C that copies the 3rd (with index 2) item to top of evaluation stack, at the same price of DUP and OVER (1<<1). This is for the convenience of operating 3 elements.
Of course they are just temporary names and byte assignments, and I am not in any hurry for any change to be made. My estimate is that, the marginal yield of PUSH1BYTE can be much higher than DUP3RD and many of the existing instructions. Maybe we can consider to include it after the next major release.

Where in the software does this update applies to?

  • Compiler
  • CLI
  • Plugins
  • SDK
  • VM
@Hecate2 Hecate2 added the discussion Initial issue state - proposed but not yet accepted label Oct 12, 2024
@Hecate2 Hecate2 changed the title Suggestion for adding OpCode Suggestion for adding OpCode PUSH1BYTE and DUP3RD Oct 12, 2024
@shargon
Copy link
Member

shargon commented Oct 13, 2024

I'm good with it, it will make cheaper the executions, it's good for all

@Jim8y
Copy link
Contributor

Jim8y commented Oct 14, 2024

e

If we decide this, maybe we can also have some V2 opcodes, for instance, POPITEM, APPEND, to avoid DUP, but directly peek the item and update the stackitem value.

@Jim8y Jim8y added this to the v3.9.0 milestone Oct 14, 2024
@Jim8y Jim8y added the enhancement Type - Changes that may affect performance, usability or add new features to existing modules. label Oct 14, 2024
@roman-khimov
Copy link
Contributor

Can be done, but not a priority to me, it's just an optimization and pretty minor one. It's not that we can't do something without some of these opcodes. And it needs to be evaluated against real contracts, different compilers, quite some work there.

@roman-khimov roman-khimov removed this from the v3.9.0 milestone Oct 14, 2024
@Jim8y
Copy link
Contributor

Jim8y commented Oct 14, 2024

v3.9 is already not priority, next big version is v3.8. can be removed when we really have to decide v3.9, otherwise this issue will be lost forever, and no one really care about it anymore.

@Jim8y Jim8y added this to the v3.9.0 milestone Oct 14, 2024
@Jim8y
Copy link
Contributor

Jim8y commented Oct 14, 2024

no plan for 3.9 yet, wont hurt anyone to mark it so that we can pick it up later.

@Jim8y Jim8y removed this from the v3.9.0 milestone Oct 14, 2024
@Jim8y
Copy link
Contributor

Jim8y commented Oct 14, 2024

Well, can be added to project as well.

@shargon
Copy link
Member

shargon commented Oct 14, 2024

For me is something that doesn't hurt anyone, it only improves, and we can add it without problems with the jumpTable now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Initial issue state - proposed but not yet accepted enhancement Type - Changes that may affect performance, usability or add new features to existing modules.
Projects
None yet
Development

No branches or pull requests

4 participants