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

feat: EIP-1153 Transient storage opcodes #546

Merged
merged 5 commits into from
Aug 3, 2023
Merged

Conversation

tynes
Copy link
Contributor

@tynes tynes commented Jul 7, 2023

Implement EIP-1153 for the Cancun hardfork

The changes to the specs in this PR I'd like some feedback on, happy to revert things that aren't directly related to the EIP implementation

Need to update the opcode numbers before this PR is ready, they are still on the older values

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

Closes #154

Implement EIP-1153 for the Cancun hardfork.
@rakita rakita changed the title feat: EIP-1153 feat: EIP-1153 Transient storage opcodes Jul 10, 2023
pub fn tload<H: Host, SPEC: Spec>(interpreter: &mut Interpreter, host: &mut H) {
gas!(interpreter, gas::WARM_STORAGE_READ_COST);

pop!(interpreter, index);
Copy link
Member

Choose a reason for hiding this comment

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

you can use pop_top! here and you set tload value to it.

use crate::primitives::{B160, U256};
use std::collections::HashMap;

#[derive(Debug, Clone, Eq, PartialEq)]
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to add docs

}

pub fn set(&mut self, address: B160, key: U256, value: U256) {
match self.data.get_mut(&address) {
Copy link
Member

Choose a reason for hiding this comment

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

You can use simpler form with entry. something like self.data.entry(&dadress).or_default().insert(key,value)

}

pub fn get(&self, address: B160, key: U256) -> U256 {
match self.data.get(&address) {
Copy link
Member

Choose a reason for hiding this comment

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

Better way i to use and_then. Something like self.data.get(&address).and_then(|s| s.get(&key)).cloned().unwrap_or_default()

@@ -196,7 +196,6 @@ pub fn evm_inner<'a, DB: Database, const INSPECT: bool>(
}
SpecId::MERGE => create_evm!(MergeSpec, db, env, insp),
SpecId::SHANGHAI => create_evm!(ShanghaiSpec, db, env, insp),
SpecId::CANCUN => create_evm!(LatestSpec, db, env, insp),
SpecId::LATEST => create_evm!(LatestSpec, db, env, insp),
SpecId::CANCUN | SpecId::LATEST => create_evm!(LatestSpec, db, env, insp),
Copy link
Member

Choose a reason for hiding this comment

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

LATEST should be LatestSpec, Cancun should have its own spec

@@ -657,6 +690,23 @@ impl JournaledState {
Ok((slot.original_value, present, new, is_cold))
}

pub fn tstore(&mut self, address: B160, key: U256, new: U256) {
let present = self.tload(address, key);
Copy link
Member

Choose a reason for hiding this comment

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

We are not calling tstore anywhere

key,
had_value,
} => {
transient_storage.set(address, key, had_value.unwrap());
Copy link
Member

Choose a reason for hiding this comment

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

If had_value is None we should remove the entry from transient storage.

@@ -2,6 +2,7 @@ pub mod analysis;
mod contract;
pub(crate) mod memory;
mod stack;
pub mod transient;
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to have full name transient_storage

Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

Left few comments

@rakita rakita marked this pull request as ready for review July 28, 2023 12:17
@rakita
Copy link
Member

rakita commented Jul 28, 2023

@tynes can you double check this, made some changes and imo is ready to be merged.

Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

lgtm

@tynes
Copy link
Contributor Author

tynes commented Aug 1, 2023

Thank you for picking this up @rakita. For test coverage, do you think using the Ethereum state tests are sufficient?

The implementation looks good to me, looks much more idiomatic than before

@rakita
Copy link
Member

rakita commented Aug 3, 2023

Thank you for picking this up @rakita. For test coverage, do you think using the Ethereum state tests are sufficient?

The implementation looks good to me, looks much more idiomatic than before

using eth tests should be sufficient to cover edge cases

@rakita rakita merged commit 06b1f6b into bluealloy:main Aug 3, 2023
@tynes tynes deleted the feat/1153 branch August 4, 2023 17:07
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.

EIP-1153: Transient storage opcodes
2 participants