├── .github
└── workflows
│ ├── build.yml
│ └── doc.yml
├── .gitignore
├── .gitmodules
├── Cargo.lock
├── Cargo.toml
├── LICENSE.AGPL-3.0
├── LICENSE.APACHE-2
├── README.md
├── build.rs
├── docs
└── EWASM_TEST.md
├── examples
├── arith-readme.md
├── arith.ds
├── arith.wasm
├── arith.wat
├── deepsea_arith.rs
├── execute_vm.rs
├── fe-readme.md
├── fe-runner.rs
├── fib.wasm
└── fib.yul
├── shell.nix
├── src
└── lib.rs
└── utils
└── docker
└── Dockerfile
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | pull_request:
8 | branches:
9 | - master
10 |
11 | jobs:
12 | build_test:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v2
16 | with:
17 | submodules: recursive
18 | - uses: cachix/install-nix-action@v13
19 | with:
20 | nix_path: nixpkgs=channel:nixos-unstable
21 | - name: Build rust-ssvm lib
22 | run: nix-shell --run "cargo build -v"
23 | - name: Test rust-ssvm
24 | run: nix-shell --run "cargo run --example execute_vm -v -- -f=examples/fib.wasm"
25 |
--------------------------------------------------------------------------------
/.github/workflows/doc.yml:
--------------------------------------------------------------------------------
1 | name: Doc
2 | on:
3 | push:
4 | branches: [ main ]
5 |
6 | jobs:
7 | doc:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v2
11 | with:
12 | submodules: recursive
13 |
14 | - uses: cachix/install-nix-action@v13
15 | with:
16 | nix_path: nixpkgs=channel:nixos-unstable
17 |
18 | - name: Build Documentation
19 | run: nix-shell --run "cargo doc"
20 |
21 | - name: Deploy Documentation
22 | env:
23 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 | PUBLISH_BRANCH: gh-pages
25 | PUBLISH_DIR: ./target/doc
26 | SCRIPT_MODE: true
27 | run: |
28 | wget https://raw.githubusercontent.com/peaceiris/actions-gh-pages/v2.5.0/entrypoint.sh
29 | bash ./entrypoint.sh
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .envrc
3 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "ssvm-evmc"]
2 | path = ssvm-evmc
3 | url = https://github.com/second-state/ssvm-evmc
4 |
--------------------------------------------------------------------------------
/Cargo.lock:
--------------------------------------------------------------------------------
1 | # This file is automatically @generated by Cargo.
2 | # It is not intended for manual editing.
3 | version = 3
4 |
5 | [[package]]
6 | name = "aho-corasick"
7 | version = "0.7.18"
8 | source = "registry+https://github.com/rust-lang/crates.io-index"
9 | checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
10 | dependencies = [
11 | "memchr",
12 | ]
13 |
14 | [[package]]
15 | name = "ansi_term"
16 | version = "0.11.0"
17 | source = "registry+https://github.com/rust-lang/crates.io-index"
18 | checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
19 | dependencies = [
20 | "winapi",
21 | ]
22 |
23 | [[package]]
24 | name = "atty"
25 | version = "0.2.14"
26 | source = "registry+https://github.com/rust-lang/crates.io-index"
27 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
28 | dependencies = [
29 | "hermit-abi",
30 | "libc",
31 | "winapi",
32 | ]
33 |
34 | [[package]]
35 | name = "autocfg"
36 | version = "1.0.1"
37 | source = "registry+https://github.com/rust-lang/crates.io-index"
38 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
39 |
40 | [[package]]
41 | name = "bindgen"
42 | version = "0.54.0"
43 | source = "registry+https://github.com/rust-lang/crates.io-index"
44 | checksum = "66c0bb6167449588ff70803f4127f0684f9063097eca5016f37eb52b92c2cf36"
45 | dependencies = [
46 | "bitflags",
47 | "cexpr",
48 | "cfg-if 0.1.10",
49 | "clang-sys",
50 | "clap",
51 | "env_logger",
52 | "lazy_static",
53 | "lazycell",
54 | "log",
55 | "peeking_take_while",
56 | "proc-macro2",
57 | "quote",
58 | "regex",
59 | "rustc-hash",
60 | "shlex",
61 | "which",
62 | ]
63 |
64 | [[package]]
65 | name = "bitflags"
66 | version = "1.2.1"
67 | source = "registry+https://github.com/rust-lang/crates.io-index"
68 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
69 |
70 | [[package]]
71 | name = "cc"
72 | version = "1.0.67"
73 | source = "registry+https://github.com/rust-lang/crates.io-index"
74 | checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
75 |
76 | [[package]]
77 | name = "cexpr"
78 | version = "0.4.0"
79 | source = "registry+https://github.com/rust-lang/crates.io-index"
80 | checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
81 | dependencies = [
82 | "nom",
83 | ]
84 |
85 | [[package]]
86 | name = "cfg-if"
87 | version = "0.1.10"
88 | source = "registry+https://github.com/rust-lang/crates.io-index"
89 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
90 |
91 | [[package]]
92 | name = "cfg-if"
93 | version = "1.0.0"
94 | source = "registry+https://github.com/rust-lang/crates.io-index"
95 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
96 |
97 | [[package]]
98 | name = "clang-sys"
99 | version = "0.29.3"
100 | source = "registry+https://github.com/rust-lang/crates.io-index"
101 | checksum = "fe6837df1d5cba2397b835c8530f51723267e16abbf83892e9e5af4f0e5dd10a"
102 | dependencies = [
103 | "glob",
104 | "libc",
105 | "libloading",
106 | ]
107 |
108 | [[package]]
109 | name = "clap"
110 | version = "2.33.3"
111 | source = "registry+https://github.com/rust-lang/crates.io-index"
112 | checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
113 | dependencies = [
114 | "ansi_term",
115 | "atty",
116 | "bitflags",
117 | "strsim",
118 | "textwrap",
119 | "unicode-width",
120 | "vec_map",
121 | ]
122 |
123 | [[package]]
124 | name = "cmake"
125 | version = "0.1.45"
126 | source = "registry+https://github.com/rust-lang/crates.io-index"
127 | checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855"
128 | dependencies = [
129 | "cc",
130 | ]
131 |
132 | [[package]]
133 | name = "enum_primitive"
134 | version = "0.1.1"
135 | source = "registry+https://github.com/rust-lang/crates.io-index"
136 | checksum = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180"
137 | dependencies = [
138 | "num-traits 0.1.43",
139 | ]
140 |
141 | [[package]]
142 | name = "env_logger"
143 | version = "0.7.1"
144 | source = "registry+https://github.com/rust-lang/crates.io-index"
145 | checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
146 | dependencies = [
147 | "atty",
148 | "humantime",
149 | "log",
150 | "regex",
151 | "termcolor",
152 | ]
153 |
154 | [[package]]
155 | name = "evmc-client"
156 | version = "7.4.0"
157 | source = "git+https://github.com/second-state/evmc?tag=v7.4.0-rust-evmc-client-rc.2#e54e3e5ee051c92f770105cc02df57c8b0b40ff8"
158 | dependencies = [
159 | "cmake",
160 | "enum_primitive",
161 | "evmc-sys",
162 | "evmc-vm",
163 | "num",
164 | ]
165 |
166 | [[package]]
167 | name = "evmc-sys"
168 | version = "7.4.0"
169 | source = "git+https://github.com/second-state/evmc?tag=v7.4.0-rust-evmc-client-rc.2#e54e3e5ee051c92f770105cc02df57c8b0b40ff8"
170 | dependencies = [
171 | "bindgen",
172 | ]
173 |
174 | [[package]]
175 | name = "evmc-vm"
176 | version = "7.4.0"
177 | source = "git+https://github.com/second-state/evmc?tag=v7.4.0-rust-evmc-client-rc.2#e54e3e5ee051c92f770105cc02df57c8b0b40ff8"
178 | dependencies = [
179 | "evmc-sys",
180 | ]
181 |
182 | [[package]]
183 | name = "glob"
184 | version = "0.3.0"
185 | source = "registry+https://github.com/rust-lang/crates.io-index"
186 | checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
187 |
188 | [[package]]
189 | name = "hermit-abi"
190 | version = "0.1.18"
191 | source = "registry+https://github.com/rust-lang/crates.io-index"
192 | checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
193 | dependencies = [
194 | "libc",
195 | ]
196 |
197 | [[package]]
198 | name = "hex"
199 | version = "0.4.3"
200 | source = "registry+https://github.com/rust-lang/crates.io-index"
201 | checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
202 |
203 | [[package]]
204 | name = "humantime"
205 | version = "1.3.0"
206 | source = "registry+https://github.com/rust-lang/crates.io-index"
207 | checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
208 | dependencies = [
209 | "quick-error",
210 | ]
211 |
212 | [[package]]
213 | name = "lazy_static"
214 | version = "1.4.0"
215 | source = "registry+https://github.com/rust-lang/crates.io-index"
216 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
217 |
218 | [[package]]
219 | name = "lazycell"
220 | version = "1.3.0"
221 | source = "registry+https://github.com/rust-lang/crates.io-index"
222 | checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
223 |
224 | [[package]]
225 | name = "libc"
226 | version = "0.2.94"
227 | source = "registry+https://github.com/rust-lang/crates.io-index"
228 | checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
229 |
230 | [[package]]
231 | name = "libloading"
232 | version = "0.5.2"
233 | source = "registry+https://github.com/rust-lang/crates.io-index"
234 | checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753"
235 | dependencies = [
236 | "cc",
237 | "winapi",
238 | ]
239 |
240 | [[package]]
241 | name = "log"
242 | version = "0.4.14"
243 | source = "registry+https://github.com/rust-lang/crates.io-index"
244 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
245 | dependencies = [
246 | "cfg-if 1.0.0",
247 | ]
248 |
249 | [[package]]
250 | name = "memchr"
251 | version = "2.4.0"
252 | source = "registry+https://github.com/rust-lang/crates.io-index"
253 | checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
254 |
255 | [[package]]
256 | name = "nom"
257 | version = "5.1.2"
258 | source = "registry+https://github.com/rust-lang/crates.io-index"
259 | checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
260 | dependencies = [
261 | "memchr",
262 | "version_check",
263 | ]
264 |
265 | [[package]]
266 | name = "num"
267 | version = "0.3.1"
268 | source = "registry+https://github.com/rust-lang/crates.io-index"
269 | checksum = "8b7a8e9be5e039e2ff869df49155f1c06bd01ade2117ec783e56ab0932b67a8f"
270 | dependencies = [
271 | "num-bigint",
272 | "num-complex",
273 | "num-integer",
274 | "num-iter",
275 | "num-rational",
276 | "num-traits 0.2.14",
277 | ]
278 |
279 | [[package]]
280 | name = "num-bigint"
281 | version = "0.3.2"
282 | source = "registry+https://github.com/rust-lang/crates.io-index"
283 | checksum = "7d0a3d5e207573f948a9e5376662aa743a2ea13f7c50a554d7af443a73fbfeba"
284 | dependencies = [
285 | "autocfg",
286 | "num-integer",
287 | "num-traits 0.2.14",
288 | ]
289 |
290 | [[package]]
291 | name = "num-complex"
292 | version = "0.3.1"
293 | source = "registry+https://github.com/rust-lang/crates.io-index"
294 | checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5"
295 | dependencies = [
296 | "num-traits 0.2.14",
297 | ]
298 |
299 | [[package]]
300 | name = "num-integer"
301 | version = "0.1.44"
302 | source = "registry+https://github.com/rust-lang/crates.io-index"
303 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
304 | dependencies = [
305 | "autocfg",
306 | "num-traits 0.2.14",
307 | ]
308 |
309 | [[package]]
310 | name = "num-iter"
311 | version = "0.1.42"
312 | source = "registry+https://github.com/rust-lang/crates.io-index"
313 | checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59"
314 | dependencies = [
315 | "autocfg",
316 | "num-integer",
317 | "num-traits 0.2.14",
318 | ]
319 |
320 | [[package]]
321 | name = "num-rational"
322 | version = "0.3.2"
323 | source = "registry+https://github.com/rust-lang/crates.io-index"
324 | checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
325 | dependencies = [
326 | "autocfg",
327 | "num-bigint",
328 | "num-integer",
329 | "num-traits 0.2.14",
330 | ]
331 |
332 | [[package]]
333 | name = "num-traits"
334 | version = "0.1.43"
335 | source = "registry+https://github.com/rust-lang/crates.io-index"
336 | checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
337 | dependencies = [
338 | "num-traits 0.2.14",
339 | ]
340 |
341 | [[package]]
342 | name = "num-traits"
343 | version = "0.2.14"
344 | source = "registry+https://github.com/rust-lang/crates.io-index"
345 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
346 | dependencies = [
347 | "autocfg",
348 | ]
349 |
350 | [[package]]
351 | name = "peeking_take_while"
352 | version = "0.1.2"
353 | source = "registry+https://github.com/rust-lang/crates.io-index"
354 | checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
355 |
356 | [[package]]
357 | name = "proc-macro2"
358 | version = "1.0.26"
359 | source = "registry+https://github.com/rust-lang/crates.io-index"
360 | checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
361 | dependencies = [
362 | "unicode-xid",
363 | ]
364 |
365 | [[package]]
366 | name = "quick-error"
367 | version = "1.2.3"
368 | source = "registry+https://github.com/rust-lang/crates.io-index"
369 | checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
370 |
371 | [[package]]
372 | name = "quote"
373 | version = "1.0.9"
374 | source = "registry+https://github.com/rust-lang/crates.io-index"
375 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
376 | dependencies = [
377 | "proc-macro2",
378 | ]
379 |
380 | [[package]]
381 | name = "regex"
382 | version = "1.5.3"
383 | source = "registry+https://github.com/rust-lang/crates.io-index"
384 | checksum = "ce5f1ceb7f74abbce32601642fcf8e8508a8a8991e0621c7d750295b9095702b"
385 | dependencies = [
386 | "aho-corasick",
387 | "memchr",
388 | "regex-syntax",
389 | ]
390 |
391 | [[package]]
392 | name = "regex-syntax"
393 | version = "0.6.25"
394 | source = "registry+https://github.com/rust-lang/crates.io-index"
395 | checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
396 |
397 | [[package]]
398 | name = "rust-ssvm"
399 | version = "0.0.1"
400 | dependencies = [
401 | "clap",
402 | "cmake",
403 | "evmc-client",
404 | "hex",
405 | "libloading",
406 | ]
407 |
408 | [[package]]
409 | name = "rustc-hash"
410 | version = "1.1.0"
411 | source = "registry+https://github.com/rust-lang/crates.io-index"
412 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
413 |
414 | [[package]]
415 | name = "shlex"
416 | version = "0.1.1"
417 | source = "registry+https://github.com/rust-lang/crates.io-index"
418 | checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
419 |
420 | [[package]]
421 | name = "strsim"
422 | version = "0.8.0"
423 | source = "registry+https://github.com/rust-lang/crates.io-index"
424 | checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
425 |
426 | [[package]]
427 | name = "termcolor"
428 | version = "1.1.2"
429 | source = "registry+https://github.com/rust-lang/crates.io-index"
430 | checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
431 | dependencies = [
432 | "winapi-util",
433 | ]
434 |
435 | [[package]]
436 | name = "textwrap"
437 | version = "0.11.0"
438 | source = "registry+https://github.com/rust-lang/crates.io-index"
439 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
440 | dependencies = [
441 | "unicode-width",
442 | ]
443 |
444 | [[package]]
445 | name = "unicode-width"
446 | version = "0.1.8"
447 | source = "registry+https://github.com/rust-lang/crates.io-index"
448 | checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
449 |
450 | [[package]]
451 | name = "unicode-xid"
452 | version = "0.2.2"
453 | source = "registry+https://github.com/rust-lang/crates.io-index"
454 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
455 |
456 | [[package]]
457 | name = "vec_map"
458 | version = "0.8.2"
459 | source = "registry+https://github.com/rust-lang/crates.io-index"
460 | checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
461 |
462 | [[package]]
463 | name = "version_check"
464 | version = "0.9.3"
465 | source = "registry+https://github.com/rust-lang/crates.io-index"
466 | checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
467 |
468 | [[package]]
469 | name = "which"
470 | version = "3.1.1"
471 | source = "registry+https://github.com/rust-lang/crates.io-index"
472 | checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724"
473 | dependencies = [
474 | "libc",
475 | ]
476 |
477 | [[package]]
478 | name = "winapi"
479 | version = "0.3.9"
480 | source = "registry+https://github.com/rust-lang/crates.io-index"
481 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
482 | dependencies = [
483 | "winapi-i686-pc-windows-gnu",
484 | "winapi-x86_64-pc-windows-gnu",
485 | ]
486 |
487 | [[package]]
488 | name = "winapi-i686-pc-windows-gnu"
489 | version = "0.4.0"
490 | source = "registry+https://github.com/rust-lang/crates.io-index"
491 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
492 |
493 | [[package]]
494 | name = "winapi-util"
495 | version = "0.1.5"
496 | source = "registry+https://github.com/rust-lang/crates.io-index"
497 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
498 | dependencies = [
499 | "winapi",
500 | ]
501 |
502 | [[package]]
503 | name = "winapi-x86_64-pc-windows-gnu"
504 | version = "0.4.0"
505 | source = "registry+https://github.com/rust-lang/crates.io-index"
506 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
507 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "rust-ssvm"
3 | version = "0.0.1"
4 | license = "AGPL-3.0"
5 | authors = ["SecondState"]
6 | description = "Rust-SSVM - a Portable EWASM Engine Binding Rust Interface"
7 | edition = "2018"
8 | repository = "https://github.com/second-state/rust-ssvm/"
9 | build="build.rs"
10 |
11 | [dependencies]
12 | evmc-client = { git = "https://github.com/second-state/evmc", tag = "v7.4.0-rust-evmc-client-rc.2" }
13 | libloading = "0.5"
14 | hex = "0.4"
15 | clap = "2.33.0"
16 |
17 | [build-dependencies]
18 | cmake = "0.1.42"
--------------------------------------------------------------------------------
/LICENSE.AGPL-3.0:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published by
637 | the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/LICENSE.APACHE-2:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [2020] [Second State]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Rust SSVM
2 | 
3 | [](https://second-state.github.io/rust-ssvm/rust_ssvm/index.html)
4 |
5 | This project provides SSVM a Rust interface by using [EVMC](https://github.com/ethereum/evmc) (Ethereum Client-VM Connector API) to binding SSVM and host written in Rust.
6 |
7 | We extend evmc rust binding module to include [evmc-client](https://github.com/second-state/evmc/releases/tag/v6.3.1-rust-evmc-client) base on evmc version 6.3.1 for now.
8 |
9 | The software architecture of **evmc-client** was inspired by [go-ethereum](https://github.com/ethereum/go-ethereum) about how to use EVMC connect Ewasm VM ([Hera](https://github.com/ewasm/hera)) with host written in golang.
10 |
11 |
12 | - EVMC-Client design architecture
13 | ```
14 | evmc-client : ┌───────────────────────────────────────────────┐
15 | stack diagram │ evmc-client │
16 | ├───────────────────────────────────────────────┤
17 | │ lib.rs (pub interface) │
18 | ├─────────────────────────────────┬─────────────┤
19 | │ host.rs (hook host context) │ loader.rs │
20 | go-ethereum : ┆ ┆
21 | sequential diagram ┆ ┆
22 | ┌───────────────────┐
23 | ┌───────────────────┐ ┌────────────────────┐ ┌─────────────────────────┐ │ C module │
24 | │geth/core/vm/evm.go│ │geth/core/vm/evmc.go│ │evmc/bindings/.../evmc.go│ │ex. loader and hera│
25 | └─────────┬─────────┘ └─────────┬──────────┘ └────────────┬────────────┘ └─────────┬─────────┘
26 | NewEVM │ NewEVMC │ │ │
27 | ─────────>│────────────────────>│ │ │
28 | │ CreateVM ─┤ │ │
29 | │ │ Load │ ╔═══════════╗
30 | │ │ ───────────────────────>│ ║ Loader ░║
31 | │ │ │ evmc_load_and_create ╚═══════════╝
32 | │ │ │───────────────────────>│
33 | │ │ │ load EVMC VM .so ─┤
34 | │ │ │ call evmc_create ─┤
35 | │ │ │ │
36 | │ │ return Instance{handle} │ return evmc_instance │
37 | │<─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │<─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─│
38 | │ │ │ │
39 | run │ Run │ │ │
40 | ─────────>│────────────────────>│ │ ╔═══════════╗
41 | │ │ Execute │ ║ EVMC VM ░║
42 | │ │ ───────────────────────>│ ║ ex. Hera ║
43 | │ │ │ evmc_execute ╚═══════════╝
44 | │ │ │───────────────────────>│
45 | │ │ │ execute ─┤
46 | │ │ return output, gasLeft, │ │
47 | │ │ err │return evmc_result │
48 | │<─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │<─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─│
49 | │ │ │ │
50 | ```
51 |
52 | ## Build environment
53 |
54 | Build rust-ssvm you need prepare a build ssvm environment and include rust compile tool.
55 |
56 | - Reuse ssvm build environment docker image
57 | ```bash
58 | > docker pull secondstate/ssvm
59 | ```
60 |
61 | - Fetch rust-ssvm source code
62 | ```bash
63 | > git clone --recursive git@github.com:second-state/rust-ssvm.git
64 | ```
65 |
66 | - Start docker container
67 | ```bash
68 | > docker run -it \
69 | -v $(pwd)/rust-ssvm:/root/rust-ssvm \
70 | secondstate/ssvm:latest
71 | ```
72 |
73 | - Install rust compile tool
74 | ```bash
75 | (docker) $ curl https://sh.rustup.rs -sSf | sh
76 | (docker) $ source ~/.cargo/env
77 | ```
78 |
79 | - Build rust-ssvm lib
80 | ```bash
81 | (docker) $ cd ~/rust-ssvm && cargo build -v
82 | ```
83 |
84 | ## Example
85 | We provide a simple demo show how to launch a ssvm instance and call vm execute function with a dummy HostContext (host functions) and `fib.wasm` demo bytecode.
86 |
87 | - The HostContext traits need implemented by chain's backend.
88 | - The `fib.wasm` was generated from [fib.yul](examples/fib.yul) written in Yul language.
89 | > [Yul](https://solidity.readthedocs.io/en/latest/yul.html) is an intermediate language designed by Ethereum fundaction.
90 | > The other project of our company call [SOLL](https://github.com/second-state/SOLL) could help you compile Yul to EWASM. [(more...)](https://github.com/second-state/SOLL/blob/master/doc/guides/DevGuide.md#compile-and-execute-yul-code)
91 |
92 | ```bash
93 | (docker) $ cd ~/rust-ssvm && cargo run --example execute_vm -v -- -f=examples/fib.wasm
94 | ```
95 |
96 | The result should be the same as the following content.
97 |
98 | ```bash
99 | Instantiate: ("ssvm", "0.4.0")
100 | Host: get_storage
101 | "0000000000000000000000000000000000000000000000000000000000000000" -> "0000000000000000000000000000000000000000000000000000000000000000"
102 | Host: set_storage
103 | "0000000000000000000000000000000000000000000000000000000000000000" -> "0000000000000000000000000000000000000000000000000000000000000001"
104 | Host: get_storage
105 | "0000000000000000000000000000000000000000000000000000000000000001" -> "0000000000000000000000000000000000000000000000000000000000000000"
106 | Host: set_storage
107 | "0000000000000000000000000000000000000000000000000000000000000001" -> "0000000000000000000000000000000000000000000000000000000000000001"
108 | Host: get_storage
109 | "0000000000000000000000000000000000000000000000000000000000000002" -> "0000000000000000000000000000000000000000000000000000000000000000"
110 | Host: set_storage
111 | "0000000000000000000000000000000000000000000000000000000000000002" -> "0000000000000000000000000000000000000000000000000000000000000002"
112 | Host: get_storage
113 | "0000000000000000000000000000000000000000000000000000000000000003" -> "0000000000000000000000000000000000000000000000000000000000000000"
114 | Host: set_storage
115 | "0000000000000000000000000000000000000000000000000000000000000003" -> "0000000000000000000000000000000000000000000000000000000000000003"
116 | Host: get_storage
117 | "0000000000000000000000000000000000000000000000000000000000000004" -> "0000000000000000000000000000000000000000000000000000000000000000"
118 | Host: set_storage
119 | "0000000000000000000000000000000000000000000000000000000000000004" -> "0000000000000000000000000000000000000000000000000000000000000005"
120 | Host: get_storage
121 | "0000000000000000000000000000000000000000000000000000000000000005" -> "0000000000000000000000000000000000000000000000000000000000000000"
122 | Host: set_storage
123 | "0000000000000000000000000000000000000000000000000000000000000005" -> "0000000000000000000000000000000000000000000000000000000000000008"
124 | Host: get_storage
125 | "0000000000000000000000000000000000000000000000000000000000000006" -> "0000000000000000000000000000000000000000000000000000000000000000"
126 | Host: set_storage
127 | "0000000000000000000000000000000000000000000000000000000000000006" -> "000000000000000000000000000000000000000000000000000000000000000d"
128 | Host: get_storage
129 | "0000000000000000000000000000000000000000000000000000000000000007" -> "0000000000000000000000000000000000000000000000000000000000000000"
130 | Host: set_storage
131 | "0000000000000000000000000000000000000000000000000000000000000007" -> "0000000000000000000000000000000000000000000000000000000000000015"
132 | Host: get_storage
133 | "0000000000000000000000000000000000000000000000000000000000000008" -> "0000000000000000000000000000000000000000000000000000000000000000"
134 | Host: set_storage
135 | "0000000000000000000000000000000000000000000000000000000000000008" -> "0000000000000000000000000000000000000000000000000000000000000022"
136 | Host: get_storage
137 | "0000000000000000000000000000000000000000000000000000000000000009" -> "0000000000000000000000000000000000000000000000000000000000000000"
138 | Host: set_storage
139 | "0000000000000000000000000000000000000000000000000000000000000009" -> "0000000000000000000000000000000000000000000000000000000000000037"
140 | Dump storage:
141 | "0000000000000000000000000000000000000000000000000000000000000000" -> "0000000000000000000000000000000000000000000000000000000000000001"
142 | "0000000000000000000000000000000000000000000000000000000000000001" -> "0000000000000000000000000000000000000000000000000000000000000001"
143 | "0000000000000000000000000000000000000000000000000000000000000002" -> "0000000000000000000000000000000000000000000000000000000000000002"
144 | "0000000000000000000000000000000000000000000000000000000000000003" -> "0000000000000000000000000000000000000000000000000000000000000003"
145 | "0000000000000000000000000000000000000000000000000000000000000004" -> "0000000000000000000000000000000000000000000000000000000000000005"
146 | "0000000000000000000000000000000000000000000000000000000000000005" -> "0000000000000000000000000000000000000000000000000000000000000008"
147 | "0000000000000000000000000000000000000000000000000000000000000006" -> "000000000000000000000000000000000000000000000000000000000000000d"
148 | "0000000000000000000000000000000000000000000000000000000000000007" -> "0000000000000000000000000000000000000000000000000000000000000015"
149 | "0000000000000000000000000000000000000000000000000000000000000008" -> "0000000000000000000000000000000000000000000000000000000000000022"
150 | "0000000000000000000000000000000000000000000000000000000000000009" -> "0000000000000000000000000000000000000000000000000000000000000037"
151 | Output: "0000000000000000000000000000000000000000000000000000000000000037"
152 | GasLeft: 49800000
153 | Status: EVMC_SUCCESS
154 | ```
155 |
156 | > If you want to see more runtime information inside SSVM, you can modify rust-ssvm/SSVM/lib/support/log.cpp as below.
157 | ```diff
158 | void setErrorLoggingLevel() {
159 | el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);
160 | - el::Loggers::setLoggingLevel(el::Level::Error);
161 | + el::Loggers::setLoggingLevel(el::Level::Debug);
162 | }
163 | ```
164 |
165 | ## EWASM Test
166 | Refer to the [EWASM Test Guide](./docs/EWASM_TEST.md) for more details.
167 |
168 | ## License
169 | Rust SSVM has dual license, including [AGPL 3.0 license](LICENSE.AGPL-3.0) and [APACHE-2 license](LICENSE.APACHE-2).
170 |
--------------------------------------------------------------------------------
/build.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Second State.
2 | // This file is part of Rust-SSVM.
3 |
4 | // Rust-SSVM is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Affero General Public License as
6 | // published by the Free Software Foundation, either version 3 of the
7 | // License, or (at your option) any later version.
8 |
9 | // Rust-SSVM is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Affero General Public License for more details.
13 |
14 | // You should have received a copy of the GNU Affero General Public License
15 | // along with this program. If not, see .
16 |
17 | use std::path::Path;
18 | extern crate cmake;
19 | use cmake::Config;
20 |
21 | fn build_link_ssvm_dylib() {
22 | let dst = Config::new("ssvm-evmc").no_build_target(true).build();
23 | let evmcssvm_path = Path::new(&dst).join("build/tools/ssvm-evmc");
24 | println!("cargo:rustc-link-search=native={}", evmcssvm_path.display());
25 | println!("cargo:rustc-link-lib=dylib=ssvm-evmc");
26 | }
27 |
28 | fn main() {
29 | build_link_ssvm_dylib();
30 | }
31 |
--------------------------------------------------------------------------------
/docs/EWASM_TEST.md:
--------------------------------------------------------------------------------
1 | # EWASM Test Guide
2 |
3 | Apart from our rust-ssvm example, we also provide an isolated ewasm test flow to test our EWASM engine (SSVM).
4 |
5 | To get started with our test flow, you will need to prepare four components at first.
6 |
7 | 1. [secondstate/ssvm](https://hub.docker.com/r/secondstate/ssvm) docker image
8 | 2. [Testeth](https://github.com/ethereum/aleth.git) with version 1.6.0
9 | 3. [Official ewasm test suite](https://github.com/ewasm/tests)
10 | 4. [SSVM](https://github.com/second-state/SSVM) with version 0.5.0 adopted by [rust-ssvm](https://github.com/second-state/rust-ssvm)
11 |
12 | - Fetch resource
13 | ```bash
14 | > docker pull secondstate/ssvm
15 | > git clone --branch v1.6.0 --recursive https://github.com/ethereum/aleth.git
16 | > git clone https://github.com/ewasm/tests.git
17 | > git clone --branch 0.5.0 https://github.com/second-state/SSVM.git
18 | ```
19 |
20 | - Copy EWASM test suite into Aleth test folder
21 | ```bash
22 | > cp tests/GeneralStateTests/stEWASMTests/* aleth/test/jsontests/GeneralStateTests/stEWASMTests/.
23 | > cp tests/src/GeneralStateTestsFiller/stEWASMTests/* aleth/test/jsontests/src/GeneralStateTestsFiller/stEWASMTests/.
24 | ```
25 |
26 | - Into Docker container (reuse secondstate/ssvm docker-image)
27 | ```bash
28 | > docker run -it --rm \
29 | -v $(pwd):/root/workspace \
30 | -w /root/workspace \
31 | secondstate/ssvm
32 | ```
33 |
34 | - Build testeth inside Aleth
35 | ```bash
36 | (docker) cd /root/workspace/aleth
37 | (docker) mkdir build; cd build # Create a build directory.
38 | (docker) cmake .. # Configure the project.
39 | (docker) cmake --build . # Build all default targets.
40 |
41 | ```
42 |
43 | - Build SSVM
44 | ```bash
45 | (docker) cd /root/workspace/SSVM
46 | (docker) mkdir -p build && cd build
47 | (docker) cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON .. && make
48 |
49 | ```
50 |
51 | - Move vm library to test folder
52 | ```bash
53 | (docker) cp /root/workspace/SSVM/build/tools/ssvm-evmc/libssvmEVMC.so /root/workspace/aleth/build/test/
54 | ```
55 |
56 | - Execute test
57 | ```bash
58 | (docker) cd /root/workspace/aleth/build/test/
59 | (docker) ./testeth -t GeneralStateTests/stEWASMTests -- --vm ./libssvmEVMC.so --singlenet "Byzantium"
60 | ```
61 |
62 | - Result
63 | ```bash
64 | Running tests using path: "../../test/jsontests"
65 | Running 1 test case...
66 | Test Case "stEWASMTests":
67 | 2020-05-27 11:09:10,742 ERROR [default] Execution failed. Code: 23
68 | 2020-05-27 11:09:10,753 ERROR [default] Execution failed. Code: 28
69 | 2020-05-27 11:09:10,756 ERROR [default] Execution failed. Code: 23
70 | /root/workspace/aleth/test/tools/libtesteth/ImportTest.cpp(768): error: in "GeneralStateTests/stEWASMTests": malformedBytecodeInvalidPreamble on Byzantium: Expected another postState hash! expected: 0x57693cf5e000607a5bf3ea9d721358cd9b5cd7f9cd3cbb7c40caf616ed7f5730 actual: 0xc47ac12abb7b3ac7f9333a6a542d5bcdd6958461846bf3f2b98275a88b969cd6 in Byzantium data: 0 gas: 0 val: 0
71 | 2020-05-27 11:09:10,771 ERROR [default] Execution failed. Code: 28
72 | 2020-05-27 11:09:10,785 ERROR [default] Execution failed. Code: 25
73 | 2020-05-27 11:09:10,793 ERROR [default] Execution failed. Code: 13
74 | 2020-05-27 11:09:10,799 ERROR [default] Execution failed. Code: 31
75 | 2020-05-27 11:09:10,805 ERROR [default] Execution failed. Code: 13
76 | 2020-05-27 11:09:10,812 ERROR [default] Execution failed. Code: 28
77 | 2020-05-27 11:09:10,816 ERROR [default] Execution failed. Code: 13
78 | 2020-05-27 11:09:10,822 ERROR [default] Execution failed. Code: 23
79 | 24%...
80 | 2020-05-27 11:09:10,833 ERROR [default] Execution failed. Code: 25
81 | 2020-05-27 11:09:10,839 ERROR [default] Execution failed. Code: 31
82 | 2020-05-27 11:09:10,841 ERROR [default] Execution failed. Code: 28
83 | 2020-05-27 11:09:10,847 ERROR [default] Execution failed. Code: 23
84 | 2020-05-27 11:09:10,876 ERROR [default] Execution failed. Code: 23
85 | 2020-05-27 11:09:10,879 ERROR [default] Execution failed. Code: 23
86 | 2020-05-27 11:09:10,882 ERROR [default] Execution failed. Code: 28
87 | 2020-05-27 11:09:10,889 ERROR [default] Execution failed. Code: 28
88 | 2020-05-27 11:09:10,897 ERROR [default] Execution failed. Code: 19
89 | 2020-05-27 11:09:10,908 ERROR [default] Execution failed. Code: 28
90 | 2020-05-27 11:09:10,915 ERROR [default] Execution failed. Code: 23
91 | 49%...
92 | 2020-05-27 11:09:10,918 ERROR [default] Execution failed. Code: 31
93 | 2020-05-27 11:09:10,920 ERROR [default] Execution failed. Code: 28
94 | 2020-05-27 11:09:10,944 ERROR [default] Execution failed. Code: 28
95 | 2020-05-27 11:09:10,948 ERROR [default] Reverted.
96 | 2020-05-27 11:09:10,965 ERROR [default] Execution failed. Code: 25
97 | 2020-05-27 11:09:10,971 ERROR [default] Execution failed. Code: 28
98 | 2020-05-27 11:09:10,976 ERROR [default] Execution failed. Code: 28
99 | 2020-05-27 11:09:10,977 ERROR [default] Execution failed. Code: 28
100 | 2020-05-27 11:09:10,982 ERROR [default] Execution failed. Code: 28
101 | 2020-05-27 11:09:10,993 ERROR [default] Execution failed. Code: 13
102 | 74%...
103 | 2020-05-27 11:09:11,009 ERROR [default] Execution failed. Code: 13
104 | 2020-05-27 11:09:11,011 ERROR [default] Execution failed. Code: 13
105 | 2020-05-27 11:09:11,014 ERROR [default] Execution failed. Code: 23
106 | 2020-05-27 11:09:11,069 ERROR [default] Execution failed. Code: 31
107 | 2020-05-27 11:09:11,086 ERROR [default] Reverted.
108 | 2020-05-27 11:09:11,095 ERROR [default] Execution failed. Code: 28
109 | 2020-05-27 11:09:11,171 ERROR [default] Execution failed. Code: 28
110 | 99%...
111 | 2020-05-27 11:09:11,177 ERROR [default] Execution failed. Code: 31
112 | 100%
113 |
114 | *** 1 failure is detected (5 failures are expected) in the test module "Master Test Suite"
115 | ```
116 |
117 | > **Known issue**
118 | The only one mismatch test case `malformedBytecodeInvalidPreamble` is already fixed in SSVM@d3f4ebd and we will release next rust-ssvm cover the solution.
--------------------------------------------------------------------------------
/examples/arith-readme.md:
--------------------------------------------------------------------------------
1 | # Deepsea arith example
2 |
3 | This example shows how to run [DeepSEA](https://github.com/certikfoundation/deepsea) language on rust-ssvm
4 |
5 | ### Compile arith.ds with DeepSEA dsc
6 |
7 | Notice that `getBlockCoinbase` and `returnDataSize` should be deleted in the generated wat file since these EEI are incompatible.
8 |
9 | ```
10 | dsc arith.ds ewasm > arith.wat
11 | wat2wasm arith.wat
12 | ```
13 |
14 | ### Run arith.wasm with rust-ssvm
15 |
16 | you could test `add` `sub` `mul` `div` function and observe their output.
17 |
18 | ```
19 | cargo run -v --example deepsea_arith \
20 | example/arith.wasm \
21 | add 3 5
22 | ```
23 |
24 |
--------------------------------------------------------------------------------
/examples/arith.ds:
--------------------------------------------------------------------------------
1 | object signature ArithInterface = {
2 | add : uint * uint -> uint;
3 | sub : uint * uint -> uint;
4 | mul : uint * uint -> uint;
5 | div : uint * uint -> uint;
6 | (* mod : uint * uint -> uint; *)
7 | }
8 |
9 | object Arith : ArithInterface {
10 | let add (n, m) =
11 | let c = n + m in
12 | assert (c >= n);
13 | n + m
14 |
15 | let sub (n, m) =
16 | assert (m <= n);
17 | n - m
18 |
19 | let mul (n, m) =
20 | if n = 0u0 then
21 | 0u0
22 | else
23 | let c = n * m in
24 | let d = c / n in
25 | assert (d = m);
26 | c
27 |
28 | let div (n, m) =
29 | assert (m > 0u0);
30 | let c = n / m in
31 | c
32 |
33 | (* let mod (n, m) =
34 | assert (m != 0);
35 | n mod m *)
36 | }
37 |
38 | layer signature ARITHSig = {
39 | arith : ArithInterface
40 | }
41 |
42 | layer ARITH : [{}] ARITHSig = {
43 | arith = Arith
44 | }
--------------------------------------------------------------------------------
/examples/arith.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/second-state/rust-ssvm/f454f641493590773f84787d64c5c090c726219c/examples/arith.wasm
--------------------------------------------------------------------------------
/examples/arith.wat:
--------------------------------------------------------------------------------
1 | (module
2 | (type (;0;) (func (param ) (result i32)))
3 | (type (;1;) (func (param i32 i32) (result i32)))
4 | (type (;2;) (func (param i32 i32) (result i32)))
5 | (type (;3;) (func (param i32 i32) (result i32)))
6 | (type (;4;) (func (param i32 i32) (result i32)))
7 | (import "ethereum" "getAddress" (func $f0 (param i32) (result )))
8 | (import "ethereum" "getExternalBalance" (func $f1 (param i32 i32) (result )))
9 | (import "ethereum" "getBlockHash" (func $f2 (param i64 i32) (result i32)))
10 | (import "ethereum" "callDataCopy" (func $f4 (param i32 i32 i32) (result )))
11 | (import "ethereum" "getCallDataSize" (func $f5 (param ) (result i32)))
12 | (import "ethereum" "callDelegate" (func $f7 (param i64 i32 i32 i32) (result i32)))
13 | (import "ethereum" "storageStore" (func $f8 (param i32 i32) (result )))
14 | (import "ethereum" "storageLoad" (func $f9 (param i32 i32) (result )))
15 | (import "ethereum" "getCaller" (func $f10 (param i32) (result )))
16 | (import "ethereum" "getCallValue" (func $f11 (param i32) (result )))
17 | (import "ethereum" "getBlockDifficulty" (func $f16 (param i32) (result )))
18 | (import "ethereum" "getGasLeft" (func $f19 (param ) (result i64)))
19 | (import "ethereum" "getBlockGasLimit" (func $f20 (param ) (result i64)))
20 | (import "ethereum" "getTxGasPrice" (func $f21 (param i32) (result )))
21 | (import "ethereum" "log" (func $f22 (param i32 i32 i32 i32 i32 i32 i32) (result )))
22 | (import "ethereum" "getBlockNumber" (func $f23 (param ) (result i64)))
23 | (import "ethereum" "getTxOrigin" (func $f24 (param i32) (result )))
24 | (import "ethereum" "useGas" (func $f25 (param i64) (result )))
25 | (import "ethereum" "getBlockTimestamp" (func $f27 (param ) (result i64)))
26 | (import "ethereum" "revert" (func $f28 (param i32 i32) (result )))
27 | (import "ethereum" "returnDataCopy" (func $f30 (param i32 i32 i32) (result )))
28 | (import "ethereum" "call" (func $f3 (param i64 i32 i32 i32 i32) (result i32)))
29 | (import "ethereum" "finish" (func $finish (param i32 i32) (result )))
30 | (memory 1)
31 | (data (i32.const 0) "0")
32 | (data (i32.const 256) "0")
33 | (data (i32.const 512) "0")
34 | (data (i32.const 768) "0")
35 | (data (i32.const 1024) "0")
36 | (data (i32.const 1280) "0")
37 | (data (i32.const 1536) "0")
38 | (data (i32.const 1792) "0")
39 | (data (i32.const 2048) "0")
40 | (data (i32.const 2304) "0")
41 | (global (mut i32) (i32.const 0)) (global (mut i32) (i32.const 0)) (global (mut i32) (i32.const 0))
42 | (export "memory" (memory 0))
43 | (export "main" (func $main))
44 | (func $f128 (param $0 i32) (param $1 i32) (result i32)
45 | (local $2 i32)
46 | (local $3 i32)
47 | (local.set $3
48 | (select
49 | (local.get $0)
50 | (i32.const 1)
51 | (i32.and
52 | (local.get $1)
53 | (i32.const 1)
54 | )
55 | )
56 | )
57 | (block $label$0
58 | (br_if $label$0
59 | (i32.eqz
60 | (local.tee $1
61 | (i32.shr_s
62 | (local.get $1)
63 | (i32.const 1)
64 | )
65 | )
66 | )
67 | )
68 | (loop $label$1
69 | (local.set $3
70 | (i32.mul
71 | (select
72 | (local.tee $0
73 | (i32.mul
74 | (local.get $0)
75 | (local.get $0)
76 | )
77 | )
78 | (i32.const 1)
79 | (i32.and
80 | (local.get $1)
81 | (i32.const 1)
82 | )
83 | )
84 | (local.get $3)
85 | )
86 | )
87 | (local.set $1
88 | (local.tee $2
89 | (i32.shr_s
90 | (local.get $1)
91 | (i32.const 1)
92 | )
93 | )
94 | )
95 | (br_if $label$1
96 | (local.get $2)
97 | )
98 | )
99 | )
100 | (local.get $3))
101 | (func $f129 (param $p0 i32) (param $p1 i32) (result i32)
102 | local.get 0
103 | )
104 | (func $f130 (param $p0 i32) (param $p1 i32) (result i32)
105 | local.get 0
106 | )
107 | (func $f131 (param $p0 i32) (param $p1 i32) (result i32)
108 | local.get 0
109 | )
110 | (func $f132 (param $p0 i32) (result i32)
111 | local.get $p0
112 | i32.const -1
113 | i32.xor)
114 | (func $set_returndata (param $value i32) (result )
115 | i32.const 256 ;; offset to store
116 | local.get $value ;; valut to store
117 | i32.store
118 | )
119 | (func $fallback (param ) (result)
120 | i32.const 256
121 | i32.const 4
122 | call $f28
123 | )
124 | (func $chendian32 (param $p0 i32) (result i32)
125 | local.get $p0
126 | i32.const 24
127 | i32.shl
128 | local.get $p0
129 | i32.const 8
130 | i32.shl
131 | i32.const 16711680
132 | i32.and
133 | i32.or
134 | local.get $p0
135 | i32.const 8
136 | i32.shr_u
137 | i32.const 65280
138 | i32.and
139 | local.get $p0
140 | i32.const 24
141 | i32.shr_u
142 | i32.or
143 | i32.or)
144 | (func $main (param ) (result )
145 | call $f5
146 | global.set 0
147 | global.get 0
148 | i32.const 3
149 | i32.le_u
150 | if
151 | i32.const 21
152 | call $set_returndata
153 | call $fallback
154 | else
155 | nop
156 | end
157 | global.get 0
158 | i32.const 4
159 | i32.sub
160 | global.set 0
161 | i32.const 4
162 | global.set 1
163 | i32.const 768
164 | i32.const 0
165 | i32.const 4
166 | call $f4
167 | i32.const 768
168 | i32.load
169 | call $chendian32
170 | global.set 2
171 | global.get 2
172 | i32.const 0x771602f7
173 | i32.eq
174 | if
175 | global.get 0
176 | i32.const 64
177 | i32.eq
178 | i32.eqz
179 | if
180 | i32.const 220
181 | call $set_returndata
182 | call $fallback
183 | else
184 | nop
185 | end
186 | i32.const 32 ;; 4 + 7 * 4 = 32, setting offset exclude name
187 | global.set 1
188 | i32.const 768
189 | global.get 1
190 | i32.const 4
191 | call $f4
192 | i32.const 768
193 | i32.load ;; load argument, which is i32
194 | call $chendian32
195 | (i32.add (global.get 1) (i32.const 32)) ;; + 8 * 4 = + 32
196 | (global.set 1)
197 | i32.const 768
198 | global.get 1
199 | i32.const 4
200 | call $f4
201 | i32.const 768
202 | i32.load ;; load argument, which is i32
203 | call $chendian32
204 | (i32.add (global.get 1) (i32.const 32)) ;; + 8 * 4 = + 32
205 | (global.set 1)
206 | (call $f257)
207 | global.set 1
208 | i32.const 256
209 | global.get 1
210 | i32.store
211 | i32.const 256
212 | i32.const 4
213 | (call $finish)
214 | else
215 | global.get 2
216 | i32.const 0xb67d77c5
217 | i32.eq
218 | if
219 | global.get 0
220 | i32.const 64
221 | i32.eq
222 | i32.eqz
223 | if
224 | i32.const 221
225 | call $set_returndata
226 | call $fallback
227 | else
228 | nop
229 | end
230 | i32.const 32 ;; 4 + 7 * 4 = 32, setting offset exclude name
231 | global.set 1
232 | i32.const 768
233 | global.get 1
234 | i32.const 4
235 | call $f4
236 | i32.const 768
237 | i32.load ;; load argument, which is i32
238 | call $chendian32
239 | (i32.add (global.get 1) (i32.const 32)) ;; + 8 * 4 = + 32
240 | (global.set 1)
241 | i32.const 768
242 | global.get 1
243 | i32.const 4
244 | call $f4
245 | i32.const 768
246 | i32.load ;; load argument, which is i32
247 | call $chendian32
248 | (i32.add (global.get 1) (i32.const 32)) ;; + 8 * 4 = + 32
249 | (global.set 1)
250 | (call $f258)
251 | global.set 1
252 | i32.const 256
253 | global.get 1
254 | i32.store
255 | i32.const 256
256 | i32.const 4
257 | (call $finish)
258 | else
259 | global.get 2
260 | i32.const 0xc8a4ac9c
261 | i32.eq
262 | if
263 | global.get 0
264 | i32.const 64
265 | i32.eq
266 | i32.eqz
267 | if
268 | i32.const 222
269 | call $set_returndata
270 | call $fallback
271 | else
272 | nop
273 | end
274 | i32.const 32 ;; 4 + 7 * 4 = 32, setting offset exclude name
275 | global.set 1
276 | i32.const 768
277 | global.get 1
278 | i32.const 4
279 | call $f4
280 | i32.const 768
281 | i32.load ;; load argument, which is i32
282 | call $chendian32
283 | (i32.add (global.get 1) (i32.const 32)) ;; + 8 * 4 = + 32
284 | (global.set 1)
285 | i32.const 768
286 | global.get 1
287 | i32.const 4
288 | call $f4
289 | i32.const 768
290 | i32.load ;; load argument, which is i32
291 | call $chendian32
292 | (i32.add (global.get 1) (i32.const 32)) ;; + 8 * 4 = + 32
293 | (global.set 1)
294 | (call $f259)
295 | global.set 1
296 | i32.const 256
297 | global.get 1
298 | i32.store
299 | i32.const 256
300 | i32.const 4
301 | (call $finish)
302 | else
303 | global.get 2
304 | i32.const 0xa391c15b
305 | i32.eq
306 | if
307 | global.get 0
308 | i32.const 64
309 | i32.eq
310 | i32.eqz
311 | if
312 | i32.const 223
313 | call $set_returndata
314 | call $fallback
315 | else
316 | nop
317 | end
318 | i32.const 32 ;; 4 + 7 * 4 = 32, setting offset exclude name
319 | global.set 1
320 | i32.const 768
321 | global.get 1
322 | i32.const 4
323 | call $f4
324 | i32.const 768
325 | i32.load ;; load argument, which is i32
326 | call $chendian32
327 | (i32.add (global.get 1) (i32.const 32)) ;; + 8 * 4 = + 32
328 | (global.set 1)
329 | i32.const 768
330 | global.get 1
331 | i32.const 4
332 | call $f4
333 | i32.const 768
334 | i32.load ;; load argument, which is i32
335 | call $chendian32
336 | (i32.add (global.get 1) (i32.const 32)) ;; + 8 * 4 = + 32
337 | (global.set 1)
338 | (call $f260)
339 | global.set 1
340 | i32.const 256
341 | global.get 1
342 | i32.store
343 | i32.const 256
344 | i32.const 4
345 | (call $finish)
346 | else
347 | i32.const 22
348 | call $set_returndata
349 | (call $fallback)
350 | end
351 | end
352 | end
353 | end
354 |
355 | )
356 | (func $constructor (type 0)
357 | (local $l0 i32)
358 | nop
359 | nop
360 | i32.const 0
361 | return
362 | )
363 | (func $f257 (type 1)
364 | (local $l2 i32)
365 | (local $l3 i32)
366 | local.get 0
367 | local.get 1
368 | i32.add
369 | local.set 3
370 | local.get 3
371 | local.get 0
372 | i32.ge_u
373 | local.set 2
374 | local.get 2
375 | if
376 | nop
377 | else
378 | i32.const 256
379 | i32.const 0
380 | call $f28
381 | end
382 | local.get 0
383 | local.get 1
384 | i32.add
385 | local.set 2
386 | local.get 2
387 | return
388 | )
389 | (func $f258 (type 2)
390 | (local $l2 i32)
391 | local.get 1
392 | local.get 0
393 | i32.le_u
394 | local.set 2
395 | local.get 2
396 | if
397 | nop
398 | else
399 | i32.const 256
400 | i32.const 0
401 | call $f28
402 | end
403 | local.get 0
404 | local.get 1
405 | i32.sub
406 | local.set 2
407 | local.get 2
408 | return
409 | )
410 | (func $f259 (type 3)
411 | (local $l2 i32)
412 | (local $l3 i32)
413 | (local $l4 i32)
414 | local.get 0
415 | i32.const 0x00
416 | i32.eq
417 | if
418 | i32.const 0x00
419 | local.set 2
420 | else
421 | local.get 0
422 | local.get 1
423 | i32.mul
424 | local.set 3
425 | local.get 3
426 | local.get 0
427 | i32.div_u
428 | local.set 4
429 | local.get 4
430 | local.get 1
431 | i32.eq
432 | local.set 2
433 | local.get 2
434 | if
435 | nop
436 | else
437 | i32.const 256
438 | i32.const 0
439 | call $f28
440 | end
441 | local.get 3
442 | local.set 2
443 | end
444 | local.get 2
445 | return
446 | )
447 | (func $f260 (type 4)
448 | (local $l2 i32)
449 | (local $l3 i32)
450 | local.get 1
451 | i32.const 0x00
452 | i32.gt_u
453 | local.set 2
454 | local.get 2
455 | if
456 | nop
457 | else
458 | i32.const 256
459 | i32.const 0
460 | call $f28
461 | end
462 | local.get 0
463 | local.get 1
464 | i32.div_u
465 | local.set 3
466 | local.get 3
467 | local.set 2
468 | local.get 2
469 | return
470 | )
471 | )
472 |
--------------------------------------------------------------------------------
/examples/deepsea_arith.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Second State.
2 | // This file is part of Rust-SSVM.
3 |
4 | // Rust-SSVM is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Affero General Public License as
6 | // published by the Free Software Foundation, either version 3 of the
7 | // License, or (at your option) any later version.
8 |
9 | // Rust-SSVM is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Affero General Public License for more details.
13 |
14 | // You should have received a copy of the GNU Affero General Public License
15 | // along with this program. If not, see .
16 |
17 | use clap::{crate_authors, crate_version, App, Arg};
18 | use std::collections::BTreeMap;
19 | use std::env;
20 | use std::fs::File;
21 | use std::io::Read;
22 |
23 | use rust_ssvm::create;
24 | use rust_ssvm::host::HostContext as HostInterface;
25 | use rust_ssvm::types::*;
26 |
27 | struct HostContext {
28 | storage: BTreeMap,
29 | }
30 |
31 | impl HostContext {
32 | fn new() -> HostContext {
33 | HostContext {
34 | storage: BTreeMap::new(),
35 | }
36 | }
37 | }
38 |
39 | impl HostInterface for HostContext {
40 | fn account_exists(&mut self, _addr: &Address) -> bool {
41 | println!("Host: account_exists");
42 | return true;
43 | }
44 | fn get_storage(&mut self, _addr: &Address, key: &Bytes32) -> Bytes32 {
45 | println!("Host: get_storage");
46 | let value = self.storage.get(key);
47 | let ret: Bytes32;
48 | match value {
49 | Some(value) => ret = value.to_owned(),
50 | None => ret = [0u8; BYTES32_LENGTH],
51 | }
52 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(ret));
53 | return ret;
54 | }
55 | fn set_storage(&mut self, _addr: &Address, key: &Bytes32, value: &Bytes32) -> StorageStatus {
56 | println!("Host: set_storage");
57 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(value));
58 | self.storage.insert(key.to_owned(), value.to_owned());
59 | return StorageStatus::EVMC_STORAGE_MODIFIED;
60 | }
61 | fn get_balance(&mut self, _addr: &Address) -> Bytes32 {
62 | println!("Host: get_balance");
63 | return [0u8; BYTES32_LENGTH];
64 | }
65 | fn get_code_size(&mut self, _addr: &Address) -> usize {
66 | println!("Host: get_code_size");
67 | return 0;
68 | }
69 | fn get_code_hash(&mut self, _addr: &Address) -> Bytes32 {
70 | println!("Host: get_code_hash");
71 | return [0u8; BYTES32_LENGTH];
72 | }
73 | fn copy_code(
74 | &mut self,
75 | _addr: &Address,
76 | _offset: &usize,
77 | _buffer_data: &*mut u8,
78 | _buffer_size: &usize,
79 | ) -> usize {
80 | println!("Host: copy_code");
81 | return 0;
82 | }
83 | fn selfdestruct(&mut self, _addr: &Address, _beneficiary: &Address) {
84 | println!("Host: selfdestruct");
85 | }
86 | fn get_tx_context(&mut self) -> (Bytes32, Address, Address, i64, i64, i64, Bytes32, Bytes32) {
87 | println!("Host: get_tx_context");
88 | return (
89 | [0u8; BYTES32_LENGTH],
90 | [0u8; ADDRESS_LENGTH],
91 | [0u8; ADDRESS_LENGTH],
92 | 0,
93 | 0,
94 | 0,
95 | [0u8; BYTES32_LENGTH],
96 | [0u8; BYTES32_LENGTH],
97 | );
98 | }
99 | fn get_block_hash(&mut self, _number: i64) -> Bytes32 {
100 | println!("Host: get_block_hash");
101 | return [0u8; BYTES32_LENGTH];
102 | }
103 | fn emit_log(&mut self, _addr: &Address, _topics: &Vec, _data: &Bytes) {
104 | println!("Host: emit_log");
105 | }
106 | fn call(
107 | &mut self,
108 | _kind: MessageKind,
109 | _destination: &Address,
110 | _sender: &Address,
111 | _value: &Bytes32,
112 | _input: &Bytes,
113 | _gas: i64,
114 | _depth: i32,
115 | _is_static: bool,
116 | _salt: &Bytes32,
117 | ) -> (Vec, i64, Address, StatusCode) {
118 | println!("Host: call");
119 | return (
120 | vec![0u8; BYTES32_LENGTH],
121 | _gas,
122 | [0u8; ADDRESS_LENGTH],
123 | StatusCode::EVMC_SUCCESS,
124 | );
125 | }
126 | }
127 |
128 | impl Drop for HostContext {
129 | fn drop(&mut self) {
130 | println!("Dump storage:");
131 | for (key, value) in &self.storage {
132 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(value));
133 | }
134 | }
135 | }
136 |
137 | fn read_a_file(path: &str) -> std::io::Result> {
138 | let mut file = File::open(path)?;
139 | let mut data = Vec::new();
140 | file.read_to_end(&mut data)?;
141 | return Ok(data);
142 | }
143 |
144 | fn main() {
145 | let args: Vec = env::args().collect();
146 |
147 | let file_path = &args[1];
148 | let funcname = &args[2];
149 | let a:i32 = (args[3]).parse().unwrap();
150 | let a_arr = a.to_be_bytes().to_vec();
151 | let b:i32 = (args[4]).parse().unwrap();
152 | let b_arr = b.to_be_bytes().to_vec();
153 |
154 |
155 | println!("{} a: {:?} b: {:?}", funcname, a_arr, b_arr);
156 |
157 | // let lib_path = "Choose specific .so path";
158 | // let (_vm, _result) = load(lib_path);
159 | let _vm = create();
160 |
161 | let msg = &[0u8; 32];
162 | let mut callData: Vec = vec![];
163 |
164 | match funcname.as_str() {
165 | "add" => callData.extend(vec![119u8,22u8,2u8,247u8]),
166 | "sub" => callData.extend(vec![182u8,125u8,119u8,197u8]),
167 | "mul" => callData.extend(vec![200u8,164u8,172u8,156u8]),
168 | "div" => callData.extend(vec![163u8,145u8,193u8,91u8]),
169 | _ => {}
170 | }
171 |
172 | let padding = vec![0u8; 28];
173 | callData.extend(&padding);
174 | callData.extend(a_arr);
175 | callData.extend(&padding);
176 | callData.extend(b_arr);
177 | println!("{:?}", callData);
178 |
179 | println!("Instantiate: {:?}", (_vm.get_name(), _vm.get_version()));
180 | match read_a_file(file_path) {
181 | Ok(code) => {
182 | let mut host_context = HostContext::new();
183 | let (output, gas_left, status_code) = _vm.execute(
184 | &mut host_context,
185 | Revision::EVMC_BYZANTIUM,
186 | MessageKind::EVMC_CALL,
187 | false,
188 | 123,
189 | 50000000,
190 | &[32u8; 20],
191 | &[128u8; 20],
192 | &callData,
193 | msg,
194 | &code[..],
195 | &[0u8; 32],
196 | );
197 | println!("Output: {:?}", output[0] as i32 + output[1] as i32 * (1 << 8) + output[2] as i32 * (1 << 16) + output[3] as i32 * (1 << 24));
198 | println!("GasLeft: {:?}", gas_left);
199 | println!("Status: {:?}", status_code);
200 | }
201 | Err(e) => println!("Error load wasm file: {:?}, {:?}", file_path, e),
202 | }
203 | _vm.destroy();
204 | }
205 |
--------------------------------------------------------------------------------
/examples/execute_vm.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Second State.
2 | // This file is part of Rust-SSVM.
3 |
4 | // Rust-SSVM is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Affero General Public License as
6 | // published by the Free Software Foundation, either version 3 of the
7 | // License, or (at your option) any later version.
8 |
9 | // Rust-SSVM is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Affero General Public License for more details.
13 |
14 | // You should have received a copy of the GNU Affero General Public License
15 | // along with this program. If not, see .
16 |
17 | use clap::{crate_authors, crate_version, App, Arg};
18 | use std::collections::BTreeMap;
19 | use std::env;
20 | use std::fs::File;
21 | use std::io::Read;
22 |
23 | use rust_ssvm::create;
24 | use rust_ssvm::host::HostContext as HostInterface;
25 | use rust_ssvm::types::*;
26 |
27 | struct HostContext {
28 | storage: BTreeMap,
29 | }
30 |
31 | impl HostContext {
32 | fn new() -> HostContext {
33 | HostContext {
34 | storage: BTreeMap::new(),
35 | }
36 | }
37 | }
38 |
39 | impl HostInterface for HostContext {
40 | fn account_exists(&mut self, _addr: &Address) -> bool {
41 | println!("Host: account_exists");
42 | return true;
43 | }
44 | fn get_storage(&mut self, _addr: &Address, key: &Bytes32) -> Bytes32 {
45 | println!("Host: get_storage");
46 | let value = self.storage.get(key);
47 | let ret: Bytes32;
48 | match value {
49 | Some(value) => ret = value.to_owned(),
50 | None => ret = [0u8; BYTES32_LENGTH],
51 | }
52 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(ret));
53 | return ret;
54 | }
55 | fn set_storage(&mut self, _addr: &Address, key: &Bytes32, value: &Bytes32) -> StorageStatus {
56 | println!("Host: set_storage");
57 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(value));
58 | self.storage.insert(key.to_owned(), value.to_owned());
59 | return StorageStatus::EVMC_STORAGE_MODIFIED;
60 | }
61 | fn get_balance(&mut self, _addr: &Address) -> Bytes32 {
62 | println!("Host: get_balance");
63 | return [0u8; BYTES32_LENGTH];
64 | }
65 | fn get_code_size(&mut self, _addr: &Address) -> usize {
66 | println!("Host: get_code_size");
67 | return 0;
68 | }
69 | fn get_code_hash(&mut self, _addr: &Address) -> Bytes32 {
70 | println!("Host: get_code_hash");
71 | return [0u8; BYTES32_LENGTH];
72 | }
73 | fn copy_code(
74 | &mut self,
75 | _addr: &Address,
76 | _offset: &usize,
77 | _buffer_data: &*mut u8,
78 | _buffer_size: &usize,
79 | ) -> usize {
80 | println!("Host: copy_code");
81 | return 0;
82 | }
83 | fn selfdestruct(&mut self, _addr: &Address, _beneficiary: &Address) {
84 | println!("Host: selfdestruct");
85 | }
86 | fn get_tx_context(&mut self) -> (Bytes32, Address, Address, i64, i64, i64, Bytes32, Bytes32) {
87 | println!("Host: get_tx_context");
88 | return (
89 | [0u8; BYTES32_LENGTH],
90 | [0u8; ADDRESS_LENGTH],
91 | [0u8; ADDRESS_LENGTH],
92 | 0,
93 | 0,
94 | 0,
95 | [0u8; BYTES32_LENGTH],
96 | [0u8; BYTES32_LENGTH],
97 | );
98 | }
99 | fn get_block_hash(&mut self, _number: i64) -> Bytes32 {
100 | println!("Host: get_block_hash");
101 | return [0u8; BYTES32_LENGTH];
102 | }
103 | fn emit_log(&mut self, _addr: &Address, _topics: &Vec, _data: &Bytes) {
104 | println!("Host: emit_log");
105 | }
106 | fn call(
107 | &mut self,
108 | _kind: MessageKind,
109 | _destination: &Address,
110 | _sender: &Address,
111 | _value: &Bytes32,
112 | _input: &Bytes,
113 | _gas: i64,
114 | _depth: i32,
115 | _is_static: bool,
116 | _salt: &Bytes32,
117 | ) -> (Vec, i64, Address, StatusCode) {
118 | println!("Host: call");
119 | return (
120 | vec![0u8; BYTES32_LENGTH],
121 | _gas,
122 | [0u8; ADDRESS_LENGTH],
123 | StatusCode::EVMC_SUCCESS,
124 | );
125 | }
126 | }
127 |
128 | impl Drop for HostContext {
129 | fn drop(&mut self) {
130 | println!("Dump storage:");
131 | for (key, value) in &self.storage {
132 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(value));
133 | }
134 | }
135 | }
136 |
137 | fn read_a_file(path: &str) -> std::io::Result> {
138 | let mut file = File::open(path)?;
139 | let mut data = Vec::new();
140 | file.read_to_end(&mut data)?;
141 | return Ok(data);
142 | }
143 |
144 | fn main() {
145 | let matches = App::new("Execute VM")
146 | .version(crate_version!())
147 | .author(crate_authors!())
148 | .about("Demo how to execute WASM bytecode use rust-ssvm")
149 | .arg(
150 | Arg::with_name("file")
151 | .short("f")
152 | .long("file")
153 | .takes_value(true)
154 | .help("wasm file path"),
155 | )
156 | .get_matches();
157 | let file_path = matches.value_of("file").unwrap();
158 |
159 | // let lib_path = "Choose specific .so path";
160 | // let (_vm, _result) = load(lib_path);
161 | let _vm = create();
162 |
163 | println!("Instantiate: {:?}", (_vm.get_name(), _vm.get_version()));
164 | match read_a_file(file_path) {
165 | Ok(code) => {
166 | let mut host_context = HostContext::new();
167 | let (output, gas_left, status_code) = _vm.execute(
168 | &mut host_context,
169 | Revision::EVMC_BYZANTIUM,
170 | MessageKind::EVMC_CALL,
171 | false,
172 | 123,
173 | 50000000,
174 | &[32u8; 20],
175 | &[128u8; 20],
176 | &[0u8; 0],
177 | &[0u8; 32],
178 | &code[..],
179 | &[0u8; 32],
180 | );
181 | println!("Output: {:?}", hex::encode(output));
182 | println!("GasLeft: {:?}", gas_left);
183 | println!("Status: {:?}", status_code);
184 | }
185 | Err(e) => println!("Error load wasm file: {:?}, {:?}", file_path, e),
186 | }
187 | _vm.destroy();
188 | }
189 |
--------------------------------------------------------------------------------
/examples/fe-readme.md:
--------------------------------------------------------------------------------
1 | # Integrate fe with rust-ssvm
2 |
3 | In this example, we would try to run fe tests under `fe/compiler/tests/fixtures`.
4 |
5 | ## Tools
6 | Build fe and Second State toolchain with the instructions inside the repository
7 |
8 | | Name | commit | Usage |
9 | |:------------------------------------------------------ |:---:| ---------------------------- |
10 | | [fe](https://github.com/ethereum/fe) | 7db1bdc | compile fe to yul IR |
11 | | [SOLL](https://github.com/second-state/soll) | d349722 | compile yul to ewasm bytecode |
12 | | [rust-ssvm](https://github.com/second-state/rust-ssvm) | dc7d33a | execute ewasm bytecode |
13 |
14 | ## Steps
15 |
16 | ### Compile \*.fe files into ewasm bytecode
17 | First, we compile \*.fe files into yul. Fe compiler does not escape ``\`` in its output, so we use `sed` to replace it.
18 |
19 | ```bash
20 | cd fe/compiler/tests/fixtures
21 | fe -e=yul -o ./return_addition_u256 ./return_addition_u256.fe
22 | cd ./return_addition_u256
23 | sed -i 's/\\//g' out.yul
24 | ```
25 |
26 | Then we could use SOLL to compile yul into ewasm bytecode
27 |
28 | ```bash
29 | soll --runtime --target=EWASM -lang=Yul out.yul
30 | ```
31 |
32 | ### execute with rust-ssvm
33 |
34 | To run with rust-ssvm, you could use fe-runner, an example in rust-ssvm.
35 |
36 | ```
37 | cd rust-ssvm/example
38 | cargo run -v --example rust-ssvm-fe-example 0xae42e951 9 11
39 | ```
40 | [\*] `0xae42e951` is the function signature of the targeting function, you are free to change it. To encode function signature, you could use API in web3.
41 | ```
42 | web3.eth.abi.encodeFunctionSignature("bar(uint256,uint256)")
43 | > 0xae42e951
44 | ```
45 |
46 | You would find the output like this:
47 |
48 | ```
49 | Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20]
50 | GasLeft: 49999982
51 | Status: EVMC_SUCCESS
52 | Dump storage:
53 | ```
54 |
55 |
--------------------------------------------------------------------------------
/examples/fe-runner.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Second State.
2 | // This file is part of Rust-SSVM.
3 |
4 | // Rust-SSVM is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Affero General Public License as
6 | // published by the Free Software Foundation, either version 3 of the
7 | // License, or (at your option) any later version.
8 |
9 | // Rust-SSVM is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Affero General Public License for more details.
13 |
14 | // You should have received a copy of the GNU Affero General Public License
15 | // along with this program. If not, see .
16 |
17 | use clap::{crate_authors, crate_version, App, Arg};
18 | use std::collections::BTreeMap;
19 | use std::env;
20 | use std::fs::File;
21 | use std::io::Read;
22 |
23 | use rust_ssvm::create;
24 | use rust_ssvm::host::HostContext as HostInterface;
25 | use rust_ssvm::types::*;
26 |
27 | struct HostContext {
28 | storage: BTreeMap,
29 | }
30 |
31 | impl HostContext {
32 | fn new() -> HostContext {
33 | HostContext {
34 | storage: BTreeMap::new(),
35 | }
36 | }
37 | }
38 |
39 | impl HostInterface for HostContext {
40 | fn account_exists(&mut self, _addr: &Address) -> bool {
41 | println!("Host: account_exists");
42 | return true;
43 | }
44 | fn get_storage(&mut self, _addr: &Address, key: &Bytes32) -> Bytes32 {
45 | println!("Host: get_storage");
46 | let value = self.storage.get(key);
47 | let ret: Bytes32;
48 | match value {
49 | Some(value) => ret = value.to_owned(),
50 | None => ret = [0u8; BYTES32_LENGTH],
51 | }
52 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(ret));
53 | return ret;
54 | }
55 | fn set_storage(&mut self, _addr: &Address, key: &Bytes32, value: &Bytes32) -> StorageStatus {
56 | println!("Host: set_storage");
57 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(value));
58 | self.storage.insert(key.to_owned(), value.to_owned());
59 | return StorageStatus::EVMC_STORAGE_MODIFIED;
60 | }
61 | fn get_balance(&mut self, _addr: &Address) -> Bytes32 {
62 | println!("Host: get_balance");
63 | return [0u8; BYTES32_LENGTH];
64 | }
65 | fn get_code_size(&mut self, _addr: &Address) -> usize {
66 | println!("Host: get_code_size");
67 | return 0;
68 | }
69 | fn get_code_hash(&mut self, _addr: &Address) -> Bytes32 {
70 | println!("Host: get_code_hash");
71 | return [0u8; BYTES32_LENGTH];
72 | }
73 | fn copy_code(
74 | &mut self,
75 | _addr: &Address,
76 | _offset: &usize,
77 | _buffer_data: &*mut u8,
78 | _buffer_size: &usize,
79 | ) -> usize {
80 | println!("Host: copy_code");
81 | return 0;
82 | }
83 | fn selfdestruct(&mut self, _addr: &Address, _beneficiary: &Address) {
84 | println!("Host: selfdestruct");
85 | }
86 | fn get_tx_context(&mut self) -> (Bytes32, Address, Address, i64, i64, i64, Bytes32, Bytes32) {
87 | println!("Host: get_tx_context");
88 | return (
89 | [0u8; BYTES32_LENGTH],
90 | [0u8; ADDRESS_LENGTH],
91 | [0u8; ADDRESS_LENGTH],
92 | 0,
93 | 0,
94 | 0,
95 | [0u8; BYTES32_LENGTH],
96 | [0u8; BYTES32_LENGTH],
97 | );
98 | }
99 | fn get_block_hash(&mut self, _number: i64) -> Bytes32 {
100 | println!("Host: get_block_hash");
101 | return [0u8; BYTES32_LENGTH];
102 | }
103 | fn emit_log(&mut self, _addr: &Address, _topics: &Vec, _data: &Bytes) {
104 | println!("Host: emit_log");
105 | }
106 | fn call(
107 | &mut self,
108 | _kind: MessageKind,
109 | _destination: &Address,
110 | _sender: &Address,
111 | _value: &Bytes32,
112 | _input: &Bytes,
113 | _gas: i64,
114 | _depth: i32,
115 | _is_static: bool,
116 | _salt: &Bytes32,
117 | ) -> (Vec, i64, Address, StatusCode) {
118 | println!("Host: call");
119 | return (
120 | vec![0u8; BYTES32_LENGTH],
121 | _gas,
122 | [0u8; ADDRESS_LENGTH],
123 | StatusCode::EVMC_SUCCESS,
124 | );
125 | }
126 | }
127 |
128 | impl Drop for HostContext {
129 | fn drop(&mut self) {
130 | println!("Dump storage:");
131 | for (key, value) in &self.storage {
132 | println!("{:?} -> {:?}", hex::encode(key), hex::encode(value));
133 | }
134 | }
135 | }
136 |
137 | fn read_a_file(path: &str) -> std::io::Result> {
138 | let mut file = File::open(path)?;
139 | let mut data = Vec::new();
140 | file.read_to_end(&mut data)?;
141 | return Ok(data);
142 | }
143 |
144 | fn main() {
145 | let args: Vec = env::args().collect();
146 |
147 | let file_path = &args[1];
148 |
149 | let without_prefix = args[2].trim_start_matches("0x");
150 | let sig = i64::from_str_radix(without_prefix, 16).unwrap();
151 | let sig_arr = sig.to_be_bytes().to_vec();
152 |
153 | let a:i32 = (args[3]).parse().unwrap();
154 | let a_arr = a.to_be_bytes().to_vec();
155 | let b:i32 = (args[4]).parse().unwrap();
156 | let b_arr = b.to_be_bytes().to_vec();
157 |
158 |
159 | println!("sig:{:?} a: {:?} b: {:?}", sig_arr, a_arr, b_arr);
160 |
161 | let _vm = create();
162 |
163 | let msg = &[0u8; 32];
164 | let mut callData: Vec = vec![];
165 |
166 | callData.extend(&sig_arr[4..8]);
167 |
168 | let padding = vec![0u8; 28];
169 | callData.extend(&padding);
170 | callData.extend(a_arr);
171 | callData.extend(&padding);
172 | callData.extend(b_arr);
173 | println!("{:?}", callData);
174 |
175 | println!("Instantiate: {:?}", (_vm.get_name(), _vm.get_version()));
176 | match read_a_file(file_path) {
177 | Ok(code) => {
178 | let mut host_context = HostContext::new();
179 | let (output, gas_left, status_code) = _vm.execute(
180 | &mut host_context,
181 | Revision::EVMC_BYZANTIUM,
182 | MessageKind::EVMC_CALL,
183 | false,
184 | 123,
185 | 50000000,
186 | &[32u8; 20],
187 | &[128u8; 20],
188 | &callData,
189 | msg,
190 | &code[..],
191 | &[0u8; 32],
192 | );
193 | println!("Output: {:?}", output);
194 | println!("GasLeft: {:?}", gas_left);
195 | println!("Status: {:?}", status_code);
196 | }
197 | Err(e) => println!("Error load wasm file: {:?}, {:?}", file_path, e),
198 | }
199 | _vm.destroy();
200 | }
201 |
--------------------------------------------------------------------------------
/examples/fib.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/second-state/rust-ssvm/f454f641493590773f84787d64c5c090c726219c/examples/fib.wasm
--------------------------------------------------------------------------------
/examples/fib.yul:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Second State.
2 | // This file is part of Rust-SSVM.
3 |
4 | // Rust-SSVM is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Affero General Public License as
6 | // published by the Free Software Foundation, either version 3 of the
7 | // License, or (at your option) any later version.
8 |
9 | // Rust-SSVM is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Affero General Public License for more details.
13 |
14 | // You should have received a copy of the GNU Affero General Public License
15 | // along with this program. If not, see .
16 |
17 | object "fib" {
18 | code {
19 | let f := 1
20 | let s := 1
21 | let next
22 | for { let i := 0 } ltu256(i, 10) { i := addu256(i, 1)}
23 | {
24 | if ltu256(i, 2) {
25 | sstore(i, 1)
26 | }
27 | if gtu256(i, 1) {
28 | next := addu256(s, f)
29 | f := s
30 | s := next
31 | sstore(i, s)
32 | }
33 | }
34 | mstore(0, next)
35 | return(0, 32)
36 | }
37 | // Unreferenced data is not added to the assembled bytecode.
38 | data "str" "Yul Fibonacci"
39 | }
40 |
--------------------------------------------------------------------------------
/shell.nix:
--------------------------------------------------------------------------------
1 | let
2 | mozillaOverlay =
3 | import (builtins.fetchGit {
4 | url = "https://github.com/mozilla/nixpkgs-mozilla.git";
5 | rev = "57c8084c7ef41366993909c20491e359bbb90f54";
6 | });
7 | nixpkgs = import { overlays = [ mozillaOverlay ]; };
8 | rust-nightly = with nixpkgs; ((rustChannelOf { date = "2020-10-23"; channel = "nightly"; }).rust.override {
9 | targets = [ "wasm32-unknown-unknown" ];
10 | });
11 | in
12 | with nixpkgs; pkgs.mkShell {
13 | buildInputs = [
14 | clang
15 | cmake
16 | pkg-config
17 | rust-nightly
18 | boost
19 | ] ++ stdenv.lib.optionals stdenv.isDarwin [
20 | darwin.apple_sdk.frameworks.Security
21 | ];
22 |
23 | LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
24 | PROTOC = "${protobuf}/bin/protoc";
25 | ROCKSDB_LIB_DIR = "${rocksdb}/lib";
26 | }
27 |
--------------------------------------------------------------------------------
/src/lib.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2020 Second State.
2 | // This file is part of Rust-SSVM.
3 |
4 | // Rust-SSVM is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Affero General Public License as
6 | // published by the Free Software Foundation, either version 3 of the
7 | // License, or (at your option) any later version.
8 |
9 | // Rust-SSVM is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Affero General Public License for more details.
13 |
14 | // You should have received a copy of the GNU Affero General Public License
15 | // along with this program. If not, see .
16 |
17 | pub use evmc_client::*;
18 |
--------------------------------------------------------------------------------
/utils/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM secondstate/ssvm
2 |
3 | ENV PATH $PATH:/root/.cargo/bin
4 | RUN curl https://sh.rustup.rs -sSf | sh -s -- -v -y
5 | RUN rustup default stable
6 | RUN rustup update nightly \
7 | && rustup target add wasm32-unknown-unknown --toolchain nightly
8 |
9 | RUN rm -rf /var/lib/apt/lists/*
10 |
--------------------------------------------------------------------------------