-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add a way to read memory without altering the word capacity #6073
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3280055
feat: add a way to read memory without altering the word capacity
delehef 649e99f
add tests
daniellehrner c2950d8
Fix read-past-end
delehef ecf412e
Do not abuse method overload
delehef 41270df
Update CHANGELOG.md
delehef c2a8444
add tests for MessageFrame.shadowReadMemory
daniellehrner 9441277
Straddled reads tests
delehef fa34066
Merge branch 'main' into shadow-read
delehef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
evm/src/test/java/org/hyperledger/besu/evm/frame/MessageFrameTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * Copyright Hyperledger Besu Contributors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.hyperledger.besu.evm.frame; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.hyperledger.besu.datatypes.Address; | ||
| import org.hyperledger.besu.datatypes.Hash; | ||
| import org.hyperledger.besu.datatypes.Wei; | ||
| import org.hyperledger.besu.evm.code.CodeV0; | ||
| import org.hyperledger.besu.evm.toy.ToyBlockValues; | ||
| import org.hyperledger.besu.evm.toy.ToyWorld; | ||
|
|
||
| import org.apache.tuweni.bytes.Bytes; | ||
| import org.apache.tuweni.bytes.Bytes32; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class MessageFrameTest { | ||
|
|
||
| private static final Bytes32 WORD1 = Bytes32.fromHexString(Long.toString(1).repeat(64)); | ||
| private static final Bytes32 WORD2 = Bytes32.fromHexString(Long.toString(2).repeat(64)); | ||
|
|
||
| private MessageFrame.Builder messageFrameBuilder; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| messageFrameBuilder = | ||
| MessageFrame.builder() | ||
| .worldUpdater(new ToyWorld()) | ||
| .originator(Address.ZERO) | ||
| .gasPrice(Wei.ONE) | ||
| .blobGasPrice(Wei.ONE) | ||
| .blockValues(new ToyBlockValues()) | ||
| .miningBeneficiary(Address.ZERO) | ||
| .blockHashLookup((l) -> Hash.ZERO) | ||
| .type(MessageFrame.Type.MESSAGE_CALL) | ||
| .initialGas(1) | ||
| .address(Address.ZERO) | ||
| .contract(Address.ZERO) | ||
| .inputData(Bytes32.ZERO) | ||
| .sender(Address.ZERO) | ||
| .value(Wei.ZERO) | ||
| .apparentValue(Wei.ZERO) | ||
| .code(CodeV0.EMPTY_CODE) | ||
| .completer(messageFrame -> {}); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotExpandMemory() { | ||
| final MessageFrame messageFrame = messageFrameBuilder.build(); | ||
|
|
||
| final Bytes value = Bytes.concatenate(WORD1, WORD2); | ||
| messageFrame.writeMemory(0, value.size(), value); | ||
| int initialActiveWords = messageFrame.memoryWordSize(); | ||
|
|
||
| // Fully in bounds read | ||
| assertThat(messageFrame.shadowReadMemory(64, Bytes32.SIZE)).isEqualTo(Bytes32.ZERO); | ||
| assertThat(messageFrame.memoryWordSize()).isEqualTo(initialActiveWords); | ||
|
|
||
| // Straddling read | ||
| final Bytes straddlingRead = messageFrame.shadowReadMemory(50, Bytes32.SIZE); | ||
| assertThat(messageFrame.memoryWordSize()).isEqualTo(initialActiveWords); | ||
| assertThat(straddlingRead.get(0)).isEqualTo((byte) 0x22); // Still in WORD2 | ||
| assertThat(straddlingRead.get(13)).isEqualTo((byte) 0x22); // Just before uninitialized memory | ||
| assertThat(straddlingRead.get(14)).isEqualTo((byte) 0); // Just in uninitialized memory | ||
| assertThat(straddlingRead.get(20)).isEqualTo((byte) 0); // In uninitialized memory | ||
|
|
||
| // Fully out of bounds read | ||
| assertThat(messageFrame.shadowReadMemory(64, Bytes32.SIZE)).isEqualTo(Bytes32.ZERO); | ||
| assertThat(messageFrame.memoryWordSize()).isEqualTo(initialActiveWords); | ||
|
|
||
| assertThat(messageFrame.shadowReadMemory(32, Bytes32.SIZE)).isEqualTo(WORD2); | ||
| assertThat(messageFrame.memoryWordSize()).isEqualTo(initialActiveWords); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.