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

Address reservation hook #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/backend/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ impl<'vicinity> Backend for MemoryBackend<'vicinity> {
self.state.contains_key(&address)
}

fn is_reserved(&self, _address: H160) -> bool {
false
}

fn basic(&self, address: H160) -> Basic {
self.state
.get(&address)
Expand Down
3 changes: 3 additions & 0 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub trait Backend {

/// Whether account at address exists.
fn exists(&self, address: H160) -> bool;
/// Whether it is disallowed to deploy contract at the specified address.
/// CREATE on the specified address will fail with CreateCollision.
fn is_reserved(&self, address: H160) -> bool;
/// Get basic account information.
fn basic(&self, address: H160) -> Basic;
/// Get account code.
Expand Down
10 changes: 4 additions & 6 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,10 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
self.enter_substate(gas_limit, false);

{
if self.code_size(address) != U256::zero() {
let _ = self.exit_substate(StackExitKind::Failed);
return Capture::Exit((ExitError::CreateCollision.into(), None, Vec::new()));
}

if self.nonce(address) > U256::zero() {
if self.state.is_reserved(address)
|| self.code_size(address) != U256::zero()
|| self.nonce(address) > U256::zero()
{
let _ = self.exit_substate(StackExitKind::Failed);
return Capture::Exit((ExitError::CreateCollision.into(), None, Vec::new()));
Copy link
Member

Choose a reason for hiding this comment

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

Might add a new ExitError variant.

}
Expand Down
4 changes: 4 additions & 0 deletions src/executor/stack/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ impl<'backend, 'config, B: Backend> Backend for MemoryStackState<'backend, 'conf
.unwrap_or_else(|| self.backend.code(address))
}

fn is_reserved(&self, address: H160) -> bool {
self.backend.is_reserved(address)
}

fn storage(&self, address: H160, key: H256) -> H256 {
self.substate
.known_storage(address, key)
Expand Down