use of org.hyperledger.besu.evm.Code 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.Code in project hedera-services by hashgraph.
the class CallEvmTxProcessorTest method givenValidMock.
private void givenValidMock() {
given(worldState.updater()).willReturn(updater);
given(worldState.updater().updater()).willReturn(updater);
given(globalDynamicProperties.fundingAccount()).willReturn(new Id(0, 0, 1010).asGrpcAccount());
var evmAccount = mock(EvmAccount.class);
given(gasCalculator.transactionIntrinsicGasCost(Bytes.EMPTY, false)).willReturn(Gas.ZERO);
given(updater.getOrCreateSenderAccount(sender.getId().asEvmAddress())).willReturn(evmAccount);
given(worldState.updater()).willReturn(updater);
given(codeCache.getIfPresent(any())).willReturn(new Code());
given(gasCalculator.getSelfDestructRefundAmount()).willReturn(Gas.ZERO);
given(gasCalculator.getMaxRefundQuotient()).willReturn(2L);
var senderMutableAccount = mock(MutableAccount.class);
given(senderMutableAccount.decrementBalance(any())).willReturn(Wei.of(1234L));
given(senderMutableAccount.incrementBalance(any())).willReturn(Wei.of(1500L));
given(evmAccount.getMutable()).willReturn(senderMutableAccount);
given(updater.getSenderAccount(any())).willReturn(evmAccount);
given(updater.getSenderAccount(any()).getMutable()).willReturn(senderMutableAccount);
given(updater.getOrCreate(any())).willReturn(evmAccount);
given(updater.getOrCreate(any()).getMutable()).willReturn(senderMutableAccount);
given(updater.getSbhRefund()).willReturn(Gas.ZERO);
}
use of org.hyperledger.besu.evm.Code 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.Code in project hedera-services by hashgraph.
the class CallLocalEvmTxProcessorTest method givenValidMock.
private void givenValidMock() {
given(worldState.updater()).willReturn(updater);
given(worldState.updater().updater()).willReturn(updater);
given(globalDynamicProperties.fundingAccount()).willReturn(new Id(0, 0, 1010).asGrpcAccount());
var evmAccount = mock(EvmAccount.class);
given(gasCalculator.transactionIntrinsicGasCost(Bytes.EMPTY, false)).willReturn(Gas.ZERO);
given(updater.getOrCreateSenderAccount(sender.getId().asEvmAddress())).willReturn(evmAccount);
given(updater.getOrCreateSenderAccount(sender.getId().asEvmAddress()).getMutable()).willReturn(mock(MutableAccount.class));
given(worldState.updater()).willReturn(updater);
given(codeCache.getIfPresent(any())).willReturn(new Code());
var senderMutableAccount = mock(MutableAccount.class);
given(senderMutableAccount.decrementBalance(any())).willReturn(Wei.of(1234L));
given(senderMutableAccount.incrementBalance(any())).willReturn(Wei.of(1500L));
given(gasCalculator.getSelfDestructRefundAmount()).willReturn(Gas.ZERO);
given(gasCalculator.getMaxRefundQuotient()).willReturn(2L);
given(updater.getSenderAccount(any())).willReturn(evmAccount);
given(updater.getSenderAccount(any()).getMutable()).willReturn(senderMutableAccount);
given(updater.getOrCreate(any())).willReturn(evmAccount);
given(updater.getOrCreate(any()).getMutable()).willReturn(senderMutableAccount);
given(updater.getSbhRefund()).willReturn(Gas.ZERO);
}
use of org.hyperledger.besu.evm.Code in project hedera-services by hashgraph.
the class CodeCache method getIfPresent.
public Code getIfPresent(final Address address) {
final var cacheKey = new BytesKey(address.toArray());
var code = cache.getIfPresent(cacheKey);
if (code == null) {
final var bytecode = entityAccess.fetchCodeIfPresent(accountIdFromEvmAddress(address));
if (bytecode != null) {
code = new Code(bytecode, Hash.hash(bytecode));
cache.put(cacheKey, code);
}
}
return code;
}
Aggregations