Repository navigation
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(thewebpackage, now 0.2.0) also checks where a request comes from: an unsafe-method request with anOriginheader (or, without one, aReferer) must name its ownHost, else 403Forbidden, before the token is looked at.Origin: null, a non-http(s) value and an Origin with noHostheader are refused; with neither header the token alone decides. A deployment behind a proxy that rewritesHostmust pass it through. Newcsrf_origin_ok(request).crypto_tsa_verifynow requires the TSA certificate'stimeStampingextended key usage to be marked critical (RFC 3161 section 2.3); a certificate whose extension is not critical givesNone. The DigiCert, Sectigo and FreeTSA certificates all mark it critical.- Artifact format 89:
Bytescan be indexed.data[i]is the byte at zero-basedias anIntfrom 0 to 255; an index past the end isR_INDEX_BOUNDSand a negative oneR_INDEX_INVALID(newCodecfunction code 20,bytes_at). An artifact below format 89 that uses it isE_ARTIFACT_VERSION; it also runs in the browser VM. matchtakes nested patterns insideSome,OkandErr:Ok(Some(x)),Ok(None),Err(e),Some(Red). Every value must match exactly one arm: a missing combination isE_MATCH_NONEXHAUSTIVEnaming it, an overlapE_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 onematch). Behaviour change: a name insideSome,OkorErrthat equals a declared enum variant now means that variant, soSome(Red)matchesRedwhere before it bound a new local namedRed. An enum variant pattern on a value that is not that enum (Err(Red)whereErrholdsText, orRed:in amatchon aTextor on another enum) is nowE_MATCH_TYPEnaming the variant and the type found; before, it was a misleadingE_MATCH_MISSING_VARIANT,E_TYPE_FIELD, or for another enum no error at all. ASome/NoneorOk/Errpattern on another type now names the type it found.Some,None,OkandErrbuild a value wherever its type is known: a return, an annotatedlet, aset, an argument, a record field, a list or map element, or inside another constructor, soreturn Ok(None)andreturn Ok(Some(x))work in a function returningResult[Option[T], E], andSome(Ok(x)),Box(Some(1))and[Some(1), None]work anywhere.Some(x)with no expected type takes its type fromx. Before, they compiled only where the type was exactly the enclosing function's result type, andE_OPTION_CONSTRUCTOR_CONTEXT/E_RESULT_CONSTRUCTOR_CONTEXTsent you to write a helper function; those codes now mean the type cannot be known (let value = None: writelet 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'scrypto_tsa_verifynow writesOk(None)andOk(Some(TsaToken(...)))directly and itstsa_none/tsa_somehelpers are gone.- Artifact format 88:
sleep_ms(ms: Int) -> Unitblocks for at leastmsmilliseconds unless a polled signal arrives (0 to 86400000, elseR_SLEEP_RANGE; newOp::Sleep, tag 224). No grant;guion inspectandguion docreport the effectclock.sleep. It waits in slices of at most 10 ms, so a stopped task, await_withindeadline and Ctrl-C end it promptly. In a program that polls for signals withprocess_signal_poll, a signal that arrives ends one sleep early on each thread, somainand 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 returnsR_HOST_UNSUPPORTED. A function that calls it runs in the VM, not as machine code. - Artifact format 87:
std:cryptoadds RFC 3161 trusted timestamps, all pure:crypto_tsa_request(digest, nonce)(a DER request for a SHA-512 digest, byte for byte whatopenssl ts -query -sha512 -certwrites),crypto_tsa_response_token(response)(a refusal, status 2 to 5, isE_TSA_STATUSnaming 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 thetimeStampingkey usage and valid atgenTime; 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 ESSissuerSerialis not compared) andcrypto_tsa_certificates(token), withrecord TsaToken(Crypto codes 17 to 20; the DER is read by a small strict reader inguion-crypto, plussha10.10.6 for the ESSCertID hash). Checked against live DigiCert, Sectigo and FreeTSA tokens and a local OpenSSL TSA. New examplelanguage/examples/timestamp. Runs in the browser VM too. Artifacts below format 87 that use them areE_ARTIFACT_VERSION; formats 14 through 86 still load. - Artifact format 86:
std:cryptoadds pure Ed25519 (RFC 8032, not Ed25519ph, no context):crypto_ed25519_public_key(seed),crypto_ed25519_sign(seed, message)andcrypto_ed25519_verify(public_key, message, signature)(Crypto codes 14 to 16;ed25519-dalek2.2.0 withoutrand_coreorgetrandom). The 32-byte seed is an argument (draw one withcrypto_random_bytes(32)), so signing is deterministic and needs no grant. Verification is strict: small-order keys and non-canonicalRorSareOk(false); a wrong length or a key that is not a curve point isE_CRYPTO_INPUT. Runs in the browser VM too. Artifacts below format 86 that use them areE_ARTIFACT_VERSION; formats 14 through 85 still load. - Artifact format 85:
std:cryptoaddscrypto_x509_dns_names(der)(Crypto code 12: the SubjectAltName dNSName entries, or the subject CN only when there is no SubjectAltName extension) andcrypto_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_verifynow accepts moduli up to 8192 bits exactly (it stopped at 4096 before),crypto_x509_verify_issued_byreturnsOk(false)when the outersignatureAlgorithmdiffers from the one inside thetbsCertificate, honours thesaltLengthof RSASSA-PSS parameters and rejects atrailerFieldother than 1,crypto_tlock_roundandcrypto_tlock_chain_hashrefuse a stanza round written as+1000or 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). EveryCryptocode (0 to 11) and the bit-operationCodeccodes (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: theJsoninstructions were native-only, sojson_parse,json_get,json_try_*and the rest failed withR_HOST_UNSUPPORTEDin the browser, and the beacon package could not read a receipt there. They now run inPortableHostwith the native limits and error codes (the decoder and thejson_try_*accessors moved fromguion-runtimeintoguion-vm-coreso both hosts share them; the column and projection instructions stay native-only). New optional request fieldlimits.allowRaisedStepslets a page raisestepsabove 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 thecrypto_tlock_encryptwrapper is not in the browser (decrypt is, andnative_crypto_tlock_encrypttakes caller-supplied randomness).docs/browser.mdlists 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 withprint; 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.eprintin native code is held the same way, which also fixes a repeatedeprintline when a native function fell back to the VM without streaming. No artifact format change. - Artifact format 84:
std:cryptoaddscrypto_tlock_chain_hash(armored)(the chain hash of a tlock file's stanza; Crypto code 10) andcrypto_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 areE_X509_ALG). New pinned dependencyp384=0.13.1 (no getrandom).beaconsuses them:tlock_openreads the chain hash with the built-in instead of parsing the stanza, andnist_verifychecks the pulse certificate was issued by the pinned DigiCert issuer infixtures/. http_getdecodes every frame of a zstd body (skippable frames skipped, one response limit over the total) and refuses bytes after the last frame withR_HTTP_ENCODING; before, only the first frame was read and the rest was dropped silently. The runtime'sJson*instruction arms are gone: the native host calls the one implementation inguion-vm-corethat the browser host uses, so the two cannot drift.guion run --json --replayagainst a changed program carries the relaxed-replay notice astape_noticein the run report (null for an exact replay).beaconshardening:nist_verifynow requires a known NIST certificate id, the pinned issuer, the nameengine.beacon.nist.govand atimeStampinside 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_getnow verifies the zstd content checksum when aContent-Encoding: zstdframe carries one; a mismatch isR_HTTP_ENCODING(ruzstd'shashfeature, addingtwox-hash2.1.4). Additive; no artifact format change.- Tooling and host fixes from building
beacons(no artifact format change).guion testwith no file, or with a directory, runs the directory'stests.gu(the fileguion new --libwrites 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 --replayof 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 isR_TAPE_DIVERGED).--replay-strict TAPEkeeps the old refusal;--replay-changedstill finds the first differing call by place. Tapes now carry acall_sha256per call; older tapes lack it and are matched strictly.http_getand the other HTTP calls decode a response sent withContent-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_ENCODINGon bad data); pure-Rustruzstd0.9.1, native runtime only.beaconsfetches Twine pulses by CID again and names its hosts as bare names. - Language and library rough spots from building
beaconsand the MCP server, all additive.passis a statement that does nothing, so amatcharm can be empty (E_BLOCK_EMPTYnow names it;passstays usable as a name). New builtinsint_and,int_or,int_xor,int_shift_leftandint_shift_rightfor 64-bit integers (artifact format 83, from 82; older artifacts still load;R_INTEGER_RANGEfor an operand outside 64 bits,R_SHIFT_RANGEfor a shift count outside 0 to 63). Every standard-library module that returnsStdErrorre-exports it (pub import "std:http_types", asstd:httpdid), soimport "std:crypto"is enough to nameStdError.std:jsonaddsjson_int_list_safe, and the reference now says which JSON accessors stop the program and which return aResult.packages/beaconsuses the bit operations in its base32, varint and big-endian helpers, andlanguage/examples/mcp_serverusesmatchfor notifications and answers wrong-typed requests with JSON-RPC-32600or-32602instead of exiting. beaconspackage, 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-byteexternal.statusCode, 8-byte indexes), checks RSA PKCS#1 v1.5 with SHA-512 under the certificate's key, thatcertificateIdis SHA-512 of the certificate's DER, and thatoutputValueis SHA-512 of the serialization plus the raw signature;nist_verify_precommitment(previous, current)checksprevious.precommitmentValue == SHA-512(current.localRandomValue), the chain link and consecutive indexes. A tamperedlocalRandomValuegivesfalse.nist_fetch_last,nist_fetchandnist_fetch_certificateonly fetch. Confirmed against live pulses, including a pair across a UTC day boundary; the live run is recorded inpackages/beacons/tapesand replays offline. NISTIR 8213 (draft) says 8-byte length prefixes; the live service uses 4.beaconspackage, part 2 (packages/beacons): Twine and CURBy in Guion.twine_verifyrecomputes a record's CID (DAG-CBOR then SHA3-512 overdata), checks that the JWS payload is the SHA3-512 multihash of the DAG-CBOR ofdata.content, and verifies the JWS (RS256, PS256 or ES256; other algorithms areE_TWINE_ALG) under the chain's JWK; a tampered content, signature or CID isfalseor an error, nevertrue.twine_verify_links/twine_verify_links_inwalk back throughlinks[0];twine_fetch_chain,twine_fetch_latestandtwine_fetch_pulseonly fetch.curby_q_chain,curby_rng_chain,curby_randomness(the 64 bytes of a CURBy-Q randomness pulse) andcurby_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 inpackages/beacons/tapesand replays offline.beaconspackage, 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 fromapi.drand.shtodrand.cloudflare.com),drand_verify(BLS check plusrandomness == SHA-256(signature)), round arithmetic, andtlock_seal/tlock_open(refuses another chain withE_TLOCK_CHAINand a future round withE_TLOCK_TOO_EARLY). 100 consecutive live quicknet rounds verified; the run is recorded inpackages/beacons/tapesand replays offline.guion runwrites eachprintandeprintas it happens instead of aftermainreturns, so a program used as a stdio tool or read through a pipe delivers lines at once.output_limit_bytesstill counts every byte. A reader that closes the pipe stops the program with the new stable codeR_OUTPUT_CLOSED.guion run --json,guion test,guion serveand embedders keep buffering;HostPolicy::with_streaming_output(true)turns streaming on for an embedder.std:ioreads 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 andNoneat the end;stdin_read_all() -> Result[Bytes, StdError]gives the rest as raw bytes, bounded bymax_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 inspectreports the effectprocess.stdin.--recordkeeps what was read; the browser playground refuses it withR_HOST_UNSUPPORTED. New instructionsStdinReadLine(221) andStdinReadAll(222).language/examples/mcp_serveris a Model Context Protocol server written in Guion: newline-delimited JSON-RPC 2.0 over stdio withinitialize,ping,tools/listand anechotool. It reads requests withstdin_read_line, answers each one as it arrives, and ends at end of input. Itsguion.tomlraisesinstruction_limitandoutput_limit_bytesbecause a long-running stdio tool would otherwise hit the script-sized defaults.std:encodingaddsdagcbor_encode(value: Json) -> Result[Bytes, StdError](artifact format 82, from 81; older artifacts still load): canonical DAG-CBOR, hand-written inguion-cryptowith 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_VALUEfor NaN, infinities, out-of-range integers and nesting past 128 levels;E_DAGCBOR_LINKfor a malformed link.Cryptofunction 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 wholedataobject). Addsserde_jsontoguion-crypto.std:cryptoadds 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]andcrypto_tlock_round(armored) -> Result[Int, StdError]. The output is armored age, byte-compatible with drand's Gotle(tlock v1.2.0) on the quicknet network, checked in both directions. A wrong round signature or a changed file isE_TLOCK_DECRYPT, a malformed fileE_TLOCK_FORMAT, bad keys or signaturesE_CRYPTO_INPUT.Cryptofunction codes 6 to 8, gated on format 81. Pure (the wrapper draws 48 bytes withcrypto_random_bytes), so it runs in the browser playground. Addshkdfandchacha20poly1305with no random-number source. The construction is incrates/crypto/src/tlock.md.std:cryptoaddscrypto_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.Cryptofunction code 5, gated on format 80. Malformed or out-of-subgroup points areE_CRYPTO_INPUT; a signature that does not verify isOk(false). Pure, so it runs in the browser playground. Adds the arkworks cratesark-bls12-381,ark-ec,ark-ffandark-serialize(0.5.0), pinned exactly, with no random-number dependency.std:cryptoverifies 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) andcrypto_pem_decode(written in Guion overbase64_decode).Cryptofunction codes 2 to 4, gated on format 79 per code. A malformed key, length, scheme or certificate is a typedStdError(E_CRYPTO_INPUT,E_CRYPTO_SCHEME,E_X509); a signature that does not verify isOk(false). Verification only, and pure, so it runs in the browser playground. Adds the RustCrypto cratesrsa,p256andx509-cert, pinned exactly, with no random-number or C dependency.- New pure crate
guion-cryptoand theCryptoinstruction (tag 223, artifact format 78, from 77; older artifacts still load).std:cryptogainscrypto_sha512(data: Bytes) -> Bytesandcrypto_sha3_512(data: Bytes) -> Bytes, 64-byte digests that need no grant. The crate does no I/O and draws no randomness, builds forwasm32-unknown-unknown, and so runs in the browser playground too. It adds the RustCrypto cratessha2(already used) andsha3, pinned exactly.