Skip to main content

grillo_manifest/
lib.rs

1//! # Grillo manifest layer
2//!
3//! Grillo parses Hopper's byte-level mutation contracts. Each instruction can
4//! declare authorized data ranges and, when enabled, lamport permissions.
5//!
6//! This crate is the parser and commitment half. It reads the
7//! `hopper.manifest.json` emitted by `hopper compile --emit manifest`
8//! (renderer: `hopper_schema::codama::ManifestJson`) into a
9//! [`MutationManifest`] and can [commit](MutationManifest::commitment) to
10//! that contract with a stable `SHA-256`. The separately runnable verifier
11//! checks caller-supplied account snapshots and touch evidence against this
12//! contract. Neither crate authenticates or completes the supplied evidence.
13//!
14//! Within the supplied evidence scope, Grillo checks:
15//!
16//! > **changed subset acquired subset authorized**
17//!
18//! where acquired-but-unchanged is legal because access is not modification. This
19//! crate supplies the `authorized` set; `grillo-verifier` supplies `acquired`
20//! (from the touch map) and `changed` (from pre/post byte snapshots).
21//!
22//! ```
23//! use grillo_manifest::MutationManifest;
24//!
25//! let json = r#"{
26//!     "name": "p", "version": "1.0.0",
27//!     "instructions": [
28//!         { "name": "pause", "tag": 1, "strictWrites": true,
29//!           "writeRanges": [
30//!             { "accountIndex": 1, "offset": 114, "size": 1 },
31//!             { "accountIndex": 1, "offset": 115, "size": 8 }
32//!           ],
33//!           "accounts": [
34//!             { "name": "admin", "signer": true },
35//!             { "name": "config", "writable": true }
36//!           ] }
37//!     ]
38//! }"#;
39//! let m = MutationManifest::from_json(json).unwrap();
40//! let pause = m.instruction("pause").unwrap();
41//! assert!(pause.strict_writes);
42//! assert_eq!(pause.authorized.len(), 2);
43//! let _commitment: [u8; 32] = m.commitment();
44//! ```
45
46pub mod authority;
47mod commitment;
48mod effect_v2;
49mod manifest;
50mod resolve;
51mod sha256;
52
53pub use effect_v2::{
54    AccountRoleContractV2, AddressConstraintV2, ContractCompletenessV2, CpiAccountBindingV2,
55    CpiEnvelopeV2, CpiPolicyV2, DataPolicyV2, DataRangeV2, DeploymentBindingV2, DuplicatePolicyV2,
56    EffectContractV2, EffectContractV2Error, ExecutablePolicyV2, InstructionEffectContractV2,
57    LamportPolicyV2, LengthPolicyV2, OwnerPolicyV2, OwnerTargetV2, PresencePolicyV2,
58    PrivilegeRequirementV2, RemainingAccountsContractV2, RemainingGroupV2, TransitionPolicyV2,
59    EFFECT_ABI_V2,
60};
61pub use manifest::{
62    AccountRole, ArgContract, ArgEncodingContract, InstructionContract, MutationContractView,
63    MutationManifest, ParametricRangeContract, ParseError, RangeContract,
64};
65pub use resolve::{ResolveError, ResolvedInstructionContract, ResolvedSelector};
66pub use sha256::sha256;