Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/vm/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ func TestLoadtx(t *testing.T) {
e.runProg(t,
"loadtx "+tx.Hash().StringLE(), // hash LE
"run",
"loadtx --gas 10000 "+tx.Hash().StringLE(), // with GAS
"loadtx --gas 100 "+tx.Hash().StringLE(), // with GAS
"run",
"loadtx 0x"+tx.Hash().StringLE(), // hash LE with 0x prefix
"run",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
golang.org/x/term v0.35.0
golang.org/x/text v0.29.0
golang.org/x/tools v0.37.0
gonum.org/v1/gonum v0.16.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
132 changes: 132 additions & 0 deletions opcodefee/append.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.metrics import r2_score"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('opcode_results/APPEND.csv')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def plot_target_vs_each_feature(X: pd.DataFrame, y: pd.Series):\n",
" y_vals = y.values.reshape(-1)\n",
" for col in X.columns:\n",
" x_vals = X[col].values\n",
" plt.figure(figsize=(8, 5))\n",
" plt.scatter(x_vals, y_vals)\n",
" plt.xlabel(col)\n",
" plt.ylabel(\"ns\")\n",
" plt.title(f\"ns vs {col}\")\n",
" plt.grid(True)\n",
" plt.tight_layout()\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def analytic_linear_regression(X: pd.DataFrame, y: pd.Series) -> np.ndarray:\n",
" X_mat = X.values\n",
" y_vec = y.values\n",
"\n",
" n = X_mat.shape[0]\n",
" X_design = np.hstack([X_mat, np.ones((n, 1))])\n",
"\n",
" beta, _, _, _ = np.linalg.lstsq(X_design, y_vec, rcond=None)\n",
"\n",
" return beta"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def myfunc(df_type: pd.DataFrame):\n",
" X = df_type[[\"refcount\"]]\n",
" y = df_type[\"ns\"]\n",
"\n",
" plot_target_vs_each_feature(X, y)\n",
" \n",
" X_train, X_test, y_train, y_test = train_test_split(\n",
" X, y, test_size=0.3, random_state=42\n",
" )\n",
" beta = analytic_linear_regression(X_train, y_train)\n",
" \n",
" X_test_mat = X_test.values\n",
" X_test_design = np.hstack([X_test_mat, np.ones((X_test_mat.shape[0], 1))])\n",
" y_pred = X_test_design @ beta\n",
" r2 = r2_score(y_test, y_pred)\n",
" \n",
" return beta, r2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"beta, r2 = myfunc(df[df[\"appendtype\"] == \"Array\"])\n",
"print(beta)\n",
"print(r2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"beta, r2 = myfunc(df[df[\"appendtype\"] == \"Struct\"])\n",
"print(beta)\n",
"print(r2)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "opcode",
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
121 changes: 121 additions & 0 deletions opcodefee/cat.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.metrics import r2_score"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('opcode_results/CAT.csv')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def plot_target_vs_each_feature(X: pd.DataFrame, y: pd.Series):\n",
" y_vals = y.values.reshape(-1)\n",
" for col in X.columns:\n",
" x_vals = X[col].values\n",
" plt.figure(figsize=(8, 5))\n",
" plt.scatter(x_vals, y_vals)\n",
" plt.xlabel(col)\n",
" plt.ylabel(\"ns\")\n",
" plt.title(f\"ns vs {col}\")\n",
" plt.grid(True)\n",
" plt.tight_layout()\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def analytic_linear_regression(X: pd.DataFrame, y: pd.Series) -> np.ndarray:\n",
" X_mat = X.values\n",
" y_vec = y.values\n",
"\n",
" n = X_mat.shape[0]\n",
" X_design = np.hstack([X_mat, np.ones((n, 1))])\n",
"\n",
" beta, _, _, _ = np.linalg.lstsq(X_design, y_vec, rcond=None)\n",
"\n",
" return beta"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def myfunc(df_type: pd.DataFrame):\n",
" X = df_type[[\"numbytes\"]]\n",
" y = df_type[\"ns\"]\n",
"\n",
" plot_target_vs_each_feature(X, y)\n",
" \n",
" X_train, X_test, y_train, y_test = train_test_split(\n",
" X, y, test_size=0.3, random_state=42\n",
" )\n",
" beta = analytic_linear_regression(X_train, y_train)\n",
" \n",
" X_test_mat = X_test.values\n",
" X_test_design = np.hstack([X_test_mat, np.ones((X_test_mat.shape[0], 1))])\n",
" y_pred = X_test_design @ beta\n",
" r2 = r2_score(y_test, y_pred)\n",
" \n",
" return beta, r2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"beta, r2 = myfunc(df)\n",
"print(beta)\n",
"print(r2)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "opcode",
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
121 changes: 121 additions & 0 deletions opcodefee/clear.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.metrics import r2_score"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('opcode_results/CLEAR.csv')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def plot_target_vs_each_feature(X: pd.DataFrame, y: pd.Series):\n",
" y_vals = y.values.reshape(-1)\n",
" for col in X.columns:\n",
" x_vals = X[col].values\n",
" plt.figure(figsize=(8, 5))\n",
" plt.scatter(x_vals, y_vals)\n",
" plt.xlabel(col)\n",
" plt.ylabel(\"ns\")\n",
" plt.title(f\"ns vs {col}\")\n",
" plt.grid(True)\n",
" plt.tight_layout()\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def analytic_linear_regression(X: pd.DataFrame, y: pd.Series) -> np.ndarray:\n",
" X_mat = X.values\n",
" y_vec = y.values\n",
"\n",
" n = X_mat.shape[0]\n",
" X_design = np.hstack([X_mat, np.ones((n, 1))])\n",
"\n",
" beta, _, _, _ = np.linalg.lstsq(X_design, y_vec, rcond=None)\n",
"\n",
" return beta"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def myfunc(df_type: pd.DataFrame):\n",
" X = df_type[[\"refcount\", \"stacksize\"]]\n",
" y = df_type[\"ns\"]\n",
"\n",
" plot_target_vs_each_feature(X, y)\n",
" \n",
" X_train, X_test, y_train, y_test = train_test_split(\n",
" X, y, test_size=0.3, random_state=42\n",
" )\n",
" beta = analytic_linear_regression(X_train, y_train)\n",
" \n",
" X_test_mat = X_test.values\n",
" X_test_design = np.hstack([X_test_mat, np.ones((X_test_mat.shape[0], 1))])\n",
" y_pred = X_test_design @ beta\n",
" r2 = r2_score(y_test, y_pred)\n",
" \n",
" return beta, r2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"beta, r2 = myfunc(df)\n",
"print(beta)\n",
"print(r2)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "opcode",
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Loading