Onchain Randomness logo

Onchain Randomness

Organization
MystenLabs
onchain-randomness

Onchain randomness on Sui. Use when generating random values in Move smart contracts, working with the Random object (0x8) or RandomGenerator, securing randomness-consuming functions against composition attacks, PTB attacks, or state leakage, implementing commit-reveal patterns, balancing gas across execution paths, or integrating randomness from TypeScript. For general Move security patterns, see the `move-security` skill. For Move language fundamentals, see the `sui-move` skill. For TypeScript SDK patterns, see the `sui-sdks` skill.

Overview

PublisherMystenLabs
Repositoryskills
Skill nameonchain-randomness
Stars
21
Forks
12
Bundled files
3
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by MystenLabs on GitHub. Read the source before you install it.

Installation

Install the Onchain Randomness AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/MystenLabs/skills/tree/main/onchain-randomness
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/MystenLabs/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/onchain-randomness .claude/skills/onchain-randomness
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Onchain Randomness in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Onchain Randomness on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Onchain Randomness is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Onchain Randomness

MCP tool: When available in your environment, also query the Sui documentation MCP server (https://sui.mcp.kapa.ai) for up-to-date answers. Use it for verification and for details not covered by these reference files.

Source constraint: All information in this skill is sourced exclusively from docs.sui.io/sui-stack/on-chain-primitives/randomness-onchain. When extending or updating this skill, only pull from this source. Do not use third-party blogs, tutorials, or unofficial documentation.

Sui provides native onchain randomness through the Random shared object at address 0x8. Move functions create RandomGenerator instances from Random and use them to produce unpredictable values. This skill covers the API, usage patterns, security considerations, and attack mitigations for onchain randomness.


Reference files

usage -- API and Usage Patterns

Path: usage.md Load when: generating random values in Move, creating a RandomGenerator, calling new_generator, using generate_u128, generate_u8_in_range, passing the Random object from TypeScript, or writing basic randomness-consuming functions. Covers: the Random object (address 0x8), RandomGenerator, the random.move API (full function list including new_generator, value generation, range generation, shuffle, generate_bytes), basic implementation examples, TypeScript integration.

security -- Security and Attack Vectors

Path: security.md Load when: securing randomness-consuming functions, preventing composition attacks, mitigating PTB attacks, avoiding RandomGenerator state leakage, implementing commit-reveal patterns, balancing gas across winning and losing paths, or choosing function visibility for randomness functions. Covers: composition attacks (abort-filtering via public functions), PTB attacks (command chaining after MoveCall consuming Random), RandomGenerator state leakage via bcs::to_bytes, compiler lints on public functions accepting Random or RandomGenerator, two-step commit-reveal pattern, balanced gas usage, entry function restrictions.


Routing guide

TaskLoad
Generating random values in Moveusage
Creating a RandomGeneratorusage
Calling random API functionsusage
Passing Random from TypeScriptusage
Securing a randomness-consuming functionsecurity
Preventing composition or abort-filtering attackssecurity
Mitigating PTB-based attackssecurity
Avoiding RandomGenerator state leakagesecurity
Implementing commit-reveal for randomnesssecurity
Balancing gas across execution pathssecurity
Choosing function visibility for randomnesssecurity
Writing a complete randomness featureusage + security
Reviewing randomness code for vulnerabilitiesusage + security

Rules

  • The Random object lives at reserved address 0x8 and is immutable for transactions. Any attempt to modify it causes transaction failure.
  • Always create RandomGenerator locally within the consuming function using r.new_generator(ctx). Never pass RandomGenerator as a public function parameter. Passing it to public(package) or private functions is acceptable for testing and in-package logic.
  • Define randomness-consuming functions as private entry functions. The Move compiler lints against public functions that accept Random or RandomGenerator as parameters.
  • Sui rejects PTBs containing commands other than TransferObjects or MergeCoins following a MoveCall that consumes Random. In other words, a call accepting Random must be the last MoveCall in a PTB.
  • Ensure winning and losing execution paths consume approximately equal total gas (both compute and storage) to prevent attackers from inferring outcomes from gas consumption. Measure gas carefully and test in each published environment before going live.
  • Use the two-step commit-reveal pattern when the outcome of randomness must not be observable before a follow-up action completes.

Common mistakes

  • Making randomness functions public instead of private entry. This is a fatal security flaw, not just a mistake. Public functions accepting Random enable abort-filtering attacks where an attacker wraps the function and reverts unfavorable outcomes. The compiler lints against this.
  • Accepting RandomGenerator as a public function parameter. Callers can predict outputs by serializing the generator's internal state with bcs::to_bytes(&generator). The compiler lints against public functions with RandomGenerator parameters. Using RandomGenerator as a parameter in public(package) or private functions is acceptable for testing and in-package logic.
  • Unbalanced gas consumption between branches. If winning and losing paths consume significantly different total gas (compute + storage), attackers can infer outcomes from gas usage. The success path should cost equal or more gas than the failure path. To achieve this, either perform a simple standard update (e.g., set a bool flag) and claim the result in a follow-up function, or create an equally sized object (e.g., a dynamic field) in the failure path. Gas values must be measured carefully and tested in each published environment before going live.
  • Skipping commit-reveal when outcomes influence subsequent user actions. If a user can observe and act on a random outcome in the same transaction, they can abort unfavorable results.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Onchain Randomness AI skill do?

Onchain randomness on Sui. Use when generating random values in Move smart contracts, working with the Random object (0x8) or RandomGenerator, securing randomness-consuming functions against composition attacks, PTB attacks, or state leakage, implementing commit-reveal patterns, balancing gas across execution paths, or integrating randomness from TypeScript. For general Move security patterns, see the `move-security` skill. For Move language fundamentals, see the `sui-move` skill. For TypeScript SDK patterns, see the `sui-sdks` skill.

Why use Onchain Randomness on TypingMind?

Because you install it once and use it with any model. Onchain Randomness is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Onchain Randomness in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/MystenLabs/skills/tree/main/onchain-randomness. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Onchain Randomness?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Onchain Randomness?

As many as you like. As long as a model supports skills, you can use Onchain Randomness with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Onchain Randomness AI skill free?

Yes. It is published on GitHub by MystenLabs under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