Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

evm: implement simple subroutine #11612

Closed
wants to merge 1 commit into from
Closed

Conversation

sorpaas
Copy link
Collaborator

@sorpaas sorpaas commented Apr 7, 2020

This is a draft of implementation of EIP-2315 (https://eips.ethereum.org/EIPS/eip-2315) simple subroutine. Code locations can be marked as subroutines, and opcodes are introduced to jump to it and return from it (via a newly-introduced "return stack").

rel https://github.com/openethereum/openethereum/issues/11562

@sorpaas sorpaas added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Apr 7, 2020
@ordian
Copy link
Member

ordian commented Apr 7, 2020

The return_stack is limited to 1023 items.

I think we should use a fixed-size array instead of a infinitely growable vec.

}
let jump = self.stack.pop_back();
if jump >= U256::from(usize::max_value()) {
return Err(vm::Error::InvalidSub)
Copy link
Member

Choose a reason for hiding this comment

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

why do we need a separate error type for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can use errors from JUMPDEST of course, but I think using separate error types is just more descriptive. It does not hurt anyway!

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I meant why not using BadSubDestination as we do return BadJumpDestination for verify_jump in such a case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm yeah you're right!

@@ -91,6 +109,27 @@ impl SharedCache {
jump_dests.shrink_to_fit();
Arc::new(jump_dests)
}

fn find_sub_destinations(code: &[u8]) -> Arc<BitSet> {
Copy link
Member

Choose a reason for hiding this comment

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

this function is used together with find_jump_destinations, so I guess it could be merge into one avoiding extra pass

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah you're right!

Comment on lines +47 to +51
impl MallocSizeOf for Dests {
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
self.jumpdests.size_of(ops) + self.subdests.size_of(ops)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

can't it be derived with #[derive(MallocSizeOf)]?

Comment on lines +324 to +329
#[doc = "Jump to a subrountine."]
JUMPSUB = 0xb3,
#[doc = "Begin a subrountine."]
BEGINSUB = 0xb5,
#[doc = "Return from a subrountine."]
RETURNSUB = 0xb7,
Copy link
Member

Choose a reason for hiding this comment

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

https://eips.ethereum.org/EIPS/eip-2315

We suggest the following opcodes:
0xb2 BEGINSUB
0xb3 JUMPSUB
0xb7 RETURNSUB

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, cc @gcolvin. What are the integer values of those opcodes? The one used in Geth PR and in the spec are different.

Copy link

Choose a reason for hiding this comment

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

@sorpaas I'm on the road, after midnight, on the road until midnight tomorrow, then I can check. @holiman might be able to shed some light.

Copy link
Member

Choose a reason for hiding this comment

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

@sorpaas I think we should follow the spec ethereum/go-ethereum#20619 (comment)

@niklasad1 niklasad1 changed the title evm: implement simple subrountine evm: implement simple subroutine Apr 8, 2020
@sorpaas
Copy link
Collaborator Author

sorpaas commented Apr 13, 2020

This PR will be superseded by a future one by @adria0!

@sorpaas sorpaas closed this Apr 13, 2020
@ordian ordian deleted the sp-simple-subroutine branch April 23, 2020 20:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants