-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from firedancer-io/harness-interface
Fuzz harness interface + ELF Loader support
- Loading branch information
Showing
14 changed files
with
437 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from test_suite.fuzz_interface import HarnessCtx | ||
import test_suite.invoke_pb2 as pb | ||
import test_suite.instr.codec_utils as instr_codec | ||
|
||
|
||
ElfHarness = HarnessCtx( | ||
fuzz_fn_name="sol_compat_elf_loader_v1", fixture_desc=pb.ELFLoaderFixture.DESCRIPTOR | ||
) | ||
|
||
InstrHarness = HarnessCtx( | ||
fuzz_fn_name="sol_compat_instr_execute_v1", | ||
fixture_desc=pb.InstrFixture.DESCRIPTOR, | ||
context_human_encode_fn=instr_codec.encode_input, | ||
context_human_decode_fn=instr_codec.decode_input, | ||
effects_human_encode_fn=instr_codec.encode_output, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import Callable, Type, TypeVar | ||
from google.protobuf import message, descriptor, message_factory | ||
from dataclasses import dataclass, InitVar | ||
|
||
msg_factory = message_factory.MessageFactory() | ||
|
||
FixtureType = TypeVar("FixtureType", bound=message.Message) | ||
ContextType = TypeVar("ContextType", bound=message.Message) | ||
EffectsType = TypeVar("EffectsType", bound=message.Message) | ||
|
||
""" | ||
Each fuzzing harness should implement this interface in fuzz_context.py | ||
The following defines the interface: | ||
- fuzz_fn_name: The name of the harness function to call in the fuzz target | ||
- fixture_desc: The protobuf descriptor for the fixture message. | ||
- A fixture message is a message that contains an input and output message. | ||
- input: The fuzz target Context | ||
- output: The fuzz target Effects | ||
- diff_effect_fn: A function that compares two effects messages for equality | ||
- human encode/decode functions for the context and effects messages to | ||
convert the messages to/from human-readable format (in-place). | ||
Both context and effects messages can have their own encode/decode functions. | ||
""" | ||
|
||
|
||
def generic_effects_diff(a: EffectsType, b: EffectsType) -> bool: | ||
return a == b | ||
|
||
|
||
def generic_human_encode(obj: message.Message) -> None: | ||
pass | ||
|
||
|
||
def generic_human_decode(obj: message.Message) -> None: | ||
pass | ||
|
||
|
||
@dataclass | ||
class HarnessCtx: | ||
fuzz_fn_name: str | ||
fixture_desc: InitVar[descriptor.Descriptor] | ||
diff_effect_fn: Callable[[EffectsType, EffectsType], bool] = generic_effects_diff | ||
context_human_encode_fn: Callable[[ContextType], None] = generic_human_encode | ||
context_human_decode_fn: Callable[[ContextType], None] = generic_human_decode | ||
effects_human_encode_fn: Callable[[EffectsType], None] = generic_human_encode | ||
effects_human_decode_fn: Callable[[EffectsType], None] = generic_human_decode | ||
fixture_type: Type[FixtureType] = message.Message | ||
context_type: Type[ContextType] = message.Message | ||
effects_type: Type[EffectsType] = message.Message | ||
|
||
def __post_init__(self, fixture_desc): | ||
self.fixture_type = msg_factory.GetPrototype(fixture_desc) | ||
self.context_type = msg_factory.GetPrototype( | ||
fixture_desc.fields_by_name["input"].message_type | ||
) | ||
self.effects_type = msg_factory.GetPrototype( | ||
fixture_desc.fields_by_name["output"].message_type | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.