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

Unlimited SWAP and DUP instructions #663

Merged
merged 3 commits into from
Mar 8, 2019

Conversation

axic
Copy link
Member

@axic axic commented Jul 3, 2017

No description provided.

@axic axic force-pushed the unlimited-swapdup branch 3 times, most recently from 76b75a1 to 1a2ce5f Compare July 3, 2017 20:15
@axic
Copy link
Member Author

axic commented Jul 4, 2017

Alternatively to ease verification, the parameter to SWAPn / DUPn could be:

  • force that a PUSH is present before them
  • have an immediate value (2 bytes, to accommodate the value 1024) instead of a PUSH

@axic
Copy link
Member Author

axic commented Jul 28, 2017

To clarify, the "immediate value" option would mean an encoding 0xb0 0xNN 0xNN for DUP and 0bx1 0xNN 0xNN for SWAP, just like how PUSH works.

@axic
Copy link
Member Author

axic commented Jul 29, 2017

Sorry haven't seen the issue #174 which proposes the same.

@gcolvin
Copy link
Contributor

gcolvin commented Jul 29, 2017

I still think that if #615 is accepted this will be unnecessary.

EIPS/draft_unlimited_swapdup.md Outdated Show resolved Hide resolved

Instructions `DUPn` (`0xb0`) and `SWAPn` (`0xb1`) are introduced, which take the top item from stack (referred to as `n`).

If `n` exceeds 1024 or the current stack depth is less than `n`, then a stack underflow exception is issued. If the current stack depth is at the limit, a stack overflow exception is issued.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a stack underflow exception is issued, what should happen to the contract execution? Would it be equivalent to REVERT with a certain output?

Does it ever happen that the stack depth is still at the limit after popping n?

- for `DUPn` the stack item at depth `n` is duplicated at the top of the stack
- for `SWAPn` the top stack item is swapped with the item at depth `n`

The gas cost for both instructions is set at 3. In reality the cost for such an operation is 6 including the required `PUSH`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cost can be smaller than 6 per operation. In fact the cost can be very close to 3. For example,

PUSH1 0
PUSH1 0
DUPn
DUPn
DUPn
DUPn
DUPn
DUPn
DUPn
...

@Arachnid
Copy link
Contributor

This is a courtesy notice to let you know that the format for EIPs has been modified slightly. If you want your draft merged, you will need to make some small changes to how your EIP is formatted:

  • Frontmatter is now contained between lines with only a triple dash ('---')
  • Headers in the frontmatter are now lowercase.

If your PR is editing an existing EIP rather than creating a new one, this has already been done for you, and you need only rebase your PR.

In addition, a continuous build has been setup, which will check your PR against the rules for EIP formatting automatically once you update your PR. This build ensures all required headers are present, as well as performing a number of other checks.

Please rebase your PR against the latest master, and edit your PR to use the above format for frontmatter. For convenience, here's a sample header you can copy and adapt:

---
eip: <num>
title: <title>
author: <author>
type: [Standards Track|Informational|Meta]
category: [Core|Networking|Interface|ERC] (for type: Standards Track only)
status: Draft
created: <date>
---

@axic axic force-pushed the unlimited-swapdup branch from 1a2ce5f to ee845e5 Compare March 1, 2019 17:42
@axic axic force-pushed the unlimited-swapdup branch from ee845e5 to de89e89 Compare March 1, 2019 17:54
@axic
Copy link
Member Author

axic commented Mar 1, 2019

Updated to satisfy draft requirements.

@nicksavers nicksavers merged commit 7609231 into ethereum:master Mar 8, 2019
@MrChico
Copy link
Member

MrChico commented Apr 20, 2019

It seems a lot easier to do stack analysis if the would be arguments inlined in the code, rather than taken off the stack. That would also play better with #615 .

@axic axic deleted the unlimited-swapdup branch April 23, 2019 14:00
@axic
Copy link
Member Author

axic commented May 17, 2019

It seems a lot easier to do stack analysis if the would be arguments inlined in the code, rather than taken off the stack.

This option was also proposed, see #663 (comment) and #663 (comment).

Changed the EIP to explicitly list both options (in #2038).

@axic
Copy link
Member Author

axic commented Jun 2, 2019

ilanolkies pushed a commit to ilanolkies/EIPs that referenced this pull request Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants