sonic-api 0.12.0

API for formally-verifiable distributed contracts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
// SONIC: Standard library for formally-verifiable distributed contracts
//
// SPDX-License-Identifier: Apache-2.0
//
// Designed in 2019-2025 by Dr Maxim Orlovsky <orlovsky@ubideco.org>
// Written in 2024-2025 by Dr Maxim Orlovsky <orlovsky@ubideco.org>
//
// Copyright (C) 2019-2024 LNP/BP Standards Association, Switzerland.
// Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO),
//                         Institute for Distributed and Cognitive Systems (InDCS), Switzerland.
// Copyright (C) 2019-2025 Dr Maxim Orlovsky.
// All rights under the above copyrights are reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under
// the License.

//! API defines how software can interface a contract.
//!
//! SONIC provides four types of actions for working with contract (ROVT):
//! 1. _Read_ the state of the contract;
//! 2. _Operate_: construct new operations performing contract state transitions;
//! 3. _Verify_ an existing operation under the contract Codex and generate transaction;
//! 4. _Transact_: apply or roll-back transactions to the contract state.
//!
//! API defines methods for human-based interaction with the contract for read and operate actions.
//! The "verify" part is implemented in the consensus layer (UltraSONIC), the "transact" part is
//! performed directly, so these two are not covered by an API.

use core::cmp::Ordering;
use core::fmt::Debug;
use core::hash::{Hash, Hasher};
use core::num::ParseIntError;

use aluvm::{Lib, LibId};
use amplify::confinement::{SmallOrdMap, SmallOrdSet, TinyOrdMap, TinyOrdSet, TinyString};
use amplify::num::u256;
use amplify::Bytes4;
use baid64::Baid64ParseError;
use commit_verify::{CommitEncode, CommitEngine, CommitId, StrictHash};
use indexmap::{indexset, IndexMap, IndexSet};
use sonic_callreq::{CallState, MethodName, StateName};
use strict_encoding::TypeName;
use strict_types::{SemId, StrictDecode, StrictDumb, StrictEncode, StrictVal, TypeSystem};
use ultrasonic::{CallId, Codex, CodexId, StateData, StateValue};

use crate::{
    Aggregator, RawBuilder, RawConvertor, StateArithm, StateAtom, StateBuildError, StateBuilder, StateCalc,
    StateConvertError, StateConvertor, LIB_NAME_SONIC,
};

/// Errors happening during parsing of a versioned contract or codex ID.
#[derive(Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum ParseVersionedError {
    /// the versioned id '{0}' misses the version component, which should be provided after a `/`
    /// sign.
    NoVersion(String),
    /// the versioned id '{0}' misses the API checksum component, which should be provided after a
    /// `#` sign.
    NoChecksum(String),
    /// invalid versioned identifier; {0}
    Id(Baid64ParseError),
    #[from]
    /// invalid versioned number; {0}
    Version(ParseIntError),
    /// invalid API checksum value; {0}
    Checksum(Baid64ParseError),
}

/// API checksum computed from a set of contract APIs present in [`Semantics`].
///
/// # Nota bene
///
/// This is not a unique identifier!
/// It is created just for UI, so users can easily visually distinguish different sets of APIs from
/// each other.
///
/// This type is not - and must not be used in any verification.
#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)]
#[wrapper(Deref, BorrowSlice, Hex, Index, RangeOps)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_SONIC)]
pub struct ApisChecksum(
    #[from]
    #[from([u8; 4])]
    Bytes4,
);

mod _baid4 {
    use core::fmt::{self, Display, Formatter};
    use core::str::FromStr;

    use amplify::ByteArray;
    use baid64::{Baid64ParseError, DisplayBaid64, FromBaid64Str};
    use commit_verify::{CommitmentId, DigestExt, Sha256};

    use super::*;

