Search in sources :

Example 1 with PrecompiledContract

use of org.hyperledger.besu.evm.precompile.PrecompiledContract in project besu by hyperledger.

the class MessageCallProcessor method executePrecompile.

/**
 * Executes this message call knowing that it is a call to the provided pre-compiled contract.
 *
 * @param contract The contract this is a message call to.
 */
private void executePrecompile(final PrecompiledContract contract, final MessageFrame frame, final OperationTracer operationTracer) {
    final Gas gasRequirement = contract.gasRequirement(frame.getInputData());
    if (frame.getRemainingGas().compareTo(gasRequirement) < 0) {
        LOG.trace("Not enough gas available for pre-compiled contract code {}: requiring " + "{} but only {} gas available", contract, gasRequirement, frame.getRemainingGas());
        frame.setExceptionalHaltReason(Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        frame.setState(MessageFrame.State.EXCEPTIONAL_HALT);
    } else {
        frame.decrementRemainingGas(gasRequirement);
        final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(frame.getInputData(), frame);
        operationTracer.tracePrecompileCall(frame, gasRequirement, result.getOutput());
        if (result.isRefundGas()) {
            frame.incrementRemainingGas(gasRequirement);
        }
        if (frame.getState() == MessageFrame.State.REVERT) {
            frame.setRevertReason(result.getOutput());
        } else {
            frame.setOutputData(result.getOutput());
        }
        frame.setState(result.getState());
        frame.setExceptionalHaltReason(result.getHaltReason());
        LOG.trace("Precompiled contract {} {} (gasComsumed: {})", contract.getName(), result.getState(), result.isRefundGas() ? Gas.ZERO : gasRequirement);
    }
}
Also used : PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Gas(org.hyperledger.besu.evm.Gas)

Example 2 with PrecompiledContract

use of org.hyperledger.besu.evm.precompile.PrecompiledContract in project besu by hyperledger.

the class PrivacyTest method flexibleEnabledPrivacy.

@Test
public void flexibleEnabledPrivacy() throws IOException, URISyntaxException {
    final BesuController besuController = setUpControllerWithPrivacyEnabled(true);
    final PrecompiledContract flexiblePrecompiledContract = getPrecompile(besuController, FLEXIBLE_PRIVACY);
    assertThat(flexiblePrecompiledContract.getName()).isEqualTo("FlexiblePrivacy");
}
Also used : PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) BesuController(org.hyperledger.besu.controller.BesuController) Test(org.junit.Test)

Example 3 with PrecompiledContract

use of org.hyperledger.besu.evm.precompile.PrecompiledContract 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 4 with PrecompiledContract

use of org.hyperledger.besu.evm.precompile.PrecompiledContract in project besu by hyperledger.

the class PrivacyTest method defaultPrivacy.

@Test
public void defaultPrivacy() throws IOException, URISyntaxException {
    final BesuController besuController = setUpControllerWithPrivacyEnabled(false);
    final PrecompiledContract precompiledContract = getPrecompile(besuController, DEFAULT_PRIVACY);
    assertThat(precompiledContract.getName()).isEqualTo("Privacy");
}
Also used : PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) BesuController(org.hyperledger.besu.controller.BesuController) Test(org.junit.Test)

Aggregations

PrecompiledContract (org.hyperledger.besu.evm.precompile.PrecompiledContract)4 BesuController (org.hyperledger.besu.controller.BesuController)2 Test (org.junit.Test)2 Gas (org.hyperledger.besu.evm.Gas)1 ModificationNotAllowedException (org.hyperledger.besu.evm.ModificationNotAllowedException)1