Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Function body code size test #7947

Merged
merged 5 commits into from
Sep 23, 2019
Merged

Conversation

jeffreyssmith2nd
Copy link
Contributor

Change Description

  • Adds a unit test to verify that a wasm is rejected when the function body size is too large.
  • Updated several exceptions to be more specific.

Consensus Changes

  • Consensus Changes

API Changes

  • API Changes

Documentation Additions

  • Documentation Additions

unittests/wasm_tests.cpp Outdated Show resolved Hide resolved
unittests/wasm_tests.cpp Outdated Show resolved Hide resolved

Module module;
Serialization::MemoryInputStream stream((const U8*)code.data(), code.size());
BOOST_CHECK_THROW(WASM::serialize(stream, module), FatalSerializationException);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really fond of testing internal components that are not directly visible to users. We don't really care about exactly where the restriction is enforced as long as the user-visible behavior is fixed.

@@ -1843,6 +1845,39 @@ BOOST_FIXTURE_TEST_CASE( depth_tests, TESTER ) try {

} FC_LOG_AND_RETHROW()

// TODO: Update to use eos-vm once merged
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to have to update tests, just because the implementation changes.

@jeffreyssmith2nd
Copy link
Contributor Author

The code size here is wrong. It's still 0x1400006, but the correct value is now 0x14000002. The size of the code segment also needs to be adjusted.

I'm not sure I understand, since I'm just using the constraint constant.

@swatanabe-b1
Copy link
Contributor

The code size here is wrong. It's still 0x1400006, but the correct value is now 0x14000002. The size of the code segment also needs to be adjusted.

I'm not sure I understand, since I'm just using the constraint constant.

The original loop emitted more bytes than the constant. It emitted 0x1400004 bytes, because that is the next larger multiple of 7. The new version emits exactly 0x1400000 bytes, which is smaller by 4.

@jeffreyssmith2nd
Copy link
Contributor Author

The code size here is wrong. It's still 0x1400006, but the correct value is now 0x14000002. The size of the code segment also needs to be adjusted.

I'm not sure I understand, since I'm just using the constraint constant.

The original loop emitted more bytes than the constant. It emitted 0x1400004 bytes, because that is the next larger multiple of 7. The new version emits exactly 0x1400000 bytes, which is smaller by 4.

Ah I see now. It was misleadingly passing, because an exception was being thrown elsewhere in the code. Changing it to maximum_code_size + 4 hits the appropriate exception.

@jeffreyssmith2nd jeffreyssmith2nd merged commit 877e82e into develop Sep 23, 2019
@jeffreyssmith2nd jeffreyssmith2nd deleted the function-body-code-size-test branch September 23, 2019 18:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants