Search in sources :

Example 26 with MessageFrame

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;
}
Also used : BlockHashLookup(org.hyperledger.besu.ethereum.vm.BlockHashLookup) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with 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);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame)

Example 28 with MessageFrame

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();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) JumpOperation(org.hyperledger.besu.evm.operation.JumpOperation) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) Test(org.junit.Test)

Example 29 with MessageFrame

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);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Test(org.junit.Test)

Example 30 with MessageFrame

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);
}
Also used : PrevRanDaoOperation(org.hyperledger.besu.evm.operation.PrevRanDaoOperation) LondonGasCalculator(org.hyperledger.besu.evm.gascalculator.LondonGasCalculator) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) BlockValues(org.hyperledger.besu.evm.frame.BlockValues) Operation(org.hyperledger.besu.evm.operation.Operation) PrevRanDaoOperation(org.hyperledger.besu.evm.operation.PrevRanDaoOperation) Bytes32(org.apache.tuweni.bytes.Bytes32) EVM(org.hyperledger.besu.evm.EVM) Test(org.junit.Test)

Aggregations

MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)73 Test (org.junit.Test)39 Bytes (org.apache.tuweni.bytes.Bytes)28 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)15 ArrayDeque (java.util.ArrayDeque)13 Wei (org.hyperledger.besu.datatypes.Wei)12 Code (org.hyperledger.besu.evm.Code)12 MessageFrameTestFixture (org.hyperledger.besu.ethereum.core.MessageFrameTestFixture)11 OperationResult (org.hyperledger.besu.evm.operation.Operation.OperationResult)11 UInt256 (org.apache.tuweni.units.bigints.UInt256)10 Address (org.hyperledger.besu.datatypes.Address)10 EVM (org.hyperledger.besu.evm.EVM)10 TraceFrame (org.hyperledger.besu.ethereum.debug.TraceFrame)9 Bytes32 (org.apache.tuweni.bytes.Bytes32)8 ContractCreationProcessor (org.hyperledger.besu.evm.processor.ContractCreationProcessor)8 BlockHashLookup (org.hyperledger.besu.ethereum.vm.BlockHashLookup)7 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)7 Hash (org.hyperledger.besu.datatypes.Hash)6 Block (org.hyperledger.besu.ethereum.core.Block)6 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)6