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

[DO NOT MERGE]: EVM emulator #1142

Draft
wants to merge 202 commits into
base: release-v25-protocol-defense
Choose a base branch
from

Conversation

0xVolosnikov
Copy link

What ❔

Why ❔

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.

jrchatruc and others added 30 commits August 7, 2024 17:00
@0xVolosnikov 0xVolosnikov mentioned this pull request Dec 12, 2024
/// @dev Prefix for EVM contracts hashes storage slots.
uint256 private constant EVM_HASHES_PREFIX = 1 << 254;
/// @dev keccak256("ALLOWED_BYTECODE_TYPES_MODE_SLOT").
bytes32 private constant ALLOWED_BYTECODE_TYPES_MODE_SLOT =
Copy link
Member

Choose a reason for hiding this comment

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

IMO it is better to write to standard storage layout. Deprecation of variables isn't a concern. Bth my main concern would be making it simple and transparent with upgrades (all deprecated variables should be stored in the storage as a legacy, so no one ever will be confused and use the same storage slot for a different purpose)

// solhint-disable-next-line reason-string, gas-custom-errors
require(NONCE_HOLDER_SYSTEM_CONTRACT.getRawNonce(_newAddress) == 0x0);
// solhint-disable-next-line reason-string, gas-custom-errors
require(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.getCodeHash(uint256(uint160(_newAddress))) == 0x0);
Copy link
Member

Choose a reason for hiding this comment

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

Is it intended to be getCodeHash not getRawCodeHash?

Copy link
Author

Choose a reason for hiding this comment

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

getRawCodeHash would be better here indeed

Comment on lines +1136 to +1139
mstore(mul(10, 32), mload(sub(offset, 0x80))
mstore(mul(11, 32), mload(sub(offset, 0x60))
mstore(mul(12, 32), mload(sub(offset, 0x40))
mstore(mul(13, 32), mload(sub(offset, 0x20))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mstore(mul(10, 32), mload(sub(offset, 0x80))
mstore(mul(11, 32), mload(sub(offset, 0x60))
mstore(mul(12, 32), mload(sub(offset, 0x40))
mstore(mul(13, 32), mload(sub(offset, 0x20))
mstore(mul(10, 32), mload(sub(offset, 0x80)))
mstore(mul(11, 32), mload(sub(offset, 0x60)))
mstore(mul(12, 32), mload(sub(offset, 0x40)))
mstore(mul(13, 32), mload(sub(offset, 0x20)))

Copy link
Author

Choose a reason for hiding this comment

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

Interesting, compiler allows this


// Setting the version of the hash
hashedEVMBytecode = (hashedEVMBytecode | bytes32(uint256(EVM_BYTECODE_FLAG) << 248));
hashedEVMBytecode = hashedEVMBytecode | bytes32(_bytecode.length << 224);
Copy link
Member

Choose a reason for hiding this comment

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

Should it be ?

Suggested change
hashedEVMBytecode = hashedEVMBytecode | bytes32(_bytecode.length << 224);
hashedEVMBytecode = hashedEVMBytecode | bytes32(lengthInWords << 224);

Copy link
Author

Choose a reason for hiding this comment

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

Actually it should be length of unpadded EVM bytecode in bytes. This will make EXTCODESIZE implementation in Emulator a lot simpler. Right now this encoding in versioned bytecode hash (padded evm code length) actually doesn't make any sense

Copy link
Author

Choose a reason for hiding this comment

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

WIP: #1066

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.

10 participants