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

Allow specifying the caller in set_code function #291

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion interpreter/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ pub trait RuntimeBackend: RuntimeBaseBackend {
/// Fully delete storages of an account.
fn reset_storage(&mut self, address: H160);
/// Set code of an account.
fn set_code(&mut self, address: H160, code: Vec<u8>) -> Result<(), ExitError>;
fn set_code(
&mut self,
address: H160,
code: Vec<u8>,
caller: Option<H160>,
Copy link
Member

Choose a reason for hiding this comment

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

We should be specific here.

Rename this parameter to origin, and add a new enum SetCodeOrigin with two variants (Transaction, Subcall(caller)).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @sorpaas, thanks for your review! I already implemented the changes in bc0a9f9.

Let me know if something else is needed :)

) -> Result<(), ExitError>;
/// Reset balance of an account.
fn reset_balance(&mut self, address: H160);
fn deposit(&mut self, target: H160, value: U256);
Expand Down
7 changes: 6 additions & 1 deletion interpreter/tests/usability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ impl RuntimeBackend for UnimplementedHandler {
unimplemented!()
}

fn set_code(&mut self, _address: H160, _code: Vec<u8>) -> Result<(), ExitError> {
fn set_code(
&mut self,
_address: H160,
_code: Vec<u8>,
_caller: Option<H160>,
) -> Result<(), ExitError> {
unimplemented!()
}

Expand Down
7 changes: 6 additions & 1 deletion src/backend/overlayed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ impl<B: RuntimeBaseBackend> RuntimeBackend for OverlayedBackend<B> {
self.substate.storage_resets.insert(address);
}

fn set_code(&mut self, address: H160, code: Vec<u8>) -> Result<(), ExitError> {
fn set_code(
&mut self,
address: H160,
code: Vec<u8>,
_caller: Option<H160>,
) -> Result<(), ExitError> {
self.substate.codes.insert(address, code);
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions src/standard/invoker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ where
retbuf,
&mut substate,
handler,
None,
)?;

Ok(TransactValue::Create {
Expand Down Expand Up @@ -564,6 +565,7 @@ where
match trap_data {
SubstackInvoke::Create { address, trap } => {
let retbuf = retval;
let caller = trap.scheme.caller();

let result = result.and_then(|_| {
routines::deploy_create_code(
Expand All @@ -572,6 +574,7 @@ where
retbuf.clone(),
&mut substate,
handler,
Some(caller),
)?;

Ok(address)
Expand Down
3 changes: 2 additions & 1 deletion src/standard/invoker/routines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ pub fn deploy_create_code<'config, S, H>(
retbuf: Vec<u8>,
state: &mut S,
handler: &mut H,
caller: Option<H160>,
) -> Result<(), ExitError>
where
S: InvokerState<'config>,
Expand All @@ -212,7 +213,7 @@ where

state.record_codedeposit(retbuf.len())?;

handler.set_code(address, retbuf)?;
handler.set_code(address, retbuf, caller)?;

Ok(())
}