Skip to content

Guion 0.8.0

Latest

Choose a tag to compare

@github-actions github-actions released this 24 Nov 06:26
· 2 commits to main since this release
755631a

Additions, plus the artifact format going from 76 to 89 (older artifacts still load; a program that uses anything below needs this runtime). New in std:crypto: SHA-512 and SHA3-512, RSA, ECDSA P-256, BLS12-381, tlock, X.509 checks, Ed25519 and RFC 3161 time-stamps, all pure and checked against published vectors; with them the beacons package, which checks drand, Twine and CURBy, and NIST beacon pulses and runs in the browser VM too. New in the language: bit operations, sleep_ms, indexing Bytes, nested match patterns and constructors that infer their type from where they are used. Two behaviour changes, both stricter: crypto_tsa_verify now requires the timeStamping key usage to be marked critical, and csrf_middleware in the web package refuses a request whose Origin or Referer does not name its own Host. A Some(Red) pattern now means the enum variant Red where it used to bind a new local. Nothing is removed or re-signed.

  • csrf_middleware (the web package, now 0.2.0) also checks where a request comes from: an unsafe-method request with an Origin header (or, without one, a Referer) must name its own Host, else 403 Forbidden, before the token is looked at. Origin: null, a non-http(s) value and an Origin with no Host header are refused; with neither header the token alone decides. A deployment behind a proxy that rewrites Host must pass it through. New csrf_origin_ok(request).
  • crypto_tsa_verify now requires the TSA certificate's timeStamping extended key usage to be marked critical (RFC 3161 section 2.3); a certificate whose extension is not critical gives None. The DigiCert, Sectigo and FreeTSA certificates all mark it critical.
  • Artifact format 89: Bytes can be indexed. data[i] is the byte at zero-based i as an Int from 0 to 255; an index past the end is R_INDEX_BOUNDS and a negative one R_INDEX_INVALID (new Codec function code 20, bytes_at). An artifact below format 89 that uses it is E_ARTIFACT_VERSION; it also runs in the browser VM.
  • match takes nested patterns inside Some, Ok and Err: Ok(Some(x)), Ok(None), Err(e), Some(Red). Every value must match exactly one arm: a missing combination is E_MATCH_NONEXHAUSTIVE naming it, an overlap E_MATCH_DUPLICATE. The compiler lowers them to single-level matches, so no new artifact format. The timestamp example uses them (Ok(Some(stamp)), Ok(None), Err(problem) in one match). Behaviour change: a name inside Some, Ok or Err that equals a declared enum variant now means that variant, so Some(Red) matches Red where before it bound a new local named Red. An enum variant pattern on a value that is not that enum (Err(Red) where Err holds Text, or Red: in a match on a Text or on another enum) is now E_MATCH_TYPE naming the variant and the type found; before, it was a misleading E_MATCH_MISSING_VARIANT, E_TYPE_FIELD, or for another enum no error at all. A Some/None or Ok/Err pattern on another type now names the type it found.
  • Some, None, Ok and Err build a value wherever its type is known: a return, an annotated let, a set, an argument, a record field, a list or map element, or inside another constructor, so return Ok(None) and return Ok(Some(x)) work in a function returning Result[Option[T], E], and Some(Ok(x)), Box(Some(1)) and [Some(1), None] work anywhere. Some(x) with no expected type takes its type from x. Before, they compiled only where the type was exactly the enclosing function's result type, and E_OPTION_CONSTRUCTOR_CONTEXT / E_RESULT_CONSTRUCTOR_CONTEXT sent you to write a helper function; those codes now mean the type cannot be known (let value = None: write let value: Option[Int] = None) or another type is expected, and the message says which. No artifact format change: any other constructor is a call to a hidden function the compiler adds once per type. std:crypto's crypto_tsa_verify now writes Ok(None) and Ok(Some(TsaToken(...))) directly and its tsa_none / tsa_some helpers are gone.
  • Artifact format 88: sleep_ms(ms: Int) -> Unit blocks for at least ms milliseconds unless a polled signal arrives (0 to 86400000, else R_SLEEP_RANGE; new Op::Sleep, tag 224). No grant; guion inspect and guion doc report the effect clock.sleep. It waits in slices of at most 10 ms, so a stopped task, a wait_within deadline and Ctrl-C end it promptly. In a program that polls for signals with process_signal_poll, a signal that arrives ends one sleep early on each thread, so main and every sleeping task wake once for it; it stays pending for the next poll, and later sleeps on the same thread run their full time. A tape does not record it and a replay does not wait. The browser VM returns R_HOST_UNSUPPORTED. A function that calls it runs in the VM, not as machine code.
  • Artifact format 87: std:crypto adds RFC 3161 trusted timestamps, all pure: crypto_tsa_request(digest, nonce) (a DER request for a SHA-512 digest, byte for byte what openssl ts -query -sha512 -cert writes), crypto_tsa_response_token(response) (a refusal, status 2 to 5, is E_TSA_STATUS naming the status, status string and failInfo bits), crypto_tsa_verify(token, digest, tsa_cert, issuer_cert) (Some(TsaToken) only for a token of this digest signed by the pinned TSA certificate, issued by the pinned issuer, with the timeStamping key usage and valid at genTime; RSA PKCS#1 v1.5, RSA-PSS and ECDSA P-256 or P-384; the extended key usage must be critical, as RFC 3161 section 2.3 says, and ESS issuerSerial is not compared) and crypto_tsa_certificates(token), with record TsaToken (Crypto codes 17 to 20; the DER is read by a small strict reader in guion-crypto, plus sha1 0.10.6 for the ESSCertID hash). Checked against live DigiCert, Sectigo and FreeTSA tokens and a local OpenSSL TSA. New example language/examples/timestamp. Runs in the browser VM too. Artifacts below format 87 that use them are E_ARTIFACT_VERSION; formats 14 through 86 still load.
  • Artifact format 86: std:crypto adds pure Ed25519 (RFC 8032, not Ed25519ph, no context): crypto_ed25519_public_key(seed), crypto_ed25519_sign(seed, message) and crypto_ed25519_verify(public_key, message, signature) (Crypto codes 14 to 16; ed25519-dalek 2.2.0 without rand_core or getrandom). The 32-byte seed is an argument (draw one with crypto_random_bytes(32)), so signing is deterministic and needs no grant. Verification is strict: small-order keys and non-canonical R or S are Ok(false); a wrong length or a key that is not a curve point is E_CRYPTO_INPUT. Runs in the browser VM too. Artifacts below format 86 that use them are E_ARTIFACT_VERSION; formats 14 through 85 still load.
  • Artifact format 85: std:crypto adds crypto_x509_dns_names(der) (Crypto code 12: the SubjectAltName dNSName entries, or the subject CN only when there is no SubjectAltName extension) and crypto_x509_validity(der) (code 13: [notBefore, notAfter] as Unix seconds), so a program that pins an issuer can also check whose certificate it is. Hardening from the final review: crypto_rsa_verify now accepts moduli up to 8192 bits exactly (it stopped at 4096 before), crypto_x509_verify_issued_by returns Ok(false) when the outer signatureAlgorithm differs from the one inside the tbsCertificate, honours the saltLength of RSASSA-PSS parameters and rejects a trailerField other than 1, crypto_tlock_round and crypto_tlock_chain_hash refuse a stanza round written as +1000 or with leading zeros (E_TLOCK_FORMAT), and the documentation now says that ECDSA verification accepts both (r, s) and (r, n - s) and that "pss-sha256" means a salt as long as the digest.
  • The browser VM runs the beacon checks (guion-vm-wasm, no artifact format change, ABI stays 1.0). Every Crypto code (0 to 11) and the bit-operation Codec codes (15 to 19) already lived in the shared core; a test now runs one set of vectors, including a rejection case for each fallible code, through the wasm ABI and the native runtime and requires identical results and error codes. The check found a real gap: the Json instructions were native-only, so json_parse, json_get, json_try_* and the rest failed with R_HOST_UNSUPPORTED in the browser, and the beacon package could not read a receipt there. They now run in PortableHost with the native limits and error codes (the decoder and the json_try_* accessors moved from guion-runtime into guion-vm-core so both hosts share them; the column and projection instructions stay native-only). New optional request field limits.allowRaisedSteps lets a page raise steps above the default 10,000 up to a hard ceiling of 50,000,000 (MAX_RAISED_BROWSER_STEPS); without it nothing changes, and it moves no other ceiling. Measured: one program that checks a drand round, opens a tlock file, verifies a CURBy-Q pulse and two NIST pulses with their precommitment chain from embedded data is 167,349 bytes of artifact (limit 1 MiB, unchanged) and 34,008 steps, so it runs with a 100,000-step budget. HMAC and random bytes stay native-only, so the crypto_tlock_encrypt wrapper is not in the browser (decrypt is, and native_crypto_tlock_encrypt takes caller-supplied randomness). docs/browser.md lists what is available.
  • Printing functions run in machine code again under guion run. Native code holds what it prints and writes it out at its next print once 2 ms have passed since the last write (the first print is written at once), at 64 KiB, and when the function returns or leaves native code with the VM carrying on; if it falls back to the VM and the function is run again from its start, the lines already written are skipped in the replay, on stdout and stderr alike. A hot loop that prints and computes ran about 11 times faster in a measurement (2.19 s to 0.19 s); a held line no longer waits for the end of a long loop: functions that print check at their loop back-edges (every 256 turns) and write a line that is 2 ms old, tested with print; print; long loop; print (the hot loop above measured 0.19 s with the check). A fallback to the VM compares the replay with the lines already written and, on a difference, stops skipping instead of swallowing later output, and clears the skip after the run. eprint in native code is held the same way, which also fixes a repeated eprint line when a native function fell back to the VM without streaming. No artifact format change.
  • Artifact format 84: std:crypto adds crypto_tlock_chain_hash(armored) (the chain hash of a tlock file's stanza; Crypto code 10) and crypto_x509_verify_issued_by(certificate_der, issuer_der) (code 11: the issuer name matches and the signature verifies under the issuer key; RSA PKCS#1 v1.5 or PSS and ECDSA P-256 or P-384 with SHA-256, SHA-384 or SHA-512; other algorithms are E_X509_ALG). New pinned dependency p384 =0.13.1 (no getrandom). beacons uses them: tlock_open reads the chain hash with the built-in instead of parsing the stanza, and nist_verify checks the pulse certificate was issued by the pinned DigiCert issuer in fixtures/.
  • http_get decodes every frame of a zstd body (skippable frames skipped, one response limit over the total) and refuses bytes after the last frame with R_HTTP_ENCODING; before, only the first frame was read and the rest was dropped silently. The runtime's Json* instruction arms are gone: the native host calls the one implementation in guion-vm-core that the browser host uses, so the two cannot drift. guion run --json --replay against a changed program carries the relaxed-replay notice as tape_notice in the run report (null for an exact replay). beacons hardening: nist_verify now requires a known NIST certificate id, the pinned issuer, the name engine.beacon.nist.gov and a timeStamp inside the certificate's validity (the issuer alone accepted any certificate DigiCert had issued to anyone), and Twine, CURBy, NIST and drand reads return their documented error codes on a malformed answer instead of stopping the program.
  • http_get now verifies the zstd content checksum when a Content-Encoding: zstd frame carries one; a mismatch is R_HTTP_ENCODING (ruzstd's hash feature, adding twox-hash 2.1.4). Additive; no artifact format change.
  • Tooling and host fixes from building beacons (no artifact format change). guion test with no file, or with a directory, runs the directory's tests.gu (the file guion new --lib writes and every package here uses); an explicit file still wins, and a directory without one is tested as a project as before. The package capability check recognises hosts in every literal form a request is built from: URL literals as before (so a literal base URL that a path is added to counts) and now bare host names such as "api.example.com", "api.example.com/v2" and "api.example.com:8443" that match a declared host, and it names each declared host no literal mentions instead of one generic warning. guion run --replay of a program that has changed since the recording no longer stops at the program hash: each outside call must match the recorded one in kind, arguments (URL, headers, body, path) and order, and a note says the hash differs (a call that moved to another line or has other locals on the stack still matches; a call with other arguments, a call out of order, a missing call or an extra one is R_TAPE_DIVERGED). --replay-strict TAPE keeps the old refusal; --replay-changed still finds the first differing call by place. Tapes now carry a call_sha256 per call; older tapes lack it and are matched strictly. http_get and the other HTTP calls decode a response sent with Content-Encoding: zstd (some hosts send it unasked even though the client advertises no encoding), bounded by the response byte limit (R_HTTP_LIMIT, R_HTTP_ENCODING on bad data); pure-Rust ruzstd 0.9.1, native runtime only. beacons fetches Twine pulses by CID again and names its hosts as bare names.
  • Language and library rough spots from building beacons and the MCP server, all additive. pass is a statement that does nothing, so a match arm can be empty (E_BLOCK_EMPTY now names it; pass stays usable as a name). New builtins int_and, int_or, int_xor, int_shift_left and int_shift_right for 64-bit integers (artifact format 83, from 82; older artifacts still load; R_INTEGER_RANGE for an operand outside 64 bits, R_SHIFT_RANGE for a shift count outside 0 to 63). Every standard-library module that returns StdError re-exports it (pub import "std:http_types", as std:http did), so import "std:crypto" is enough to name StdError. std:json adds json_int_list_safe, and the reference now says which JSON accessors stop the program and which return a Result. packages/beacons uses the bit operations in its base32, varint and big-endian helpers, and language/examples/mcp_server uses match for notifications and answers wrong-typed requests with JSON-RPC -32600 or -32602 instead of exiting.
  • beacons package, part 3 (packages/beacons): the NIST Randomness Beacon 2.0 in Guion. nist_verify(pulse, certificate_pem) serializes fields 1 to 19 of a pulse as the live service signs them (4-byte big-endian length prefixes, 4-byte external.statusCode, 8-byte indexes), checks RSA PKCS#1 v1.5 with SHA-512 under the certificate's key, that certificateId is SHA-512 of the certificate's DER, and that outputValue is SHA-512 of the serialization plus the raw signature; nist_verify_precommitment(previous, current) checks previous.precommitmentValue == SHA-512(current.localRandomValue), the chain link and consecutive indexes. A tampered localRandomValue gives false. nist_fetch_last, nist_fetch and nist_fetch_certificate only fetch. Confirmed against live pulses, including a pair across a UTC day boundary; the live run is recorded in packages/beacons/tapes and replays offline. NISTIR 8213 (draft) says 8-byte length prefixes; the live service uses 4.
  • beacons package, part 2 (packages/beacons): Twine and CURBy in Guion. twine_verify recomputes a record's CID (DAG-CBOR then SHA3-512 over data), checks that the JWS payload is the SHA3-512 multihash of the DAG-CBOR of data.content, and verifies the JWS (RS256, PS256 or ES256; other algorithms are E_TWINE_ALG) under the chain's JWK; a tampered content, signature or CID is false or an error, never true. twine_verify_links / twine_verify_links_in walk back through links[0]; twine_fetch_chain, twine_fetch_latest and twine_fetch_pulse only fetch. curby_q_chain, curby_rng_chain, curby_randomness (the 64 bytes of a CURBy-Q randomness pulse) and curby_rng_randomness (CURBy-RNG, with the precommitment check). The latest CURBy-Q, CURBy-RNG and a P-256 chain pulse verify, and the bytes match CURBy's own JavaScript client; the live run is recorded in packages/beacons/tapes and replays offline.
  • beacons package, part 1 (packages/beacons, not published to the registry): base32, varint and CIDv1 helpers (base32_lower_encode, cid_v1, cid_parse), and drand quicknet in Guion over the new crypto primitives: drand_fetch (falls back from api.drand.sh to drand.cloudflare.com), drand_verify (BLS check plus randomness == SHA-256(signature)), round arithmetic, and tlock_seal / tlock_open (refuses another chain with E_TLOCK_CHAIN and a future round with E_TLOCK_TOO_EARLY). 100 consecutive live quicknet rounds verified; the run is recorded in packages/beacons/tapes and replays offline.
  • guion run writes each print and eprint as it happens instead of after main returns, so a program used as a stdio tool or read through a pipe delivers lines at once. output_limit_bytes still counts every byte. A reader that closes the pipe stops the program with the new stable code R_OUTPUT_CLOSED. guion run --json, guion test, guion serve and embedders keep buffering; HostPolicy::with_streaming_output(true) turns streaming on for an embedder.
  • std:io reads the program's own standard input (artifact format 77, from 76; older artifacts still load). stdin_read_line() -> Result[Option[Text], StdError] gives each line without its line ending and None at the end; stdin_read_all() -> Result[Bytes, StdError] gives the rest as raw bytes, bounded by max_file_bytes. [runtime] stdin_line_limit_bytes (default 1048576) bounds a line. Typed errors: E_STDIN_LINE_LIMIT, E_STDIN_UTF8, E_STDIN_READ, E_STDIN_LIMIT. Needs no grant; guion inspect reports the effect process.stdin. --record keeps what was read; the browser playground refuses it with R_HOST_UNSUPPORTED. New instructions StdinReadLine (221) and StdinReadAll (222).
  • language/examples/mcp_server is a Model Context Protocol server written in Guion: newline-delimited JSON-RPC 2.0 over stdio with initialize, ping, tools/list and an echo tool. It reads requests with stdin_read_line, answers each one as it arrives, and ends at end of input. Its guion.toml raises instruction_limit and output_limit_bytes because a long-running stdio tool would otherwise hit the script-sized defaults.
  • std:encoding adds dagcbor_encode(value: Json) -> Result[Bytes, StdError] (artifact format 82, from 81; older artifacts still load): canonical DAG-CBOR, hand-written in guion-crypto with no IPLD crate. Integers use the shortest form, other numbers are 64-bit floats, map keys sort by encoded length then bytes, {"/": "<cid>"} is a tag-42 link and {"/": {"bytes": ...}} a byte string. E_DAGCBOR_VALUE for NaN, infinities, out-of-range integers and nesting past 128 levels; E_DAGCBOR_LINK for a malformed link. Crypto function code 9, gated on format 82. Pure, so it runs in the browser playground. Checked by recomputing the CIDs of live CURBy chain records (CIDv1, dag-cbor, SHA3-512, over the whole data object). Adds serde_json to guion-crypto.
  • std:crypto adds drand timelock encryption (artifact format 81, from 80; older artifacts still load): crypto_tlock_encrypt(round, chain_hash, public_key, plaintext) -> Result[Text, StdError], crypto_tlock_decrypt(armored, round_signature) -> Result[Bytes, StdError] and crypto_tlock_round(armored) -> Result[Int, StdError]. The output is armored age, byte-compatible with drand's Go tle (tlock v1.2.0) on the quicknet network, checked in both directions. A wrong round signature or a changed file is E_TLOCK_DECRYPT, a malformed file E_TLOCK_FORMAT, bad keys or signatures E_CRYPTO_INPUT. Crypto function codes 6 to 8, gated on format 81. Pure (the wrapper draws 48 bytes with crypto_random_bytes), so it runs in the browser playground. Adds hkdf and chacha20poly1305 with no random-number source. The construction is in crates/crypto/src/tlock.md.
  • std:crypto adds crypto_bls12381_verify_g1 (artifact format 80, from 79; older artifacts still load): BLS12-381 min-signature verification (48-byte G1 signature, 96-byte G2 public key, RFC 9380 hash to G1 with the caller's domain separation tag), enough to check a drand quicknet round. Crypto function code 5, gated on format 80. Malformed or out-of-subgroup points are E_CRYPTO_INPUT; a signature that does not verify is Ok(false). Pure, so it runs in the browser playground. Adds the arkworks crates ark-bls12-381, ark-ec, ark-ff and ark-serialize (0.5.0), pinned exactly, with no random-number dependency.
  • std:crypto verifies signatures (artifact format 79, from 78; older artifacts still load): crypto_rsa_verify (PKCS#1 v1.5 with SHA-256 or SHA-512, and PSS with SHA-256), crypto_ecdsa_p256_verify (raw 64-byte r and s, SHA-256), crypto_x509_rsa_public_key (modulus and exponent from a DER certificate) and crypto_pem_decode (written in Guion over base64_decode). Crypto function codes 2 to 4, gated on format 79 per code. A malformed key, length, scheme or certificate is a typed StdError (E_CRYPTO_INPUT, E_CRYPTO_SCHEME, E_X509); a signature that does not verify is Ok(false). Verification only, and pure, so it runs in the browser playground. Adds the RustCrypto crates rsa, p256 and x509-cert, pinned exactly, with no random-number or C dependency.
  • New pure crate guion-crypto and the Crypto instruction (tag 223, artifact format 78, from 77; older artifacts still load). std:crypto gains crypto_sha512(data: Bytes) -> Bytes and crypto_sha3_512(data: Bytes) -> Bytes, 64-byte digests that need no grant. The crate does no I/O and draws no randomness, builds for wasm32-unknown-unknown, and so runs in the browser playground too. It adds the RustCrypto crates sha2 (already used) and sha3, pinned exactly.