static long memoryCost(final long length) {
    final long lengthSquare = clampedMultiply(length, length);
    final long base =
        (lengthSquare == Long.MAX_VALUE)
            ? clampedMultiply(length / 512, length)
            : lengthSquare / 512;

    return clampedAdd(clampedMultiply(MEMORY_WORD_GAS_COST, length), base);
  }
Memory cost.

@param length the length
@return the cost
evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java