Class: Vangrail::AdaptiveAttackMatrix
- Inherits:
-
Object
- Object
- Vangrail::AdaptiveAttackMatrix
- Includes:
- ArtifactData
- Defined in:
- lib/vangrail/adaptive_attack_matrix.rb
Overview
Versioned adaptive cases with explicit access, budget, and utility constraints.
Constant Summary collapse
- SCHEMA =
'vangrail-adaptive-attack-matrix-v1'- FAMILIES =
%w[ obfuscation encoding multilingual role_impersonation paraphrase score_query binary_query black_box_search reinforcement_learning white_box argument_steering conditional_dummy long_horizon cross_tool memory_poisoning policy_laundering grant_replay use_exhaustion retry_exploitation sink_exfiltration human_red_team ].freeze
- ACCESS =
%w[black_box score_query binary_query white_box human].freeze
- SPLITS =
%w[train calibration threshold test].freeze
- FIELDS =
%w[schema id version cases].freeze
- CASE_FIELDS =
%w[ id parent_case_id family split language domain origin access attack_budget seed utility_constraint scenario ].freeze
- MAX_CASES =
100_000- MAX_BYTES =
16 * 1024 * 1024
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#sha256 ⇒ Object
readonly
Returns the value of attribute sha256.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(raw = nil, source_sha256: nil, **fields) ⇒ AdaptiveAttackMatrix
constructor
A new instance of AdaptiveAttackMatrix.
- #to_h ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(raw = nil, source_sha256: nil, **fields) ⇒ AdaptiveAttackMatrix
Returns a new instance of AdaptiveAttackMatrix.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vangrail/adaptive_attack_matrix.rb', line 32 def initialize(raw = nil, source_sha256: nil, **fields) raw = fields if raw.nil? raise ArtifactError, 'adaptive attack matrix fields are ambiguous' unless fields.empty? || raw.equal?(fields) raise ArtifactError, 'adaptive attack matrix must be a hash' unless raw.is_a?(Hash) @data = stringify(raw) validate! encoded = canonical(@data) raise ArtifactError, "adaptive attack matrix exceeds #{MAX_BYTES} bytes" if encoded.bytesize > MAX_BYTES @sha256 = (source_sha256 || Digest::SHA256.hexdigest(encoded)).freeze @data = immutable(@data) freeze end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
30 31 32 |
# File 'lib/vangrail/adaptive_attack_matrix.rb', line 30 def data @data end |
#sha256 ⇒ Object (readonly)
Returns the value of attribute sha256.
30 31 32 |
# File 'lib/vangrail/adaptive_attack_matrix.rb', line 30 def sha256 @sha256 end |
Class Method Details
.load(path, expected_sha256: nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vangrail/adaptive_attack_matrix.rb', line 47 def self.load(path, expected_sha256: nil) size = File.size(path) raise ArtifactError, "adaptive attack matrix exceeds #{MAX_BYTES} bytes" if size > MAX_BYTES bytes = File.binread(path) actual = Digest::SHA256.hexdigest(bytes) raise ArtifactError, 'adaptive attack matrix hash does not match' if expected_sha256 && actual != expected_sha256 new(JSON.parse(bytes), source_sha256: actual) rescue JSON::ParserError => e raise ArtifactError, "adaptive attack matrix is not JSON: #{e.}" end |
Instance Method Details
#id ⇒ Object
64 65 66 |
# File 'lib/vangrail/adaptive_attack_matrix.rb', line 64 def id data['id'] end |
#to_h ⇒ Object
60 61 62 |
# File 'lib/vangrail/adaptive_attack_matrix.rb', line 60 def to_h data end |
#version ⇒ Object
68 69 70 |
# File 'lib/vangrail/adaptive_attack_matrix.rb', line 68 def version data['version'] end |