{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 1,
      "id": "71de0621-6285-49a1-a5b5-89b56c4e4060",
      "metadata": {
        "id": "71de0621-6285-49a1-a5b5-89b56c4e4060"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import matplotlib.ticker as ticker"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "f1658d97-0d39-49d3-b2e7-176d8305f20b",
      "metadata": {
        "id": "f1658d97-0d39-49d3-b2e7-176d8305f20b"
      },
      "source": [
        "## Data"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "id": "0bceac9d-3ce2-47c5-b499-1935453036de",
      "metadata": {
        "id": "0bceac9d-3ce2-47c5-b499-1935453036de"
      },
      "outputs": [],
      "source": [
        "no_of_ranges = np.array([1, 2, 78, 538, 716, 1074], dtype=float)\n",
        "secret_sizes = np.array([2873, 3133, 22621, 134525, 177765, 265421], dtype=float)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "86d5cb46-dd20-4d5a-8f44-fd56127b2e50",
      "metadata": {
        "id": "86d5cb46-dd20-4d5a-8f44-fd56127b2e50"
      },
      "source": [
        "## Compute a best-fit line using np.polyfit (degree=1 for linear)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "id": "d88f787b-b33e-4caf-98e2-b63e089bfcf2",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "d88f787b-b33e-4caf-98e2-b63e089bfcf2",
        "outputId": "70e5ed8a-de3c-4d90-f28d-64fc06956d8d"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Slope = 244.401, Intercept = 2929.222\n"
          ]
        }
      ],
      "source": [
        "slope, intercept = np.polyfit(no_of_ranges, secret_sizes, 1)\n",
        "print(f\"Slope = {slope:.3f}, Intercept = {intercept:.3f}\")"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "5e1d98f8-b479-48d0-a93d-c37bfaf14238",
      "metadata": {
        "editable": true,
        "tags": [],
        "id": "5e1d98f8-b479-48d0-a93d-c37bfaf14238"
      },
      "source": [
        "## Create a function for the fitted line"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "id": "e43c50b0-380a-4ee4-b8e7-7fd972542a4c",
      "metadata": {
        "id": "e43c50b0-380a-4ee4-b8e7-7fd972542a4c"
      },
      "outputs": [],
      "source": [
        "def line_of_best_fit(x):\n",
        "    return slope * x + intercept"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "185e7cb5-36ac-485f-8c7a-ab1bc35c4dc6",
      "metadata": {
        "id": "185e7cb5-36ac-485f-8c7a-ab1bc35c4dc6"
      },
      "source": [
        "## Plot: data points and best-fit line"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "id": "30a80b4b-7787-4eec-b1b9-df0f7813ee5a",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 407
        },
        "id": "30a80b4b-7787-4eec-b1b9-df0f7813ee5a",
        "outputId": "7b3bfa2c-21b1-43d8-b16a-80ef475409fc"
      },
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 600x400 with 1 Axes>"
            ],
            "image/png": "[encoded data, 46444 characters]\n"
          },
          "metadata": {}
        }
      ],
      "source": [
        "x_line = np.linspace(no_of_ranges.min() - 1, no_of_ranges.max() + 1, 100)\n",
        "y_line = line_of_best_fit(x_line)\n",
        "\n",
        "plt.figure(figsize=(6, 4))\n",
        "plt.scatter(no_of_ranges, secret_sizes, color=\"red\", label=\"Data points\")\n",
        "\n",
        "plt.plot(x_line, y_line, color=\"blue\", label=f\"y = {slope:.2f}x + {intercept:.2f}\")\n",
        "plt.title(\"Secret Size v.s. Ranges Committed\")\n",
        "plt.ylabel(\"Size of Secret (Bytes)\")\n",
        "plt.xlabel(\"No. of Ranges Committed\")\n",
        "plt.legend()\n",
        "\n",
        "# Access current axes and set a FuncFormatter\n",
        "def bytes_to_kb(y, pos):\n",
        "    # y is the tick value (in bytes)\n",
        "    return f\"{y / 1024:.1f}K\"\n",
        "\n",
        "ax = plt.gca()\n",
        "ax.yaxis.set_major_formatter(ticker.FuncFormatter(bytes_to_kb))\n",
        "\n",
        "plt.grid(True)\n",
        "plt.tight_layout()"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "be14170a-fce8-489f-b01f-d8e12f0b91f9",
      "metadata": {
        "id": "be14170a-fce8-489f-b01f-d8e12f0b91f9"
      },
      "source": [
        "\n",
        "## Info\n",
        "- `Transcript` of 1076 bytes (sent len: 226 bytes, recv len: 850 bytes) is used.\n",
        "- `No. of Ranges Committed (K)` are generated by different commit strategies:\n",
        "  - Commit to request (1 range)\n",
        "  - Commit to request and response (2 ranges)\n",
        "  - Commit to HTTP objects (78 ranges)\n",
        "  - Commit to every single byte (1076 ranges)\n",
        "  - Commit to every X byte (538 ranges, 717 ranges)\n",
        "- `Size of Secret` is the size of the resulting secret file generated, which includes:\n",
        "  - Data that don't grow with increasing `K`, e.g. transcript itself, server cert info\n",
        "  - Data that grows **linearly**: `EncodingTree`, which has\n",
        "      - `MerkleTree`, where no. of leaves = `K`, hence total number of nodes scales in `O(K)`\n",
        "      - `Vec<Blinder>`, where no. of blinder = `K`\n",
        "      - `BiMap<usize, (Direction, Idx)>`, where `(Direction, Idx)` = ranges committed\n",
        "- `Attestation` generated don't grow with increasing `K` as only the merkle root is committed."
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.11.10"
    },
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}