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

EVM: fix EXTCODE_ ops #870

Merged
merged 16 commits into from
Dec 1, 2022
Merged

EVM: fix EXTCODE_ ops #870

merged 16 commits into from
Dec 1, 2022

Conversation

mriise
Copy link
Contributor

@mriise mriise commented Nov 24, 2022

@mriise mriise changed the title wip fixes EVM: fix EXTCODE_ ops Nov 24, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2022

Codecov Report

Merging #870 (95d4db2) into next (5a4b15b) will increase coverage by 0.12%.
The diff coverage is 93.91%.

❗ Current head 95d4db2 differs from pull request most recent head 9026da0. Consider uploading reports for the commit 9026da0 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             next     #870      +/-   ##
==========================================
+ Coverage   87.10%   87.23%   +0.12%     
==========================================
  Files         126      127       +1     
  Lines       23278    23677     +399     
==========================================
+ Hits        20276    20654     +378     
- Misses       3002     3023      +21     
Impacted Files Coverage Δ
actors/market/src/ext.rs 100.00% <ø> (ø)
actors/paych/src/state.rs 100.00% <ø> (ø)
actors/verifreg/src/types.rs 100.00% <ø> (ø)
runtime/src/actor_error.rs 76.74% <ø> (+2.32%) ⬆️
actors/power/src/state.rs 83.49% <77.27%> (+4.73%) ⬆️
actors/evm/src/interpreter/instructions/mod.rs 81.48% <81.25%> (-0.96%) ⬇️
actors/miner/src/lib.rs 83.26% <84.94%> (-0.16%) ⬇️
runtime/src/test_utils.rs 81.35% <85.71%> (+0.19%) ⬆️
actors/evm/src/interpreter/execution.rs 86.36% <87.50%> (-2.17%) ⬇️
actors/evm/src/interpreter/instructions/call.rs 83.25% <87.50%> (-0.32%) ⬇️
... and 37 more

@mriise mriise requested review from Stebalien and raulk November 28, 2022 23:44
@mriise
Copy link
Contributor Author

mriise commented Nov 28, 2022

just need to fix tests

@mriise mriise marked this pull request as ready for review November 29, 2022 00:29
@mriise
Copy link
Contributor Author

mriise commented Nov 29, 2022

tests implemented! review time :)

Comment on lines 117 to 120
let actor_id = rt.resolve_address(&addr).ok_or_else(|| {
StatusCode::InvalidArgument("failed to resolve address".to_string())
StatusCode::InvalidArgument("EVM EXT opcode failed to resolve address".to_string())
// TODO better error code
})?;
Copy link
Member

Choose a reason for hiding this comment

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

This should return empty bytecode.

Copy link
Member

Choose a reason for hiding this comment

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

That is, by definition, all actors that don't exist have empty bytecode (in the EVM).

@Stebalien Stebalien requested a review from vyzo November 30, 2022 02:29
vyzo
vyzo previously requested changes Nov 30, 2022
Copy link
Contributor

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

What are all these unrelated changes?

Please remove them from this pr.

Copy link
Contributor

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

the relevant parts look ok at first glance however.

@vyzo
Copy link
Contributor

vyzo commented Nov 30, 2022

Also, and this is important, please dont change toolchain like this in a totally irrelevant pr.

This is an important change that should be its own pr.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Couple of small nits remaining. I made some larger changes because it was difficult to review this patch due to the added indentation and deep indentation (see the changes I pushed).

let raw_bytecode = rt
.store()
.get(cid) // TODO this is inefficient; should call stat here.
.get(&cid) // TODO this is inefficient; should call stat here.
Copy link
Member

Choose a reason for hiding this comment

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

This is fine. Note: we don't actually ever expect this error as it should be impossible.

pub fn get_cid_type(rt: &impl Runtime, addr: U256) -> CodeCid {
let addr: EthAddress = addr.into();

addr.try_into()
Copy link
Member

Choose a reason for hiding this comment

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

I flattened this to make it easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ty

)
}
// If we're calling an account or a non-existent actor, return nothing because
// this is how the EVM behaves.
Copy link
Member

Choose a reason for hiding this comment

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

I changed this to return "ok" in these cases.

TokenAmount::from(&value),
)
}
CallKind::DelegateCall => match get_cid_type(system.rt, dst) {
Copy link
Member

Choose a reason for hiding this comment

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

I removed the closure/return. We didn't need them.

Generally speaking, jumping like that is a "last resort" kind of thing as it can make code really hard to follow. It also increases diffs by changing indent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah diff was gross for sure. In all honesty this method ended up a lot cleaner than i was thinking (idk what i was thinking tbh). I probably should've given it at least a few minutes of poking before dismissing it as unfeasible.

Copy link
Contributor

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

The important parts look good now, but we probably want to address steven's remarks before merging.

.map(|bytecode| bytecode.len())?;
let len = match get_cid_type(system.rt, addr) {
CodeCid::EVM(addr) => get_evm_bytecode(system.rt, &addr).map(|bytecode| bytecode.len())?,
CodeCid::Native(_) => 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

why 1?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, 0xfe below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, but has more to do with playing nicely with solidity's behavior of isContract

@vyzo
Copy link
Contributor

vyzo commented Dec 1, 2022

Can we wait for #885 before merging?

@vyzo
Copy link
Contributor

vyzo commented Dec 1, 2022

I mean we already have conflicts, and it will certainly create more with 885.

@Stebalien Stebalien enabled auto-merge (squash) December 1, 2022 18:28
@Stebalien Stebalien merged commit 49f927c into next Dec 1, 2022
@Stebalien Stebalien deleted the fix/codesize-op branch December 1, 2022 18:50
raulk pushed a commit that referenced this pull request Dec 2, 2022
* wip fixes

* cleanup implementation

* return 0 for non existient address in extcodesize

* use enum instead of result result maddness

* fmt & cleanup some logic

* update tests for the remaining two ext opcodes

* redo logic to make things a bit more clearn

* fix bugs & keep bytecode logic seperate, verify expectations before asserting for better debugging help

* add another test case for ext op

* use closure for early return

* nit: reduce indentation

* fix: formatting

* remove unnecessary closure

* fix: make delegatecall behave more like the EVM

- address todo
- use the new get_cid_type

* fix some review nits

Co-authored-by: Steven Allen <steven@stebalien.com>
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.

5 participants