    impl DisplayBaid64<4> for ApisChecksum {
        const HRI: &'static str = "api";
        const CHUNKING: bool = false;
        const PREFIX: bool = false;
        const EMBED_CHECKSUM: bool = false;
        const MNEMONIC: bool = false;
        fn to_baid64_payload(&self) -> [u8; 4] { self.to_byte_array() }
    }
    impl FromBaid64Str<4> for ApisChecksum {}
    impl FromStr for ApisChecksum {
        type Err = Baid64ParseError;
        fn from_str(s: &str) -> Result<Self, Self::Err> { Self::from_baid64_str(s) }
    }
    impl Display for ApisChecksum {
        fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.fmt_baid64(f) }
    }

    impl From<Sha256> for ApisChecksum {
        fn from(hasher: Sha256) -> Self {
            let hash = hasher.finish();
            Self::from_slice_checked(&hash[..4])
        }
    }

    impl CommitmentId for ApisChecksum {
        const TAG: &'static str = "urn:ubideco:sonic:apis#2025-05-25";
    }

    #[cfg(feature = "serde")]
    ultrasonic::impl_serde_str_bin_wrapper!(ApisChecksum, Bytes4);
}

/// A helper structure to store the contract semantics, made of a set of APIs, corresponding type
/// system, and libs, used by the codex.
///
/// A contract may have multiple APIs defined; this structure summarizes information about them.
/// The structure also holds a set of AluVM libraries for the codex and type system used by the
/// APIs.
#[derive(Clone, Eq, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_SONIC)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))]
pub struct Semantics {
    /// Backward-compatible version number for the issuer.
    ///
    /// This version number is used to decide which contract APIs to apply if multiple
    /// contract APIs are available.
    pub version: u16,
    /// The default API.
    pub default: Api,
    /// The custom named APIs.
    ///
    /// The mechanism of the custom APIs allows a contract to have multiple implementations
    /// of the same interface.
    ///
    /// For instance, a contract may provide multiple tokens using different token names.
    pub custom: SmallOrdMap<TypeName, Api>,
    /// A set of zk-AluVM libraries called from the contract codex.
    pub codex_libs: SmallOrdSet<Lib>,
    /// A set of AluVM libraries called from the APIs.
    pub api_libs: SmallOrdSet<Lib>,
    /// The type system used by the contract APIs.
    pub types: TypeSystem,
}

impl PartialEq for Semantics {
    fn eq(&self, other: &Self) -> bool {
        self.default.codex_id == other.default.codex_id
            && self.version == other.version
            && self.commit_id() == other.commit_id()
    }
}
impl PartialOrd for Semantics {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}
impl Ord for Semantics {
    fn cmp(&self, other: &Self) -> Ordering {
        match self.default.codex_id.cmp(&other.default.codex_id) {
            Ordering::Equal => match self.version.cmp(&other.version) {
                Ordering::Equal => self.commit_id().cmp(&other.commit_id()),
                other => other,
            },
            other => other,
        }
    }
}

impl CommitEncode for Semantics {
    type CommitmentId = ApisChecksum;
    fn commit_encode(&self, e: &mut CommitEngine) {
        e.commit_to_serialized(&self.version);
        e.commit_to_hash(&self.default);
        // We do not commit to the codex_libs since they are not a part of APIs
        // and are commit to inside the codex.
        // The fact that there are no other libs
        // is verified in the Articles and Issuer constructors.
        let apis = SmallOrdMap::from_iter_checked(
            self.custom
                .iter()
                .map(|(name, api)| (name.clone(), api.api_id())),
        );
        e.commit_to_linear_map(&apis);
        let libs = SmallOrdSet::from_iter_checked(self.api_libs.iter().map(Lib::lib_id));
        e.commit_to_linear_set(&libs);
        e.commit_to_serialized(&self.types.id());
    }
}

impl Semantics {
    pub fn apis_checksum(&self) -> ApisChecksum { self.commit_id() }

    /// Iterates over all APIs, including default and named ones.
    pub fn apis(&self) -> impl Iterator<Item = &Api> { [&self.default].into_iter().chain(self.custom.values()) }

