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

EIP-2315: update jumpsub gascost and add back testcases #2669

Merged
merged 1 commit into from May 26, 2020

Conversation

holiman
Copy link
Contributor

@holiman holiman commented May 25, 2020

This PR

  • Adds back a testcase that went missing (walk into subroutine) in struggling with travis #2662
  • Fixes another testcase where BEGINSUB was present,
  • Changes cost of JUMPSUB to 8.

I'm marking this as draft since otherwise the trigger-happy autobot will merge it. Can I please get a thumb up from:

@gcolvin , @ordian (or @sorpaas , or @vorot93 ?), @makt

Just want to make sure everyone is on the same page here...

Copy link

@ordian ordian left a comment

Choose a reason for hiding this comment

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

👍

| 4 | RETURNSUB | 2 | [] | [ 8] |
| 9 | STOP | 0 | [] | [] |

Consumed gas: `26`
Copy link

Choose a reason for hiding this comment

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

why was it 26 before, a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was because it executed a BEGINSUB. See https://github.com/ethereum/EIPs/pull/2656/files#diff-4568ebb9120e779b93e457d3926c14d6L152 . The changes made it not do the BEGINSUB. And after that commit, Greg did some changes and it got reverted back to 26 again.

Copy link

Choose a reason for hiding this comment

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

@holiman Is this 2 gas cost for RETURNSUB ok? In the specification says VeryLow that AFAIK is 3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh my god. Yeah 2 is base.
I don't see why RETURNSUB should be so cheap. I'd actually prefer it to be same as JUMPSUB -- or, more specifically, that cost of(JUMPSUB+RETURNSUB) == cost of (JUMP + JUMP). Which currently would put it at mid == 8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@axic thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

JUMPSUB inserts into returnstack, whereas RETURNSUB pops one. The popped value does not need to be validated (but a length-check is needed on the returnstack)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, what I meant is that JUMPSUB inserts into the return stack (needs to check for stack overflow) and RETUNRSUB needs to pop from the stack (needs to check for stack underflow).

Neither of them validate the content nor does JUMP, but JUMP is not growing any stacks.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@holiman holiman May 26, 2020

Choose a reason for hiding this comment

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

Right. I'd compare JUMPSUB with JUMPI. JUMPI pops an item from a stack, does a check, then a jump. It costs 10.
So one might argue that both JUMPSUB and RETURNSUB should be 10. But having RETURNSUB at 8 would also be sensible, IMO. It might be good to not make subroutines too expensive, so that optimizers replace it all with jumps in the end anyway... Actually, since RETURNSUB does not have to validate the destination (check the opcode at destination + check if destination is code), it could be lower, so the two together are 16.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I was in the mindset JUMPSUB analysis happens prior to execution, but strictly looking at the spec, it is not. Following that logic indeed RETURNSUB should be cheaper as it does no validation.

However even if both would be set at 10 and thus higher than JUMP, they would still be cheaper given the return address doesn't need to be pushed and no need for stack rotation if there are return values, which is the case for current "subroutines via jump".

@holiman holiman marked this pull request as ready for review May 26, 2020 07:57
@holiman holiman merged commit 57c863d into ethereum:master May 26, 2020
pizzarob pushed a commit to pizzarob/EIPs that referenced this pull request Jun 12, 2020
tkstanczak pushed a commit to tkstanczak/EIPs that referenced this pull request Nov 7, 2020
Arachnid pushed a commit to Arachnid/EIPs that referenced this pull request Mar 6, 2021
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.

None yet

5 participants