-
Notifications
You must be signed in to change notification settings - Fork 0
Fuzz protocol #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fuzz protocol #340
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a89fd74
add conformance fuzz protocol impl
qiweiii 9399022
add to xcode
qiweiii 1e69e4f
fix build
qiweiii 09a0707
fix build
qiweiii 7a36e67
improve getkeys
qiweiii 054315d
use enum for fuzz jam config
qiweiii 69be161
use a iterator approach for getKeys
qiweiii 96eb2f6
remove old file
qiweiii 98a8bfd
reserve capacity
qiweiii ae869c1
fix
qiweiii 966cf39
fix test
qiweiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,64 +1,76 @@ | ||
| { | ||
| "configurations": [ | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "sourceLanguages": [ | ||
| "swift" | ||
| ], | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Boka", | ||
| "name": "Debug Boka (Boka)", | ||
| "program": "${workspaceFolder:boka}/Boka/.build/debug/Boka", | ||
| "preLaunchTask": "swift: Build Debug Boka (Boka)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "sourceLanguages": [ | ||
| "swift" | ||
| ], | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Boka", | ||
| "name": "Release Boka (Boka)", | ||
| "program": "${workspaceFolder:boka}/Boka/.build/release/Boka", | ||
| "preLaunchTask": "swift: Build Release Boka (Boka)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Cli", | ||
| "name": "Debug Cli (Cli)", | ||
| "program": "${workspaceFolder:boka}/Cli/.build/debug/Cli", | ||
| "preLaunchTask": "swift: Build Debug Cli (Cli)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Cli", | ||
| "name": "Release Cli (Cli)", | ||
| "program": "${workspaceFolder:boka}/Cli/.build/release/Cli", | ||
| "preLaunchTask": "swift: Build Release Cli (Cli)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Tools", | ||
| "name": "Debug Tools (Tools)", | ||
| "program": "${workspaceFolder:boka}/Tools/.build/debug/Tools", | ||
| "preLaunchTask": "swift: Build Debug Tools (Tools)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Tools", | ||
| "name": "Release Tools (Tools)", | ||
| "program": "${workspaceFolder:boka}/Tools/.build/release/Tools", | ||
| "preLaunchTask": "swift: Build Release Tools (Tools)" | ||
| } | ||
| ] | ||
| } | ||
| "configurations": [ | ||
| { | ||
| "type": "swift", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Boka", | ||
| "name": "Debug Boka (Boka)", | ||
| "program": "${workspaceFolder:boka}/Boka/.build/debug/Boka", | ||
| "preLaunchTask": "swift: Build Debug Boka (Boka)" | ||
| }, | ||
| { | ||
| "type": "swift", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Boka", | ||
| "name": "Release Boka (Boka)", | ||
| "program": "${workspaceFolder:boka}/Boka/.build/release/Boka", | ||
| "preLaunchTask": "swift: Build Release Boka (Boka)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Cli", | ||
| "name": "Debug Cli (Cli)", | ||
| "program": "${workspaceFolder:boka}/Cli/.build/debug/Cli", | ||
| "preLaunchTask": "swift: Build Debug Cli (Cli)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Cli", | ||
| "name": "Release Cli (Cli)", | ||
| "program": "${workspaceFolder:boka}/Cli/.build/release/Cli", | ||
| "preLaunchTask": "swift: Build Release Cli (Cli)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Tools", | ||
| "name": "Debug Tools (Tools)", | ||
| "program": "${workspaceFolder:boka}/Tools/.build/debug/Tools", | ||
| "preLaunchTask": "swift: Build Debug Tools (Tools)" | ||
| }, | ||
| { | ||
| "type": "lldb", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Tools", | ||
| "name": "Release Tools (Tools)", | ||
| "program": "${workspaceFolder:boka}/Tools/.build/release/Tools", | ||
| "preLaunchTask": "swift: Build Release Tools (Tools)" | ||
| }, | ||
| { | ||
| "type": "swift", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Fuzzing", | ||
| "name": "Debug BokaFuzzer (Fuzzing)", | ||
| "program": "${workspaceFolder:boka}/Fuzzing/.build/debug/BokaFuzzer", | ||
| "preLaunchTask": "swift: Build Debug BokaFuzzer (Fuzzing)" | ||
| }, | ||
| { | ||
| "type": "swift", | ||
| "request": "launch", | ||
| "args": [], | ||
| "cwd": "${workspaceFolder:boka}/Fuzzing", | ||
| "name": "Release BokaFuzzer (Fuzzing)", | ||
| "program": "${workspaceFolder:boka}/Fuzzing/.build/release/BokaFuzzer", | ||
| "preLaunchTask": "swift: Build Release BokaFuzzer (Fuzzing)" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,80 @@ | ||
| import ArgumentParser | ||
| import Foundation | ||
| import Fuzzing | ||
| import Logging | ||
|
|
||
| extension Boka { | ||
| struct Fuzz: AsyncParsableCommand { | ||
| static let configuration = CommandConfiguration( | ||
| commandName: "fuzz", | ||
| abstract: "JAM Conformance Protocol", | ||
| subcommands: [Target.self, Fuzzer.self] | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| extension Boka.Fuzz { | ||
| struct Target: AsyncParsableCommand { | ||
| static let configuration = CommandConfiguration( | ||
| abstract: "Run fuzzing target - waits for fuzzer connections" | ||
| ) | ||
|
|
||
| @Option(help: "Unix socket path for fuzzing protocol") | ||
| var socketPath: String = "/tmp/jam_conformance.sock" | ||
|
|
||
| @Option(help: "JAM Protocol configuration preset, tiny or full") | ||
| var config: String = "tiny" | ||
qiweiii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| func run() async throws { | ||
| let env = ProcessInfo.processInfo.environment | ||
| LoggingSystem.bootstrap { label in | ||
| var handler = StreamLogHandler.standardOutput(label: label) | ||
| handler.logLevel = parseLevel(env["LOG_LEVEL"] ?? "") ?? .info | ||
| return handler | ||
| } | ||
|
|
||
| let fuzzTarget = try FuzzingTarget( | ||
| socketPath: socketPath, | ||
| config: config | ||
| ) | ||
|
|
||
| try await fuzzTarget.run() | ||
| } | ||
| } | ||
|
|
||
| struct Fuzzer: AsyncParsableCommand { | ||
| static let configuration = CommandConfiguration( | ||
| abstract: "Run fuzzing fuzzer - connects to targets" | ||
| ) | ||
|
|
||
| @Option(help: "Unix socket path for fuzzing protocol.") | ||
| var socketPath: String = "/tmp/jam_conformance.sock" | ||
|
|
||
| @Option(help: "JAM Protocol configuration preset.") | ||
| var config: String = "tiny" | ||
|
|
||
| @Option(name: .long, help: "Random seed for deterministic testing. Default is random") | ||
| var seed: UInt64 = .random(in: 0 ... UInt64.max) | ||
|
|
||
| @Option(name: .long, help: "Number of blocks to process.") | ||
| var blocks: Int = 100 | ||
|
|
||
| func run() async throws { | ||
| let env = ProcessInfo.processInfo.environment | ||
| LoggingSystem.bootstrap { label in | ||
| var handler = StreamLogHandler.standardOutput(label: label) | ||
| handler.logLevel = parseLevel(env["LOG_LEVEL"] ?? "") ?? .info | ||
| return handler | ||
| } | ||
|
|
||
| let fuzzer = try FuzzingClient( | ||
| socketPath: socketPath, | ||
| config: config, | ||
| seed: seed, | ||
| blockCount: blocks | ||
| ) | ||
|
|
||
| try await fuzzer.run() | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,48 @@ | ||
| // swift-tools-version: 6.0 | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "Fuzzing", | ||
| platforms: [ | ||
| .macOS(.v15), | ||
| ], | ||
| products: [ | ||
| .library( | ||
| name: "Fuzzing", | ||
| targets: ["Fuzzing"] | ||
| ), | ||
| ], | ||
| dependencies: [ | ||
| .package(path: "../Blockchain"), | ||
| .package(path: "../Codec"), | ||
| .package(path: "../TracingUtils"), | ||
| .package(path: "../Utils"), | ||
| .package(url: "https://github.com/apple/swift-testing.git", branch: "6.0.0"), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "Fuzzing", | ||
| dependencies: [ | ||
| "Blockchain", | ||
| "Codec", | ||
| "TracingUtils", | ||
| "Utils", | ||
| ], | ||
| swiftSettings: [ | ||
| .interoperabilityMode(.Cxx), | ||
| ] | ||
| ), | ||
| .testTarget( | ||
| name: "FuzzingTests", | ||
| dependencies: [ | ||
| "Fuzzing", | ||
| .product(name: "Testing", package: "swift-testing"), | ||
| ], | ||
| swiftSettings: [ | ||
| .interoperabilityMode(.Cxx), | ||
| ] | ||
| ), | ||
| ], | ||
| swiftLanguageModes: [.version("6")] | ||
| ) |
This file contains hidden or 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,29 @@ | ||
| import Blockchain | ||
| import Codec | ||
| import Foundation | ||
| import Utils | ||
|
|
||
| /// Protocol for generating fuzzing test data | ||
| public protocol FuzzGenerator { | ||
| /// Generate initial state for fuzzing | ||
| /// - Parameters: | ||
| /// - timeslot: The timeslot for which to generate the state | ||
| /// - config: Protocol configuration | ||
| /// - Returns: Array of fuzz key-value pairs representing the state | ||
| func generateState(timeslot: TimeslotIndex, config: ProtocolConfigRef) async throws -> [FuzzKeyValue] | ||
|
|
||
| /// Generate a block for the given timeslot and state | ||
| /// - Parameters: | ||
| /// - timeslot: The timeslot for which to generate the block | ||
| /// - currentStateRef: Current state reference | ||
| /// - config: Protocol configuration | ||
| /// - Returns: A valid block reference | ||
| func generateBlock(timeslot: UInt32, currentStateRef: StateRef, config: ProtocolConfigRef) async throws -> BlockRef | ||
| } | ||
|
|
||
| /// Error types for fuzz generators | ||
| public enum FuzzGeneratorError: Error { | ||
| case stateGenerationFailed(String) | ||
| case blockGenerationFailed(String) | ||
| case invalidTestData(String) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.