    /// Check whether this semantics object matches codex and the provided set of libraries for it.
    pub fn check(&self, codex: &Codex) -> Result<(), SemanticError> {
        let codex_id = codex.codex_id();

        let mut ids = bset![];
        for api in self.apis() {
            if api.codex_id != codex_id {
                return Err(SemanticError::CodexMismatch);
            }
            let api_id = api.api_id();
            if !ids.insert(api_id) {
                return Err(SemanticError::DuplicatedApi(api_id));
            }
        }

        // Check codex libs for redundancies and completeness
        let lib_map = self
            .codex_libs
            .iter()
            .map(|lib| (lib.lib_id(), lib))
            .collect::<IndexMap<_, _>>();

        let mut lib_ids = codex
            .verifiers
            .values()
            .map(|entry| entry.lib_id)
            .collect::<IndexSet<_>>();
        let mut i = 0usize;
        let mut count = lib_ids.len();
        while i < count {
            let id = lib_ids.get_index(i).expect("index is valid");
            let lib = lib_map.get(id).ok_or(SemanticError::MissedCodexLib(*id))?;
            lib_ids.extend(lib.libs.iter().copied());
            count = lib_ids.len();
            i += 1;
        }
        for id in lib_map.keys() {
            if !lib_ids.contains(id) {
                return Err(SemanticError::ExcessiveCodexLib(*id));
            }
        }

        // Check API libs for redundancies and completeness
        let lib_map = self
            .api_libs
            .iter()
            .map(|lib| (lib.lib_id(), lib))
            .collect::<IndexMap<_, _>>();

        let mut lib_ids = indexset![];
        for api in self.apis() {
            for agg in api.aggregators.values() {
                if let Aggregator::AluVM(entry) = agg {
                    lib_ids.insert(entry.lib_id);
                }
            }
            for glob in api.global.values() {
                if let StateConvertor::AluVM(entry) = glob.convertor {
                    lib_ids.insert(entry.lib_id);
                }
                if let StateBuilder::AluVM(entry) = glob.builder {
                    lib_ids.insert(entry.lib_id);
                }
                if let RawConvertor::AluVM(entry) = glob.raw_convertor {
                    lib_ids.insert(entry.lib_id);
                }
                if let RawBuilder::AluVM(entry) = glob.raw_builder {
                    lib_ids.insert(entry.lib_id);
                }
            }
            for owned in api.owned.values() {
                if let StateConvertor::AluVM(entry) = owned.convertor {
                    lib_ids.insert(entry.lib_id);
                }
                if let StateBuilder::AluVM(entry) = owned.builder {
                    lib_ids.insert(entry.lib_id);
                }
                if let StateBuilder::AluVM(entry) = owned.witness_builder {
                    lib_ids.insert(entry.lib_id);
                }
                if let StateArithm::AluVM(entry) = owned.arithmetics {
                    lib_ids.insert(entry.lib_id);
                }
            }
        }
        let mut i = 0usize;
        let mut count = lib_ids.len();
        while i < count {
            let id = lib_ids.get_index(i).expect("index is valid");
            let lib = lib_map.get(id).ok_or(SemanticError::MissedApiLib(*id))?;
            lib_ids.extend(lib.libs.iter().copied());
            count = lib_ids.len();
            i += 1;
        }
        for id in lib_map.keys() {
            if !lib_ids.contains(id) {
                return Err(SemanticError::ExcessiveApiLib(*id));
            }
        }

        Ok(())
    }
}

/// API is an interface implementation.
///
/// API should work without requiring runtime to have corresponding interfaces; it should provide
/// all necessary data. Basically, one may think of API as a compiled interface hierarchy applied to
/// a specific codex.
///
/// API does not commit to an interface, since it can match multiple interfaces in the interface
/// hierarchy.
#[derive(Getters, Clone, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_SONIC)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = StrictHash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase", bound = ""))]
pub struct Api {
    /// Commitment to the codex under which the API is valid.
    #[getter(as_copy)]
    pub codex_id: CodexId,

    /// Interface standards to which the API conforms.
    pub conforms: TinyOrdSet<u16>,

    /// Name for the default API call and owned state name.
    pub default_call: Option<CallState>,

    /// State API defines how a structured global contract state is constructed out of (and
    /// converted into) UltraSONIC immutable memory cells.
    pub global: TinyOrdMap<StateName, GlobalApi>,

    /// State API defines how a structured owned contract state is constructed out of (and converted
    /// into) UltraSONIC destructible memory cells.
    pub owned: TinyOrdMap<StateName, OwnedApi>,

