Search in sources :

Example 1 with Code

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);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Gas(org.hyperledger.besu.evm.Gas) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) Wei(org.hyperledger.besu.datatypes.Wei) Code(org.hyperledger.besu.evm.Code)

Example 2 with Code

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);
}
Also used : Id(com.hedera.services.store.models.Id) Code(org.hyperledger.besu.evm.Code)

Example 3 with Code

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

Example 4 with Code

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);
}
Also used : MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) Id(com.hedera.services.store.models.Id) Code(org.hyperledger.besu.evm.Code)

Example 5 with Code

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;
}
Also used : BytesKey(com.hedera.services.utils.BytesKey) Code(org.hyperledger.besu.evm.Code)

Aggregations

Code (org.hyperledger.besu.evm.Code)25 Bytes (org.apache.tuweni.bytes.Bytes)15 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)12 Wei (org.hyperledger.besu.datatypes.Wei)10 ArrayDeque (java.util.ArrayDeque)8 Address (org.hyperledger.besu.datatypes.Address)8 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)8 Deque (java.util.Deque)5 Hash (org.hyperledger.besu.datatypes.Hash)5 EVM (org.hyperledger.besu.evm.EVM)5 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)5 List (java.util.List)4 Optional (java.util.Optional)4 Transaction (org.hyperledger.besu.ethereum.core.Transaction)4 PrecompileContractRegistry (org.hyperledger.besu.evm.precompile.PrecompileContractRegistry)4 MessageCallProcessor (org.hyperledger.besu.evm.processor.MessageCallProcessor)4 Test (org.junit.Test)4 ProcessableBlockHeader (org.hyperledger.besu.ethereum.core.ProcessableBlockHeader)3 OperationTracer (org.hyperledger.besu.evm.tracing.OperationTracer)3 Test (org.junit.jupiter.api.Test)3