use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.
the class CreateOperationTest method testMemoryFrame.
@NotNull
private MessageFrame testMemoryFrame(final UInt256 memoryOffset, final UInt256 memoryLength, final UInt256 value, final int depth, final ArrayDeque<MessageFrame> messageFrameStack) {
final MessageFrame messageFrame = MessageFrame.builder().type(MessageFrame.Type.CONTRACT_CREATION).contract(Address.ZERO).inputData(Bytes.EMPTY).sender(Address.fromHexString(SENDER)).value(Wei.ZERO).apparentValue(Wei.ZERO).code(Code.createLegacyCode(SIMPLE_CREATE, Hash.hash(SIMPLE_CREATE))).depth(depth).completer(__ -> {
}).address(Address.fromHexString(SENDER)).blockHashLookup(mock(BlockHashLookup.class)).blockValues(mock(ProcessableBlockHeader.class)).gasPrice(Wei.ZERO).messageFrameStack(messageFrameStack).miningBeneficiary(Address.ZERO).originator(Address.ZERO).initialGas(100000L).worldUpdater(worldUpdater).build();
messageFrame.pushStackItem(memoryLength);
messageFrame.pushStackItem(memoryOffset);
messageFrame.pushStackItem(value);
messageFrame.expandMemory(0, 500);
messageFrame.writeMemory(memoryOffset.trimLeadingZeros().toInt(), SIMPLE_CREATE.size(), SIMPLE_CREATE);
return messageFrame;
}
use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.
the class ExtCodeHashOperationTest method executeOperation.
private Bytes executeOperation(final Address requestedAddress) {
final MessageFrame frame = createMessageFrame(requestedAddress);
operation.execute(frame, null);
return frame.getStackItem(0);
}
use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.
the class JumpOperationTest method longContractsValidate.
@Test
public void longContractsValidate() {
final JumpOperation operation = new JumpOperation(gasCalculator);
final Bytes longCode = Bytes.fromHexString("0x60006000351461001157600050610018565b6101016020525b60016000351461002a5760005061002f565b326020525b60026000351461004157600050610046565b336020525b6003600035146100585760005061005d565b306020525b60046000351461006f57600050610075565b60016020525b60005160005260006020351461008d576000506100b6565b5a600052602051315060165a60005103036000555a600052602051315060165a60005103036001555b6001602035146100c8576000506100f1565b5a6000526020513b5060165a60005103036000555a6000526020513b5060165a60005103036001555b6002602035146101035760005061012c565b5a6000526020513f5060165a60005103036000555a6000526020513f5060165a60005103036001555b60036020351461013e5760005061017a565b6106a5610100525a600052602060006101006020513c60205a60005103036000555a600052602060006101006020513c60205a60005103036001555b00");
final MessageFrame longContract = createMessageFrameBuilder(100L).pushStackItem(UInt256.fromHexString("0x12c")).code(Code.createLegacyCode(longCode, Hash.hash(longCode))).build();
longContract.setPC(255);
final OperationResult result = operation.execute(longContract, evm);
assertThat(result.getHaltReason()).isEmpty();
}
use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.
the class LondonSStoreOperationGasCostTest method shouldCalculateGasAccordingToEip3529.
@Test
public void shouldCalculateGasAccordingToEip3529() {
final long gasLimit = 1_000_000;
final MessageFrame frame = codeExecutor.executeCode(code, gasLimit, account -> account.setStorageValue(UInt256.ZERO, UInt256.valueOf(originalValue)));
assertThat(frame.getState()).isEqualTo(State.COMPLETED_SUCCESS);
assertThat(frame.getRemainingGas()).isEqualTo(gasLimit - (expectedGasUsed + 2100));
assertThat(frame.getGasRefund()).isEqualTo(expectedGasRefund);
}
use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.
the class PrevRanDaoOperationTest method pushesPrevRandaoWhenDifficultyZero.
@Test
public void pushesPrevRandaoWhenDifficultyZero() {
PrevRanDaoOperation op = new PrevRanDaoOperation(new LondonGasCalculator());
MessageFrame messageFrame = mock(MessageFrame.class);
BlockValues blockHeader = mock(BlockValues.class);
Bytes32 prevRandao = Bytes32.fromHexString("0xb0b0face");
when(blockHeader.getDifficultyBytes()).thenReturn(UInt256.ZERO);
when(blockHeader.getMixHashOrPrevRandao()).thenReturn(prevRandao);
when(messageFrame.getBlockValues()).thenReturn(blockHeader);
EVM evm = mock(EVM.class);
Operation.OperationResult r = op.executeFixedCostOperation(messageFrame, evm);
assertThat(r.getHaltReason()).isNotPresent();
verify(messageFrame).pushStackItem(prevRandao);
}
Aggregations