    /// Readers have access to the converted global `state` and can construct a derived state out of
    /// it.
    ///
    /// The typical examples when readers are used are to sum individual asset issues and compute
    /// the number of totally issued assets.
    pub aggregators: TinyOrdMap<MethodName, Aggregator>,

    /// Links between named transaction methods defined in the interface - and corresponding
    /// verifier call ids defined by the contract.
    ///
    /// NB: Multiple methods from the interface may call the came verifier.
    pub verifiers: TinyOrdMap<MethodName, CallId>,

    /// Maps error type reported by a contract verifier via `EA` value to an error description taken
    /// from the interfaces.
    pub errors: TinyOrdMap<u256, TinyString>,
}

impl PartialEq for Api {
    fn eq(&self, other: &Self) -> bool { self.cmp(other) == Ordering::Equal }
}
impl Eq for Api {}
impl PartialOrd for Api {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}
impl Ord for Api {
    fn cmp(&self, other: &Self) -> Ordering { self.api_id().cmp(&other.api_id()) }
}
impl Hash for Api {
    fn hash<H: Hasher>(&self, state: &mut H) { self.api_id().hash(state); }
}

impl Api {
    pub fn api_id(&self) -> StrictHash { self.commit_id() }

    pub fn verifier(&self, method: impl Into<MethodName>) -> Option<CallId> {
        self.verifiers.get(&method.into()).copied()
    }

    pub fn convert_global(
        &self,
        data: &StateData,
        sys: &TypeSystem,
    ) -> Result<Option<(StateName, StateAtom)>, StateConvertError> {
        // Here we do not yet know which state we are using, since it is encoded inside the field element
        // of `StateValue`. Thus, we are trying all available convertors until they succeed, since the
        // convertors check the state type. Then, we use the state name associated with the succeeding
        // convertor.
        for (name, api) in &self.global {
            if let Some(verified) = api.convertor.convert(api.sem_id, data.value, sys)? {
                let unverified =
                    if let Some(raw) = data.raw.as_ref() { Some(api.raw_convertor.convert(raw, sys)?) } else { None };
                return Ok(Some((name.clone(), StateAtom { verified, unverified })));
            }
        }
        // This means this state is unrelated to this API
        Ok(None)
    }

    pub fn convert_owned(
        &self,
        value: StateValue,
        sys: &TypeSystem,
    ) -> Result<Option<(StateName, StrictVal)>, StateConvertError> {
        // Here we do not yet know which state we are using, since it is encoded inside the field element
        // of `StateValue`. Thus, we are trying all available convertors until they succeed, since the
        // convertors check the state type. Then, we use the state name associated with the succeeding
        // convertor.
        for (name, api) in &self.owned {
            if let Some(atom) = api.convertor.convert(api.sem_id, value, sys)? {
                return Ok(Some((name.clone(), atom)));
            }
        }
        // This means this state is unrelated to this API
        Ok(None)
    }

    #[allow(clippy::result_large_err)]
    pub fn build_immutable(
        &self,
        name: impl Into<StateName>,
        data: StrictVal,
        raw: Option<StrictVal>,
        sys: &TypeSystem,
    ) -> Result<StateData, StateBuildError> {
        let name = name.into();
        let api = self
            .global
            .get(&name)
            .ok_or(StateBuildError::UnknownStateName(name))?;
        let value = api.builder.build(api.sem_id, data, sys)?;
        let raw = raw.map(|raw| api.raw_builder.build(raw, sys)).transpose()?;
        Ok(StateData { value, raw })
    }

    #[allow(clippy::result_large_err)]
    pub fn build_destructible(
        &self,
        name: impl Into<StateName>,
        data: StrictVal,
        sys: &TypeSystem,
    ) -> Result<StateValue, StateBuildError> {
        let name = name.into();
        let api = self
            .owned
            .get(&name)
            .ok_or(StateBuildError::UnknownStateName(name))?;

        api.builder.build(api.sem_id, data, sys)
    }

