@Override
  public OperationResult execute(final MessageFrame frame, final EVM evm) {
    Code code = frame.getCode();
    if (code.getEofVersion() == 0) {
      return InvalidOperation.INVALID_RESULT;
    }

    int pc = frame.getPC();
    int index = code.readU8(pc + 1);

    final long from = clampedToLong(frame.popStackItem());
    final long length = clampedToLong(frame.popStackItem());

    final long cost = gasCalculator().memoryExpansionGasCost(frame, from, length);
    if (frame.getRemainingGas() < cost) {
      return new OperationResult(cost, ExceptionalHaltReason.INSUFFICIENT_GAS);
    }

    if (index >= code.getSubcontainerCount()) {
      return new OperationResult(cost, ExceptionalHaltReason.NONEXISTENT_CONTAINER);
    }

    Bytes auxData = frame.readMemory(from, length);
    if (code.getDataSize() + auxData.size() > evm.getMaxCodeSize()) {
      return new OperationResult(cost, ExceptionalHaltReason.CODE_TOO_LARGE);
    }
    if (code.getDataSize() + auxData.size() < code.getDeclaredDataSize()) {
      return new OperationResult(cost, ExceptionalHaltReason.DATA_TOO_SMALL);
    }
    Optional<Code> newCode = code.getSubContainer(index, auxData, evm);
    if (newCode.isEmpty()) {
      return new OperationResult(cost, ExceptionalHaltReason.INVALID_CONTAINER);
    }

    frame.setCreatedCode(newCode.get());
    frame.setState(MessageFrame.State.CODE_SUCCESS);
    return new OperationResult(cost, null);
  }
Instantiates a new Return operation.

@param gasCalculator the gas calculator
evm/src/main/java/org/hyperledger/besu/evm/operation/ReturnContractOperation.java