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);
}
}
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");
}
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);
}
}
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");
}
Aggregations