    #[allow(clippy::result_large_err)]
    pub fn build_witness(
        &self,
        name: impl Into<StateName>,
        data: StrictVal,
        sys: &TypeSystem,
    ) -> Result<StateValue, StateBuildError> {
        let name = name.into();
        let api = self
            .owned
            .get(&name)
            .ok_or(StateBuildError::UnknownStateName(name))?;

        api.witness_builder.build(api.witness_sem_id, data, sys)
    }

    pub fn calculate(&self, name: impl Into<StateName>) -> Result<StateCalc, StateUnknown> {
        let name = name.into();
        let api = self.owned.get(&name).ok_or(StateUnknown(name))?;

        Ok(api.arithmetics.calculator())
    }
}

/// API for global (immutable, or append-only) state.
///
/// API covers two main functions: taking structured data from the user input and _building_ a valid
/// state included in a new contract operation - and taking contract state and _converting_ it
/// into a user-friendly form, as a structured data (which may be lately used by _readers_
/// performing aggregation of state into a collection-type object).
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_SONIC)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))]
pub struct GlobalApi {
    /// Semantic type id for verifiable part of the state.
    pub sem_id: SemId,

    /// Whether the state is a published state.
    pub published: bool,

    /// Procedure which converts a state made of finite field elements [`StateValue`] into a
    /// structured type [`StrictVal`].
    pub convertor: StateConvertor,

    /// Procedure which builds a state in the form of field elements [`StateValue`] out of a
    /// structured type [`StrictVal`].
    pub builder: StateBuilder,

    /// Procedure which converts a state made of raw bytes [`RawState`] into a structured type
    /// [`StrictVal`].
    pub raw_convertor: RawConvertor,

    /// Procedure which builds a state in the form of raw bytes [`RawState`] out of a structured
    /// type [`StrictVal`].
    pub raw_builder: RawBuilder,
}

/// API for owned (destrictible, or read-once) state.
///
/// API covers two main functions: taking structured data from the user input and _building_ a valid
/// state included in a new contract operation - and taking contract state and _converting_ it
/// into a user-friendly form, as structured data. It also allows constructing a state for witness,
/// allowing destroying previously defined state.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_SONIC)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))]
pub struct OwnedApi {
    /// Semantic type id for the structured converted state data.
    pub sem_id: SemId,

    /// State arithmetics engine used in constructing new contract operations.
    pub arithmetics: StateArithm,

    /// Procedure which converts a state made of finite field elements [`StateValue`] into a
    /// structured type [`StrictVal`].
    pub convertor: StateConvertor,

    /// Procedure which builds a state in the form of field elements [`StateValue`] out of a
    /// structured type [`StrictVal`].
    pub builder: StateBuilder,

    /// Semantic type id for the witness data.
    pub witness_sem_id: SemId,

    /// Procedure which converts structured data in the form of [`StrictVal`] into a witness made of
    /// finite field elements in the form of [`StateValue`] for the destroyed previous state (an
    /// input of an operation).
    pub witness_builder: StateBuilder,
}

/// Error indicating that an API was asked to convert a state which is not known to it.
#[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)]
#[display("unknown state name '{0}'")]
pub struct StateUnknown(pub StateName);

/// Errors happening if it is attempted to construct an invalid semantic object [`Semantics`] or
/// upgrade it inside a contract issuer or articles.
#[derive(Clone, Eq, PartialEq, Debug, Display, Error)]
#[display(doc_comments)]
pub enum SemanticError {
    /// contract id for the merged contract articles doesn't match.
    ContractMismatch,

    /// codex id for the merged articles doesn't match.
    CodexMismatch,

    /// articles contain duplicated API {0} under a different name.
    DuplicatedApi(StrictHash),

    /// library {0} is used by the contract codex verifiers but absent from the articles.
    MissedCodexLib(LibId),

    /// library {0} is present in the contract articles but not used in the codex verifiers.
    ExcessiveCodexLib(LibId),

    /// library {0} is used by the contract APIs but absent from the articles.
    MissedApiLib(LibId),

    /// library {0} is present in the contract articles but not used in the APIs.
    ExcessiveApiLib(LibId),

    /// invalid signature over the contract articles.
    InvalidSignature,
}