Search in sources :

Example 1 with ModificationNotAllowedException

use of org.hyperledger.besu.evm.ModificationNotAllowedException in project besu by hyperledger.

the class MessageCallProcessor method start.

@Override
public void start(final MessageFrame frame, final OperationTracer operationTracer) {
    LOG.trace("Executing message-call");
    try {
        transferValue(frame);
        // Check first if the message call is to a pre-compile contract
        final PrecompiledContract precompile = precompiles.get(frame.getContractAddress());
        if (precompile != null) {
            executePrecompile(precompile, frame, operationTracer);
        } else {
            frame.setState(MessageFrame.State.CODE_EXECUTING);
        }
    } catch (final ModificationNotAllowedException ex) {
        LOG.trace("Message call error: attempt to mutate an immutable account");
        frame.setExceptionalHaltReason(Optional.of(ExceptionalHaltReason.ILLEGAL_STATE_CHANGE));
        frame.setState(MessageFrame.State.EXCEPTIONAL_HALT);
    }
}
Also used : PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) ModificationNotAllowedException(org.hyperledger.besu.evm.ModificationNotAllowedException)

Example 2 with ModificationNotAllowedException

use of org.hyperledger.besu.evm.ModificationNotAllowedException in project besu by hyperledger.

the class ContractCreationProcessor method start.

@Override
public void start(final MessageFrame frame, final OperationTracer operationTracer) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Executing contract-creation");
    }
    try {
        final MutableAccount sender = frame.getWorldUpdater().getSenderAccount(frame).getMutable();
        sender.decrementBalance(frame.getValue());
        final MutableAccount contract = frame.getWorldUpdater().getOrCreate(frame.getContractAddress()).getMutable();
        if (accountExists(contract)) {
            LOG.trace("Contract creation error: account has already been created for address {}", frame.getContractAddress());
            frame.setExceptionalHaltReason(Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
            frame.setState(MessageFrame.State.EXCEPTIONAL_HALT);
            operationTracer.traceAccountCreationResult(frame, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        } else {
            contract.incrementBalance(frame.getValue());
            contract.setNonce(initialContractNonce);
            contract.clearStorage();
            frame.setState(MessageFrame.State.CODE_EXECUTING);
        }
    } catch (final ModificationNotAllowedException ex) {
        LOG.trace("Contract creation error: attempt to mutate an immutable account");
        frame.setExceptionalHaltReason(Optional.of(ExceptionalHaltReason.ILLEGAL_STATE_CHANGE));
        frame.setState(MessageFrame.State.EXCEPTIONAL_HALT);
    }
}
Also used : ModificationNotAllowedException(org.hyperledger.besu.evm.ModificationNotAllowedException) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount)

Aggregations

ModificationNotAllowedException (org.hyperledger.besu.evm.ModificationNotAllowedException)2 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)1 PrecompiledContract (org.hyperledger.besu.evm.precompile.PrecompiledContract)1