siphon-library 1.2.5 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +17 -17
- package/out/proof_of_work.d.ts +16 -0
- package/out/proof_of_work.d.ts.map +1 -0
- package/out/proof_of_work.js +21 -0
- package/out/proof_of_work.js.map +1 -0
- package/out/siphon_client.d.ts +1 -0
- package/out/siphon_client.d.ts.map +1 -1
- package/out/siphon_client.js +23 -21
- package/out/siphon_client.js.map +1 -1
- package/out/test.js +135 -135
- package/package.json +38 -38
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Tomé Dias
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tomé Dias
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# Siphon Library
|
|
2
|
-
|
|
3
|
-
Siphon Library is a TypeScript library that enables your application to connect to a Siphon server for analyzing Solidity smart contracts. The Siphon server uses static analysis (as described in the Siphon thesis) to identify inefficiencies and gas optimization patterns in your Solidity code.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Features](#features)
|
|
8
|
-
- [License](#license)
|
|
9
|
-
|
|
10
|
-
## Features
|
|
11
|
-
|
|
12
|
-
- **Connect via WebSocket:** Seamlessly connect to a Siphon server using WebSockets.
|
|
13
|
-
- **Request Optimization Patterns:** Analyze Solidity code to retrieve a map of detected gas optimization patterns.
|
|
14
|
-
|
|
15
|
-
## License
|
|
16
|
-
|
|
17
|
-
This project is licensed under the [MIT License](LICENSE).
|
|
1
|
+
# Siphon Library
|
|
2
|
+
|
|
3
|
+
Siphon Library is a TypeScript library that enables your application to connect to a Siphon server for analyzing Solidity smart contracts. The Siphon server uses static analysis (as described in the Siphon thesis) to identify inefficiencies and gas optimization patterns in your Solidity code.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Features](#features)
|
|
8
|
+
- [License](#license)
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Connect via WebSocket:** Seamlessly connect to a Siphon server using WebSockets.
|
|
13
|
+
- **Request Optimization Patterns:** Analyze Solidity code to retrieve a map of detected gas optimization patterns.
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface PowPayload {
|
|
2
|
+
id: string;
|
|
3
|
+
method: string;
|
|
4
|
+
params: unknown;
|
|
5
|
+
}
|
|
6
|
+
interface PowResult {
|
|
7
|
+
nonce: number;
|
|
8
|
+
serializedPayload: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Computes a nonce so that the SHA-256 hash of the serialized payload has two leading zeros.
|
|
12
|
+
* Returns the nonce alongside the serialized payload, which should be sent as-is to the server.
|
|
13
|
+
*/
|
|
14
|
+
export declare function computePowPayload(basePayload: PowPayload): PowResult;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=proof_of_work.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof_of_work.d.ts","sourceRoot":"","sources":["../src/proof_of_work.ts"],"names":[],"mappings":"AAEA,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,SAAS;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,UAAU,GAAG,SAAS,CAcpE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computePowPayload = computePowPayload;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
/**
|
|
6
|
+
* Computes a nonce so that the SHA-256 hash of the serialized payload has two leading zeros.
|
|
7
|
+
* Returns the nonce alongside the serialized payload, which should be sent as-is to the server.
|
|
8
|
+
*/
|
|
9
|
+
function computePowPayload(basePayload) {
|
|
10
|
+
let nonce = 0;
|
|
11
|
+
while (true) {
|
|
12
|
+
const payloadWithNonce = { ...basePayload, nonce };
|
|
13
|
+
const serializedPayload = JSON.stringify(payloadWithNonce);
|
|
14
|
+
const hashHex = (0, crypto_1.createHash)("sha256").update(serializedPayload).digest("hex");
|
|
15
|
+
if (hashHex.startsWith("00")) {
|
|
16
|
+
return { nonce, serializedPayload };
|
|
17
|
+
}
|
|
18
|
+
nonce += 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=proof_of_work.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof_of_work.js","sourceRoot":"","sources":["../src/proof_of_work.ts"],"names":[],"mappings":";;AAiBA,8CAcC;AA/BD,mCAAoC;AAapC;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,WAAuB;IACvD,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,gBAAgB,GAAG,EAAE,GAAG,WAAW,EAAE,KAAK,EAAE,CAAC;QACnD,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE7E,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;QACtC,CAAC;QAED,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;AACH,CAAC"}
|
package/out/siphon_client.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siphon_client.d.ts","sourceRoot":"","sources":["../src/siphon_client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"siphon_client.d.ts","sourceRoot":"","sources":["../src/siphon_client.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC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,MAAM,GAAG,IAAW,EACnC,aAAa,GAAE,MAAM,GAAG,IAAW,GAClC,OAAO,CAAC;QAAE,OAAO,EAAE,GAAG,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAW/C;;;OAGG;IACH,mBAAmB,CACjB,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,aAAa,GAAE,MAAM,GAAG,IAAW,EACnC,aAAa,GAAE,MAAM,GAAG,IAAW,GAClC,OAAO,CAAC;QAAE,OAAO,EAAE,GAAG,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAmB/C,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAiBrC"}
|
package/out/siphon_client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SiphonWS = void 0;
|
|
4
|
+
const proof_of_work_1 = require("./proof_of_work");
|
|
4
5
|
class SiphonWS {
|
|
5
6
|
ws;
|
|
6
7
|
pending = new Map();
|
|
@@ -16,7 +17,7 @@ class SiphonWS {
|
|
|
16
17
|
this.url = url;
|
|
17
18
|
this.reconnectIntervalMs = Math.max(0, options.reconnectIntervalMs ?? 500);
|
|
18
19
|
this.maxReconnectAttempts =
|
|
19
|
-
typeof options.maxReconnectAttempts ===
|
|
20
|
+
typeof options.maxReconnectAttempts === "number"
|
|
20
21
|
? options.maxReconnectAttempts
|
|
21
22
|
: null;
|
|
22
23
|
const defaultMaxDelay = Math.max(this.reconnectIntervalMs, 8000);
|
|
@@ -29,7 +30,7 @@ class SiphonWS {
|
|
|
29
30
|
_createWebSocket() {
|
|
30
31
|
const socket = new WebSocket(this.url);
|
|
31
32
|
socket.onopen = () => this._handleOpen();
|
|
32
|
-
socket.onmessage = (evt) => this._onMessage(typeof evt.data ===
|
|
33
|
+
socket.onmessage = (evt) => this._onMessage(typeof evt.data === "string" ? evt.data : evt.data.toString("utf-8"));
|
|
33
34
|
socket.onclose = () => this._handleClose();
|
|
34
35
|
socket.onerror = () => this._handleError();
|
|
35
36
|
return socket;
|
|
@@ -44,12 +45,12 @@ class SiphonWS {
|
|
|
44
45
|
}
|
|
45
46
|
_handleClose() {
|
|
46
47
|
if (this.shouldReconnect) {
|
|
47
|
-
const err = new Error(
|
|
48
|
+
const err = new Error("WebSocket connection lost");
|
|
48
49
|
this._rejectSentPending(err);
|
|
49
50
|
this._scheduleReconnect();
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
|
-
const err = new Error(
|
|
53
|
+
const err = new Error("WebSocket connection closed");
|
|
53
54
|
this._rejectAllPending(err);
|
|
54
55
|
}
|
|
55
56
|
_handleError() {
|
|
@@ -69,10 +70,10 @@ class SiphonWS {
|
|
|
69
70
|
if (state === WebSocket.OPEN) {
|
|
70
71
|
try {
|
|
71
72
|
this.ws.send(payload);
|
|
72
|
-
pendingEntry.status =
|
|
73
|
+
pendingEntry.status = "sent";
|
|
73
74
|
}
|
|
74
75
|
catch {
|
|
75
|
-
pendingEntry.status =
|
|
76
|
+
pendingEntry.status = "queued";
|
|
76
77
|
this.sendQueue.unshift({ payload, id });
|
|
77
78
|
this._scheduleReconnect();
|
|
78
79
|
}
|
|
@@ -80,10 +81,10 @@ class SiphonWS {
|
|
|
80
81
|
}
|
|
81
82
|
if (!this.shouldReconnect) {
|
|
82
83
|
this.pending.delete(id);
|
|
83
|
-
pendingEntry.reject(new Error(
|
|
84
|
+
pendingEntry.reject(new Error("WebSocket is not connected"));
|
|
84
85
|
return;
|
|
85
86
|
}
|
|
86
|
-
pendingEntry.status =
|
|
87
|
+
pendingEntry.status = "queued";
|
|
87
88
|
this.sendQueue.push({ payload, id });
|
|
88
89
|
if (state !== WebSocket.CONNECTING) {
|
|
89
90
|
this._scheduleReconnect();
|
|
@@ -101,10 +102,10 @@ class SiphonWS {
|
|
|
101
102
|
}
|
|
102
103
|
try {
|
|
103
104
|
this.ws.send(payload);
|
|
104
|
-
pendingEntry.status =
|
|
105
|
+
pendingEntry.status = "sent";
|
|
105
106
|
}
|
|
106
107
|
catch {
|
|
107
|
-
pendingEntry.status =
|
|
108
|
+
pendingEntry.status = "queued";
|
|
108
109
|
this.sendQueue.unshift({ payload, id });
|
|
109
110
|
if (this.ws.readyState !== WebSocket.OPEN) {
|
|
110
111
|
break;
|
|
@@ -120,9 +121,10 @@ class SiphonWS {
|
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
123
|
const attempt = this.reconnectAttempts + 1;
|
|
123
|
-
if (this.maxReconnectAttempts !== null &&
|
|
124
|
+
if (this.maxReconnectAttempts !== null &&
|
|
125
|
+
attempt > this.maxReconnectAttempts) {
|
|
124
126
|
this.shouldReconnect = false;
|
|
125
|
-
this._rejectAllPending(new Error(
|
|
127
|
+
this._rejectAllPending(new Error("Maximum reconnect attempts reached"));
|
|
126
128
|
return;
|
|
127
129
|
}
|
|
128
130
|
const delay = this._computeReconnectDelay(attempt);
|
|
@@ -141,7 +143,7 @@ class SiphonWS {
|
|
|
141
143
|
}
|
|
142
144
|
_rejectSentPending(err) {
|
|
143
145
|
for (const [id, pendingEntry] of this.pending.entries()) {
|
|
144
|
-
if (pendingEntry.status ===
|
|
146
|
+
if (pendingEntry.status === "sent") {
|
|
145
147
|
pendingEntry.reject(err);
|
|
146
148
|
this.pending.delete(id);
|
|
147
149
|
}
|
|
@@ -174,11 +176,11 @@ class SiphonWS {
|
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
_rpc(method, id, params = {}) {
|
|
177
|
-
const
|
|
179
|
+
const { serializedPayload } = (0, proof_of_work_1.computePowPayload)({ id, method, params });
|
|
178
180
|
return new Promise((resolve, reject) => {
|
|
179
|
-
const pendingEntry = { resolve, reject, status:
|
|
181
|
+
const pendingEntry = { resolve, reject, status: "queued" };
|
|
180
182
|
this.pending.set(id, pendingEntry);
|
|
181
|
-
this._sendOrQueue(
|
|
183
|
+
this._sendOrQueue(serializedPayload, id, pendingEntry);
|
|
182
184
|
});
|
|
183
185
|
}
|
|
184
186
|
/** One-off pattern analysis */
|
|
@@ -186,7 +188,7 @@ class SiphonWS {
|
|
|
186
188
|
if (!msg_id) {
|
|
187
189
|
msg_id = Math.random().toString(36).slice(2, 10);
|
|
188
190
|
}
|
|
189
|
-
return this._rpc(
|
|
191
|
+
return this._rpc("analyze", msg_id, {
|
|
190
192
|
code,
|
|
191
193
|
contract_name,
|
|
192
194
|
function_name,
|
|
@@ -197,7 +199,7 @@ class SiphonWS {
|
|
|
197
199
|
if (!msg_id) {
|
|
198
200
|
msg_id = Math.random().toString(36).slice(2, 10);
|
|
199
201
|
}
|
|
200
|
-
return this._rpc(
|
|
202
|
+
return this._rpc("optimize", msg_id, {
|
|
201
203
|
code,
|
|
202
204
|
contract_name,
|
|
203
205
|
function_name,
|
|
@@ -211,10 +213,10 @@ class SiphonWS {
|
|
|
211
213
|
if (!msg_id) {
|
|
212
214
|
msg_id = Math.random().toString(36).slice(2, 10);
|
|
213
215
|
}
|
|
214
|
-
return this._rpc(
|
|
216
|
+
return this._rpc("analyze", msg_id, {
|
|
215
217
|
code,
|
|
216
218
|
}).then((r) => {
|
|
217
|
-
return this._rpc(
|
|
219
|
+
return this._rpc("optimize", msg_id, {
|
|
218
220
|
code,
|
|
219
221
|
contract_name,
|
|
220
222
|
function_name,
|
|
@@ -227,7 +229,7 @@ class SiphonWS {
|
|
|
227
229
|
clearTimeout(this.reconnectTimer);
|
|
228
230
|
this.reconnectTimer = null;
|
|
229
231
|
}
|
|
230
|
-
this._rejectAllPending(new Error(
|
|
232
|
+
this._rejectAllPending(new Error("WebSocket connection closed by client"));
|
|
231
233
|
if (this.ws.readyState === WebSocket.CLOSING ||
|
|
232
234
|
this.ws.readyState === WebSocket.CLOSED) {
|
|
233
235
|
return;
|
package/out/siphon_client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siphon_client.js","sourceRoot":"","sources":["../src/siphon_client.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"siphon_client.js","sourceRoot":"","sources":["../src/siphon_client.ts"],"names":[],"mappings":";;;AAAA,mDAAoD;AA2CpD,MAAa,QAAQ;IACX,EAAE,CAAY;IACd,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC5B,GAAG,CAAS;IACZ,mBAAmB,CAAS;IAC5B,oBAAoB,CAAgB;IACpC,mBAAmB,CAAS;IACrC,iBAAiB,GAAG,CAAC,CAAC;IACtB,cAAc,GAAyC,IAAI,CAAC;IAC5D,eAAe,GAAG,IAAI,CAAC;IACvB,SAAS,GAAoB,EAAE,CAAC;IAExC,YAAY,GAAW,EAAE,UAA2B,EAAE;QACpD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,mBAAmB,IAAI,GAAG,CAAC,CAAC;QAC3E,IAAI,CAAC,oBAAoB;YACvB,OAAO,OAAO,CAAC,oBAAoB,KAAK,QAAQ;gBAC9C,CAAC,CAAC,OAAO,CAAC,oBAAoB;gBAC9B,CAAC,CAAC,IAAI,CAAC;QAEX,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;QACjE,IAAI,CAAC,mBAAmB;YACtB,OAAO,CAAC,mBAAmB,KAAK,SAAS;gBACvC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,mBAAmB,CAAC;gBACjE,CAAC,CAAC,eAAe,CAAC;QAEtB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACpC,CAAC;IAEO,gBAAgB;QACtB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,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aAAa;gBACb,aAAa;aACd,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAa,EAAE,MAAe;QAClC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC,iBAAiB,CAAC,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC,CAAC;QAE3E,IACE,IAAI,CAAC,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,OAAO;YACxC,IAAI,CAAC,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,MAAM,EACvC,CAAC;YACD,OAAO;QACT,CAAC;QAED,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AArSD,4BAqSC"}
|
package/out/test.js
CHANGED
|
@@ -6,141 +6,141 @@ async function runTests() {
|
|
|
6
6
|
const client = new siphon_client_1.SiphonWS('ws://localhost:8000/ws');
|
|
7
7
|
await new Promise(res => setTimeout(res, 100)); // give WS a moment
|
|
8
8
|
console.log('✅ Connected to Siphon WS');
|
|
9
|
-
const codeSample = `
|
|
10
|
-
// SPDX-License-Identifier: GPL-3.0
|
|
11
|
-
|
|
12
|
-
pragma solidity >=0.8.0;
|
|
13
|
-
|
|
14
|
-
contract EvaluationPattern1 {
|
|
15
|
-
uint256 minThreshold;
|
|
16
|
-
uint256 maxThreshold;
|
|
17
|
-
uint256 scalingFactor;
|
|
18
|
-
uint256 offset;
|
|
19
|
-
bool public Error;
|
|
20
|
-
|
|
21
|
-
function pattern1(uint256 x) public {
|
|
22
|
-
minThreshold = 5;
|
|
23
|
-
maxThreshold = 10;
|
|
24
|
-
scalingFactor = maxThreshold / minThreshold;
|
|
25
|
-
offset = 2;
|
|
26
|
-
|
|
27
|
-
uint256 y;
|
|
28
|
-
uint256 z;
|
|
29
|
-
if (minThreshold < x && x < maxThreshold) {
|
|
30
|
-
y = x * scalingFactor;
|
|
31
|
-
|
|
32
|
-
if (y < maxThreshold) {
|
|
33
|
-
Error = true;
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
y = 2 * maxThreshold;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
z = y - offset;
|
|
40
|
-
|
|
41
|
-
if (z < maxThreshold) {
|
|
42
|
-
Error = true;
|
|
43
|
-
} else {
|
|
44
|
-
Error = false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
contract EvaluationPattern2 {
|
|
50
|
-
uint256 amount = 15;
|
|
51
|
-
uint256 interest = 2;
|
|
52
|
-
uint256 balance;
|
|
53
|
-
bool public Error;
|
|
54
|
-
|
|
55
|
-
function pattern2() public {
|
|
56
|
-
amount = 15;
|
|
57
|
-
interest = 2;
|
|
58
|
-
|
|
59
|
-
uint256 tentativeBalance = balance;
|
|
60
|
-
if (tentativeBalance > amount * interest) {
|
|
61
|
-
tentativeBalance -= amount * interest;
|
|
62
|
-
|
|
63
|
-
if (tentativeBalance > 0) {
|
|
64
|
-
Error = false;
|
|
65
|
-
} else {
|
|
66
|
-
Error = true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
balance = tentativeBalance;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
contract EvaluationPattern4 {
|
|
75
|
-
uint256 numberOfTransactions;
|
|
76
|
-
address[] userList;
|
|
77
|
-
mapping(address => uint256) usersBalance;
|
|
78
|
-
address smallestBalanceIndex;
|
|
79
|
-
|
|
80
|
-
function pattern4(uint256 transactionAmount) public {
|
|
81
|
-
for(uint256 i = 0; i < userList.length; i++) {
|
|
82
|
-
numberOfTransactions++;
|
|
83
|
-
address userAddress = userList[i];
|
|
84
|
-
|
|
85
|
-
usersBalance[userAddress] += transactionAmount;
|
|
86
|
-
|
|
87
|
-
if (usersBalance[userAddress] < usersBalance[smallestBalanceIndex]) {
|
|
88
|
-
smallestBalanceIndex = userAddress;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
for(uint256 i = 0; i < userList.length; i++) {
|
|
95
|
-
usersBalance[smallestBalanceIndex] += transactionAmount * 2;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
contract EvaluationPattern5 {
|
|
101
|
-
address[] userList;
|
|
102
|
-
mapping(address => uint256) usersBalance;
|
|
103
|
-
|
|
104
|
-
function validAddress(address userAddress) public pure returns (bool) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function interest(uint256 amount) public pure returns (uint256) {
|
|
109
|
-
return amount * 2;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function pattern5(uint256 amount) public {
|
|
113
|
-
for(uint256 i = 0; i < userList.length; i++) {
|
|
114
|
-
address userAddress = userList[i];
|
|
115
|
-
if (validAddress(userAddress)) {
|
|
116
|
-
usersBalance[userAddress] += interest(amount);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
contract EvaluationPattern6 {
|
|
123
|
-
address[] userList;
|
|
124
|
-
mapping(address => uint256) usersBalance;
|
|
125
|
-
|
|
126
|
-
function adjustedMinThreshold(uint256 amount) public pure returns (uint256) {
|
|
127
|
-
return (amount) / (amount + 100);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function pattern6(uint256 amount) public {
|
|
131
|
-
for(uint256 i = 0; i < userList.length; i++) {
|
|
132
|
-
address userAddress = userList[i];
|
|
133
|
-
uint256 value;
|
|
134
|
-
if (amount < adjustedMinThreshold(amount)) {
|
|
135
|
-
value = amount;
|
|
136
|
-
} else {
|
|
137
|
-
value = 100;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
usersBalance[userAddress] += value;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
9
|
+
const codeSample = `
|
|
10
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
11
|
+
|
|
12
|
+
pragma solidity >=0.8.0;
|
|
13
|
+
|
|
14
|
+
contract EvaluationPattern1 {
|
|
15
|
+
uint256 minThreshold;
|
|
16
|
+
uint256 maxThreshold;
|
|
17
|
+
uint256 scalingFactor;
|
|
18
|
+
uint256 offset;
|
|
19
|
+
bool public Error;
|
|
20
|
+
|
|
21
|
+
function pattern1(uint256 x) public {
|
|
22
|
+
minThreshold = 5;
|
|
23
|
+
maxThreshold = 10;
|
|
24
|
+
scalingFactor = maxThreshold / minThreshold;
|
|
25
|
+
offset = 2;
|
|
26
|
+
|
|
27
|
+
uint256 y;
|
|
28
|
+
uint256 z;
|
|
29
|
+
if (minThreshold < x && x < maxThreshold) {
|
|
30
|
+
y = x * scalingFactor;
|
|
31
|
+
|
|
32
|
+
if (y < maxThreshold) {
|
|
33
|
+
Error = true;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
y = 2 * maxThreshold;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
z = y - offset;
|
|
40
|
+
|
|
41
|
+
if (z < maxThreshold) {
|
|
42
|
+
Error = true;
|
|
43
|
+
} else {
|
|
44
|
+
Error = false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
contract EvaluationPattern2 {
|
|
50
|
+
uint256 amount = 15;
|
|
51
|
+
uint256 interest = 2;
|
|
52
|
+
uint256 balance;
|
|
53
|
+
bool public Error;
|
|
54
|
+
|
|
55
|
+
function pattern2() public {
|
|
56
|
+
amount = 15;
|
|
57
|
+
interest = 2;
|
|
58
|
+
|
|
59
|
+
uint256 tentativeBalance = balance;
|
|
60
|
+
if (tentativeBalance > amount * interest) {
|
|
61
|
+
tentativeBalance -= amount * interest;
|
|
62
|
+
|
|
63
|
+
if (tentativeBalance > 0) {
|
|
64
|
+
Error = false;
|
|
65
|
+
} else {
|
|
66
|
+
Error = true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
balance = tentativeBalance;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
contract EvaluationPattern4 {
|
|
75
|
+
uint256 numberOfTransactions;
|
|
76
|
+
address[] userList;
|
|
77
|
+
mapping(address => uint256) usersBalance;
|
|
78
|
+
address smallestBalanceIndex;
|
|
79
|
+
|
|
80
|
+
function pattern4(uint256 transactionAmount) public {
|
|
81
|
+
for(uint256 i = 0; i < userList.length; i++) {
|
|
82
|
+
numberOfTransactions++;
|
|
83
|
+
address userAddress = userList[i];
|
|
84
|
+
|
|
85
|
+
usersBalance[userAddress] += transactionAmount;
|
|
86
|
+
|
|
87
|
+
if (usersBalance[userAddress] < usersBalance[smallestBalanceIndex]) {
|
|
88
|
+
smallestBalanceIndex = userAddress;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
for(uint256 i = 0; i < userList.length; i++) {
|
|
95
|
+
usersBalance[smallestBalanceIndex] += transactionAmount * 2;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
contract EvaluationPattern5 {
|
|
101
|
+
address[] userList;
|
|
102
|
+
mapping(address => uint256) usersBalance;
|
|
103
|
+
|
|
104
|
+
function validAddress(address userAddress) public pure returns (bool) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function interest(uint256 amount) public pure returns (uint256) {
|
|
109
|
+
return amount * 2;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function pattern5(uint256 amount) public {
|
|
113
|
+
for(uint256 i = 0; i < userList.length; i++) {
|
|
114
|
+
address userAddress = userList[i];
|
|
115
|
+
if (validAddress(userAddress)) {
|
|
116
|
+
usersBalance[userAddress] += interest(amount);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
contract EvaluationPattern6 {
|
|
123
|
+
address[] userList;
|
|
124
|
+
mapping(address => uint256) usersBalance;
|
|
125
|
+
|
|
126
|
+
function adjustedMinThreshold(uint256 amount) public pure returns (uint256) {
|
|
127
|
+
return (amount) / (amount + 100);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function pattern6(uint256 amount) public {
|
|
131
|
+
for(uint256 i = 0; i < userList.length; i++) {
|
|
132
|
+
address userAddress = userList[i];
|
|
133
|
+
uint256 value;
|
|
134
|
+
if (amount < adjustedMinThreshold(amount)) {
|
|
135
|
+
value = amount;
|
|
136
|
+
} else {
|
|
137
|
+
value = 100;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
usersBalance[userAddress] += value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
144
|
`;
|
|
145
145
|
// 1) analyze
|
|
146
146
|
const patterns = await client.analyze(codeSample);
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "siphon-library",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "A library for ...",
|
|
5
|
-
"main": "out/index.js",
|
|
6
|
-
"types": "out/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"out",
|
|
9
|
-
"README.md",
|
|
10
|
-
"LICENSE"
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "tsc",
|
|
14
|
-
"prepare": "npm run build"
|
|
15
|
-
},
|
|
16
|
-
"jest": {
|
|
17
|
-
"preset": "ts-jest",
|
|
18
|
-
"testEnvironment": "node",
|
|
19
|
-
"moduleFileExtensions": [
|
|
20
|
-
"ts",
|
|
21
|
-
"js",
|
|
22
|
-
"json"
|
|
23
|
-
],
|
|
24
|
-
"testMatch": [
|
|
25
|
-
"**/?(*.)+(spec|test).[jt]s?(x)"
|
|
26
|
-
]
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"typescript": "5.8.2",
|
|
30
|
-
"ts-jest": "^29.0.0",
|
|
31
|
-
"jest": "^29.0.0",
|
|
32
|
-
"@types/jest": "^29.0.0",
|
|
33
|
-
"@types/ws": "^8.18.1"
|
|
34
|
-
},
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"ws": "^8.18.3"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "siphon-library",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A library for ...",
|
|
5
|
+
"main": "out/index.js",
|
|
6
|
+
"types": "out/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"out",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"prepare": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"jest": {
|
|
17
|
+
"preset": "ts-jest",
|
|
18
|
+
"testEnvironment": "node",
|
|
19
|
+
"moduleFileExtensions": [
|
|
20
|
+
"ts",
|
|
21
|
+
"js",
|
|
22
|
+
"json"
|
|
23
|
+
],
|
|
24
|
+
"testMatch": [
|
|
25
|
+
"**/?(*.)+(spec|test).[jt]s?(x)"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "5.8.2",
|
|
30
|
+
"ts-jest": "^29.0.0",
|
|
31
|
+
"jest": "^29.0.0",
|
|
32
|
+
"@types/jest": "^29.0.0",
|
|
33
|
+
"@types/ws": "^8.18.1"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"ws": "^8.18.3"
|
|
37
|
+
}
|
|
38
|
+
}
|