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();
}
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;
}
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());
}
Aggregations