Search in sources :

Example 6 with BlockValues

use of org.hyperledger.besu.evm.frame.BlockValues in project besu by hyperledger.

the class EVMExecutor method execute.

public Bytes execute() {
    final MessageCallProcessor mcp = thisMessageCallProcessor();
    final ContractCreationProcessor ccp = thisContractCreationProcessor();
    final Deque<MessageFrame> messageFrameStack = new ArrayDeque<>();
    final MessageFrame initialMessageFrame = MessageFrame.builder().type(MessageFrame.Type.MESSAGE_CALL).messageFrameStack(messageFrameStack).worldUpdater(worldUpdater.updater()).initialGas(gas).contract(Address.ZERO).address(receiver).originator(sender).sender(sender).gasPrice(gasPriceGWei).inputData(callData).value(ethValue).apparentValue(ethValue).code(code).blockValues(blockValues).depth(0).completer(c -> {
    }).miningBeneficiary(Address.ZERO).blockHashLookup(h -> null).accessListWarmAddresses(accessListWarmAddresses).accessListWarmStorage(accessListWarmStorage).build();
    messageFrameStack.add(initialMessageFrame);
    while (!messageFrameStack.isEmpty()) {
        final MessageFrame messageFrame = messageFrameStack.peek();
        switch(messageFrame.getType()) {
            case CONTRACT_CREATION:
                ccp.process(messageFrame, tracer);
                break;
            case MESSAGE_CALL:
                mcp.process(messageFrame, tracer);
                break;
        }
    }
    if (commitWorldState) {
        worldUpdater.commit();
    }
    return initialMessageFrame.getReturnData();
}
Also used : MessageCallProcessor(org.hyperledger.besu.evm.processor.MessageCallProcessor) PrefixCodeRule(org.hyperledger.besu.evm.contractvalidation.PrefixCodeRule) MessageCallProcessor(org.hyperledger.besu.evm.processor.MessageCallProcessor) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) PrecompileContractRegistry(org.hyperledger.besu.evm.precompile.PrecompileContractRegistry) OperationTracer(org.hyperledger.besu.evm.tracing.OperationTracer) Bytes(org.apache.tuweni.bytes.Bytes) Deque(java.util.Deque) Multimap(com.google.common.collect.Multimap) Address(org.hyperledger.besu.datatypes.Address) MaxCodeSizeRule(org.hyperledger.besu.evm.contractvalidation.MaxCodeSizeRule) HashMultimap(com.google.common.collect.HashMultimap) EVM(org.hyperledger.besu.evm.EVM) MainnetEVMs(org.hyperledger.besu.evm.MainnetEVMs) Wei(org.hyperledger.besu.datatypes.Wei) Code(org.hyperledger.besu.evm.Code) Bytes32(org.apache.tuweni.bytes.Bytes32) MainnetPrecompiledContracts(org.hyperledger.besu.evm.precompile.MainnetPrecompiledContracts) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) Objects(java.util.Objects) List(java.util.List) BlockValues(org.hyperledger.besu.evm.frame.BlockValues) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) ContractCreationProcessor(org.hyperledger.besu.evm.processor.ContractCreationProcessor) ArrayDeque(java.util.ArrayDeque) ContractValidationRule(org.hyperledger.besu.evm.contractvalidation.ContractValidationRule) Hash(org.hyperledger.besu.datatypes.Hash) ContractCreationProcessor(org.hyperledger.besu.evm.processor.ContractCreationProcessor) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) ArrayDeque(java.util.ArrayDeque)

Example 7 with BlockValues

use of org.hyperledger.besu.evm.frame.BlockValues in project besu by hyperledger.

the class BlockHashOperation method executeFixedCostOperation.

@Override
public Operation.OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) {
    final UInt256 blockArg = UInt256.fromBytes(frame.popStackItem());
    // Short-circuit if value is unreasonably large
    if (!blockArg.fitsLong()) {
        frame.pushStackItem(UInt256.ZERO);
        return successResponse;
    }
    final long soughtBlock = blockArg.toLong();
    final BlockValues blockValues = frame.getBlockValues();
    final long currentBlockNumber = blockValues.getNumber();
    final long mostRecentBlockNumber = currentBlockNumber - 1;
    // not within the last 256 completed blocks, zero is returned.
    if (currentBlockNumber == 0 || soughtBlock < (mostRecentBlockNumber - MAX_RELATIVE_BLOCK) || soughtBlock > mostRecentBlockNumber) {
        frame.pushStackItem(UInt256.ZERO);
    } else {
        final Function<Long, Hash> blockHashLookup = frame.getBlockHashLookup();
        final Hash blockHash = blockHashLookup.apply(soughtBlock);
        frame.pushStackItem(UInt256.fromBytes(blockHash));
    }
    return successResponse;
}
Also used : BlockValues(org.hyperledger.besu.evm.frame.BlockValues) Hash(org.hyperledger.besu.datatypes.Hash) UInt256(org.apache.tuweni.units.bigints.UInt256)

Example 8 with BlockValues

use of org.hyperledger.besu.evm.frame.BlockValues in project hedera-services by hashgraph.

the class CallLocalEvmTxProcessorTest method assertTransactionSenderAndValue.

@Test
void assertTransactionSenderAndValue() {
    // setup:
    doReturn(Optional.of(receiver.getId().asEvmAddress())).when(transaction).getTo();
    given(worldState.updater()).willReturn(mock(HederaWorldState.Updater.class));
    given(codeCache.getIfPresent(any())).willReturn(new Code());
    given(transaction.getSender()).willReturn(sender.getId().asEvmAddress());
    given(transaction.getValue()).willReturn(Wei.of(1L));
    final MessageFrame.Builder commonInitialFrame = MessageFrame.builder().messageFrameStack(mock(Deque.class)).maxStackSize(MAX_STACK_SIZE).worldUpdater(mock(WorldUpdater.class)).initialGas(mock(Gas.class)).originator(sender.getId().asEvmAddress()).gasPrice(mock(Wei.class)).sender(sender.getId().asEvmAddress()).value(Wei.of(transaction.getValue().getAsBigInteger())).apparentValue(Wei.of(transaction.getValue().getAsBigInteger())).blockValues(mock(BlockValues.class)).depth(0).completer(__ -> {
    }).miningBeneficiary(mock(Address.class)).blockHashLookup(h -> null);
    // when:
    MessageFrame buildMessageFrame = callLocalEvmTxProcessor.buildInitialFrame(commonInitialFrame, worldState.updater(), (Address) transaction.getTo().get(), Bytes.EMPTY);
    // expect:
    assertEquals(transaction.getSender(), buildMessageFrame.getSenderAddress());
    assertEquals(transaction.getValue(), buildMessageFrame.getApparentValue());
}
Also used : WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Gas(org.hyperledger.besu.evm.Gas) BlockValues(org.hyperledger.besu.evm.frame.BlockValues) Wei(org.hyperledger.besu.datatypes.Wei) Code(org.hyperledger.besu.evm.Code) Test(org.junit.jupiter.api.Test)

Aggregations

BlockValues (org.hyperledger.besu.evm.frame.BlockValues)8 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)6 Wei (org.hyperledger.besu.datatypes.Wei)4 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 Code (org.hyperledger.besu.evm.Code)3 EVM (org.hyperledger.besu.evm.EVM)3 Gas (org.hyperledger.besu.evm.Gas)3 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)3 Test (org.junit.jupiter.api.Test)3 Bytes (org.apache.tuweni.bytes.Bytes)2 Hash (org.hyperledger.besu.datatypes.Hash)2 LondonGasCalculator (org.hyperledger.besu.evm.gascalculator.LondonGasCalculator)2 Operation (org.hyperledger.besu.evm.operation.Operation)2 PrevRanDaoOperation (org.hyperledger.besu.evm.operation.PrevRanDaoOperation)2 Test (org.junit.Test)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 ArrayDeque (java.util.ArrayDeque)1 Collection (java.util.Collection)1