-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement Simple Subroutines for the EVM (EIP 2315) #11629
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some parts are missing like
https://github.com/openethereum/openethereum/pull/11612/files#diff-62a9081304c809673d1a737d1a3d469eR605-R607
Co-Authored-By: Andronik Ordian <[email protected]>
Co-Authored-By: Andronik Ordian <[email protected]>
Co-Authored-By: Andronik Ordian <[email protected]>
Co-Authored-By: Andronik Ordian <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo one unresolved question.
Co-Authored-By: Andronik Ordian <[email protected]>
/// Global cache for EVM interpreter | ||
pub struct SharedCache { | ||
jump_destinations: Mutex<MemoryLruCache<H256, Bits>>, | ||
jump_destinations: Mutex<MemoryLruCache<H256, CacheItem>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not in scope for this PR but I don't think the Mutex
is necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM just a slight thing that I think can be improved in the future. Mark this as mustn'tgrumble!
@@ -412,6 +422,21 @@ impl<Cost: CostType> Interpreter<Cost> { | |||
}; | |||
self.reader.position = pos; | |||
}, | |||
InstructionResult::JumpToSubroutine(position) => { | |||
if self.valid_subroutine_destinations.is_none() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we fetch valid_subrountine_destinations
, we can set valid_jump_destinations
at the same time, and vice versa, because those two values are always computed at the same time. Should slightly improve performance.
@@ -586,6 +592,9 @@ lazy_static! { | |||
arr[LOG2 as usize] = Some(InstructionInfo::new("LOG2", 4, 0, GasPriceTier::Special)); | |||
arr[LOG3 as usize] = Some(InstructionInfo::new("LOG3", 5, 0, GasPriceTier::Special)); | |||
arr[LOG4 as usize] = Some(InstructionInfo::new("LOG4", 6, 0, GasPriceTier::Special)); | |||
arr[BEGINSUB as usize] = Some(InstructionInfo::new("BEGINSUB", 0, 0, GasPriceTier::Base)); | |||
arr[JUMPSUB as usize] = Some(InstructionInfo::new("JUMPSUB", 1, 0, GasPriceTier::Low)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm mistaken, both geth and besu used mid
(8) for JUMPSUB
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We followed the suggestion from the spec
We suggest that the cost of JUMPSUB be low, and RETURNSUB be verylow. Measurement will tell.
Is there any reason why geth and besu chose mid
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original geth-PR from Greg used that value, and then we didn't change it when the EIP was updated at some point. IMO it makes zero sense to have JUMPSUB
be cheaper than JUMP
, considering that JUMPSUB
causes a memory allocation in the returnstack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL: ethereum/EIPs#2669
Created this PR https://github.com/openethereum/openethereum/pull/11731 for updates to the EIP |
This PR implements Simple Subroutines for the EVM (EIP 2315).
The code was written by @adria0 with my assistance and also guidance by @sorpaas during a live coding session on Monday. It should be functional but may require some cleanup.