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

Implement EIP5656 MCOPY #2808

Merged
merged 7 commits into from
Jun 25, 2023
Merged

Implement EIP5656 MCOPY #2808

merged 7 commits into from
Jun 25, 2023

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Jun 21, 2023

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

TODOS:

To test against ethereum/tests: ensure ethereum/tests is on latest version of develop (so cd ./packages/ethereum-tests/ && git checkout develop && git pull).

Then, edit the cancun common to include EIP 5656. Now run the tests in vm:

npm run test:blockchain -- --fork=Cancun --dir=../EIPTests/BlockchainTests/StateTests/stEIP5656-MCOPY

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Merging #2808 (5701cad) into master (c51d81e) will increase coverage by 0.04%.
The diff coverage is 71.42%.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 89.13% <ø> (ø)
blockchain 92.50% <ø> (ø)
client 87.08% <ø> (-0.02%) ⬇️
common 97.10% <100.00%> (+<0.01%) ⬆️
devp2p 86.58% <ø> (ø)
ethash ?
evm 66.99% <70.00%> (+0.21%) ⬆️
rlp ∅ <ø> (?)
statemanager 86.35% <ø> (ø)
trie 90.05% <ø> (+0.36%) ⬆️
tx 95.97% <ø> (ø)
util 85.31% <ø> (ø)
vm 77.14% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Contributor

@scorbajio scorbajio left a comment

Choose a reason for hiding this comment

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

The code looks great! Just one piece seems to be missing.

// MCOPY
const [dst, src, length] = runState.stack.popN(3)
const data = runState.memory.read(Number(src), Number(length), true)
runState.memory.write(Number(dst), Number(length), data)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like write will throw in the case of writing beyond memory length, but the EIP semantics expects this case automatically handled with extra gas accounted for: If length > 0 and (src + length or dst + length) is beyond the current memory length, the memory is extended with respective gas cost applied.

Also see the write function: if (offset + size > this._store.length) throw new Error('Value exceeds memory capacity')

Copy link
Contributor

Choose a reason for hiding this comment

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

An example test case wasn't provided either. Maybe we could add one for it as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for this comment! Note that in write, we also call extend in memory. I am rather sure (and I think I once introduced this) is that this explicit error check is added as a precaution. However, I doubt this can ever happen.

( see memory.ts line 55: this.extend(offset, size), this extends memory prior to writing)

(The unit tests absolutely do not cover all the cases. I have introduced them for completeness since these are in the EIP. However, EIP authors have written tests: ethereum/tests#1229 which we pass)

@jochem-brouwer
Copy link
Member Author

We pass these as well: ethereum/tests#1234

Copy link
Contributor

@scorbajio scorbajio left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants