Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adds metering to WASM bytecode as part of conversion process per @axic #397

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "src/GeneralStateTestsFiller/stEWASMTests/utils/wabt"]
path = src/GeneralStateTestsFiller/stEWASMTests/utils/wabt
url = https://github.com/webassembly/wabt
[submodule "src/GeneralStateTestsFiller/stEWASMTests/utils/wasm-metering"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need submodule?

path = src/GeneralStateTestsFiller/stEWASMTests/utils/wasm-metering
url = https://github.com/ewasm/wasm-metering
7 changes: 6 additions & 1 deletion src/GeneralStateTestsFiller/stEWASMTests/utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ mkdir build
cd build
cmake -DBUILD_TESTS=OFF ..
make -j4
mv wat2wasm ../..
```

Install wasm-metering
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats wasm-metering?

```
cd wasm-metering
npm install
```

Setup tests script:
Expand Down
17 changes: 12 additions & 5 deletions src/GeneralStateTestsFiller/stEWASMTests/utils/convert_wast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@ def wat2wasm(code, file_name):
with open("tmp.wast", "w+") as f:
f.write(code)

result = subprocess.run(['./wat2wasm', 'tmp.wast', '-o', 'tmp.wasm'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = subprocess.run(['wabt/build/wat2wasm', 'tmp.wast', '-o', 'tmp.wasm'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if result.returncode != 0:
print('Error in ' + file_name + ':')
print('Error running wat2wasm on ' + file_name + ':')
print(result.stderr.decode('UTF-8'))
exit(1)

with open('tmp.wasm', 'rb') as f:
# Add metering
result = subprocess.run(['wasm-metering/bin/wasm-metering', 'tmp.wasm',
'tmp.metered.wasm'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if result.returncode != 0:
print('Error adding metering to ' + file_name + ':')
print(result.stderr.decode('UTF-8'))
exit(1)

with open('tmp.metered.wasm', 'rb') as f:
result = f.read()

return result.hex()

def convert_state_test(file_name):
state_test = None

state_test = yaml.load(open(file_name, 'r').read().rstrip())

if not state_test:
Expand Down
Submodule wasm-metering added at 7d63fa