use of org.hyperledger.besu.evm.frame.MessageFrame in project hedera-services by hashgraph.
the class AbstractRecordingCreateOperation method spawnChildMessage.
private void spawnChildMessage(final MessageFrame frame) {
// memory cost needs to be calculated prior to memory expansion
final Gas cost = cost(frame);
frame.decrementRemainingGas(cost);
final Address address = frame.getRecipientAddress();
final MutableAccount account = frame.getWorldUpdater().getAccount(address).getMutable();
account.incrementNonce();
final Wei value = Wei.wrap(frame.getStackItem(0));
final long inputOffset = clampedToLong(frame.getStackItem(1));
final long inputSize = clampedToLong(frame.getStackItem(2));
final Bytes inputData = frame.readMemory(inputOffset, inputSize);
final Address contractAddress = targetContractAddress(frame);
final Gas childGasStipend = gasCalculator().gasAvailableForChildCreate(frame.getRemainingGas());
frame.decrementRemainingGas(childGasStipend);
final MessageFrame childFrame = MessageFrame.builder().type(MessageFrame.Type.CONTRACT_CREATION).messageFrameStack(frame.getMessageFrameStack()).worldUpdater(frame.getWorldUpdater().updater()).initialGas(childGasStipend).address(contractAddress).originator(frame.getOriginatorAddress()).contract(contractAddress).gasPrice(frame.getGasPrice()).inputData(Bytes.EMPTY).sender(frame.getRecipientAddress()).value(value).apparentValue(value).code(new Code(inputData, Hash.EMPTY)).blockValues(frame.getBlockValues()).depth(frame.getMessageStackDepth() + 1).completer(child -> complete(frame, child)).miningBeneficiary(frame.getMiningBeneficiary()).blockHashLookup(frame.getBlockHashLookup()).maxStackSize(frame.getMaxStackSize()).build();
frame.incrementRemainingGas(cost);
frame.getMessageFrameStack().addFirst(childFrame);
frame.setState(MessageFrame.State.CODE_SUSPENDED);
}
use of org.hyperledger.besu.evm.frame.MessageFrame in project hedera-services by hashgraph.
the class HederaOperationUtil method newContractExpiryIn.
/**
* Returns the expiry to be used for a new contract. Climbs the {@link MessageFrame} and searches for the parent
* {@link com.hedera.services.store.contracts.HederaWorldState.WorldStateAccount}. The expiry to be used is
* the expiry of the first account found in the stack
*
* @param frame Current message frame
* @return Expiry to be used for new contracts
*/
public static long newContractExpiryIn(MessageFrame frame) {
long expiry = 0;
HederaWorldState.WorldStateAccount hederaAccount;
Iterator<MessageFrame> framesIterator = frame.getMessageFrameStack().iterator();
MessageFrame messageFrame;
while (framesIterator.hasNext()) {
messageFrame = framesIterator.next();
/* if this is the initial frame from the deque, check context vars first */
if (!framesIterator.hasNext()) {
OptionalLong expiryOptional = messageFrame.getContextVariable("expiry");
if (expiryOptional.isPresent()) {
expiry = expiryOptional.getAsLong();
break;
}
}
/* check if this messageFrame's sender account can be retrieved from state */
final var updater = (HederaWorldUpdater) messageFrame.getWorldUpdater();
hederaAccount = updater.getHederaAccount(frame.getSenderAddress());
if (hederaAccount != null) {
expiry = hederaAccount.getExpiry();
break;
}
}
return expiry;
}
use of org.hyperledger.besu.evm.frame.MessageFrame in project hedera-services by hashgraph.
the class CallEvmTxProcessorTest 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 = callEvmTxProcessor.buildInitialFrame(commonInitialFrame, worldState.updater(), (Address) transaction.getTo().get(), Bytes.EMPTY);
// expect:
assertEquals(transaction.getSender(), buildMessageFrame.getSenderAddress());
assertEquals(transaction.getValue(), buildMessageFrame.getApparentValue());
}
use of org.hyperledger.besu.evm.frame.MessageFrame in project hedera-services by hashgraph.
the class CreateEvmTxProcessorTest method assertTransactionSenderAndValue.
@Test
void assertTransactionSenderAndValue() {
// setup:
doReturn(Optional.of(receiver.getId().asEvmAddress())).when(transaction).getTo();
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 = createEvmTxProcessor.buildInitialFrame(commonInitialFrame, worldState.updater(), (Address) transaction.getTo().get(), Bytes.EMPTY);
// expect:
assertEquals(transaction.getSender(), buildMessageFrame.getSenderAddress());
assertEquals(transaction.getValue(), buildMessageFrame.getApparentValue());
}
use of org.hyperledger.besu.evm.frame.MessageFrame in project hedera-services by hashgraph.
the class HederaSStoreOperationTest method executesWithZero.
@Test
void executesWithZero() {
final UInt256 keyBytes = UInt256.fromBytes(keyBytesMock);
final UInt256 valueBytes = UInt256.fromBytes(Bytes.fromHexString("0x12345678"));
givenValidContext(keyBytes, valueBytes);
given(mutableAccount.getStorageValue(any())).willReturn(UInt256.ZERO);
final var expectedExpiry = 20L;
Deque<MessageFrame> frameDeque = new ArrayDeque<>();
frameDeque.add(messageFrame);
given(messageFrame.getMessageFrameStack()).willReturn(frameDeque);
given(messageFrame.getContextVariable("expiry")).willReturn(OptionalLong.of(expectedExpiry));
given(messageFrame.getContextVariable("sbh")).willReturn(5L);
given(messageFrame.getBlockValues()).willReturn(hederaBlockValues);
given(messageFrame.getGasPrice()).willReturn(Wei.of(50000L));
given(hederaBlockValues.getTimestamp()).willReturn(10L);
final var result = subject.execute(messageFrame, evm);
final var expected = new Operation.OperationResult(Optional.of(Gas.of(10)), Optional.empty());
assertEquals(expected.getGasCost(), result.getGasCost());
assertEquals(expected.getHaltReason(), result.getHaltReason());
verify(mutableAccount).setStorageValue(any(), any());
verify(messageFrame).storageWasUpdated(any(), any());
}
Aggregations