Transaction

8C752800A12091…E5EDDA4BE567

Block 271,987 · index 1 · indexed

Summary

Hash
8C752800A120919BD8B11F3CE019D63FF3B22D7D35561081A993E5EDDA4BE567
Block
271,987
Size
4384 bytes
Gas used
9,049,782 / 22,418,200
Fee
67254ugnot
Status
success

Messages

#1AddPackagegno.land/p/moul/agents/commit/v011 arguments
Attached funds
5000000ugnot

Arguments · 11

  1. #1commit
  2. #2README.md
  3. #3# p/moul/agents/commit/v0 — shared commitment helpers A tiny pure package: the one place the agent demos agree on *how* a commitment is computed. On-chain realms should store commitments (hashes) to off-chain material — reports, patches, verdicts — not the material itself. When several realms do that, they need to compute hashes the same way, or they can't verify each other's commitments. ```go commit.Hash(parts...) // hex SHA-256, length-prefixed (no boundary collisions) commit.Verdict(vote, salt) // canonical commit-reveal commitment for a hidden bool commit.Short(hexHash) // abbreviate for display ``` `Hash` length-prefixes each part, so `Hash("ab","c") != Hash("a","bc")` — a small detail that matters the moment a commitment concatenates attacker-influenced fields. `Verdict` is the scheme the [jury](../../../r/moul/agents/jury/v0/) demo uses for blind voting: commit `Verdict(vote, salt)` during the commit phase, then reveal `(vote, salt)` — anyone can recompute and confirm the vote wasn't changed after the fact. Pure, deterministic, no realm state. Import it; don't reinvent the hashing. ```sh gno test . ``` <!-- BEGIN GNOCONTRACTS FOOTER (generated by `make readmes`; do not edit below) --> --- Part of **[moul/gno-contracts](https://github.com/moul/gno-contracts)** — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage. > ⚠️ **Disclaimer:** provided as-is, without warranty; not security-audited. Full disclaimer: [DISCLAIMER](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md). <!-- END GNOCONTRACTS FOOTER -->
  4. #4commit.gno
  5. #5// Package commit provides small, deterministic commitment helpers shared by // the agent demos. On-chain realms store *commitments* to off-chain data // (reports, patches, verdicts) rather than the data itself; this package is // the one place that defines how those commitments are computed, so several // realms agree on the scheme. package commit import ( "crypto/sha256" "encoding/hex" ) // Hash returns the hex-encoded SHA-256 over its parts, length-prefixed so // that Hash("ab","c") != Hash("a","bc"). Use it to commit to structured // off-chain material without revealing it. func Hash(parts ...string) string { var buf []byte for _, p := range parts { buf = appendUvarint(buf, uint64(len(p))) buf = append(buf, p...) } sum := sha256.Sum256(buf) return hex.EncodeToString(sum[:]) } // Verdict is the canonical commitment used by commit-reveal voting: a hidden // boolean plus a salt. Reveal the same (verdict, salt) later and any observer // can recompute this and confirm the vote was not changed after the fact. func Verdict(verdict bool, salt string) string { v := "no" if verdict { v = "yes" } return Hash("verdict", v, salt) } // Short abbreviates a hex commitment for display. func Short(h string) string { if len(h) <= 12 { return h } return h[:6] + "…" + h[len(h)-4:] } func appendUvarint(buf []byte, x uint64) []byte { for x >= 0x80 { buf = append(buf, byte(x)|0x80) x >>= 7 } return append(buf, byte(x)) }
  6. #6commit_test.gno
  7. #7package commit import ( "testing" "gno.land/p/nt/uassert/v0" ) func TestHashDeterministicAndPrefixed(t *testing.T) { uassert.Equal(t, Hash("a", "bc"), Hash("a", "bc")) // length-prefixing prevents boundary collisions uassert.NotEqual(t, Hash("ab", "c"), Hash("a", "bc")) uassert.Equal(t, 64, len(Hash("x"))) // sha256 hex is 64 chars } func TestVerdictCommitReveal(t *testing.T) { c := Verdict(true, "salt-123") // reproducible from the revealed values uassert.Equal(t, c, Verdict(true, "salt-123")) // flipping the vote or the salt changes the commitment uassert.NotEqual(t, c, Verdict(false, "salt-123")) uassert.NotEqual(t, c, Verdict(true, "salt-999")) } func TestShort(t *testing.T) { uassert.Equal(t, "abc", Short("abc")) uassert.True(t, len(Short(Hash("x"))) < 20) }
  8. #8gnomod.toml
  9. #9module = "gno.land/p/moul/agents/commit/v0" gno = "0.9"
  10. #10/gno.MemPackageType
  11. #11 MPUserAll

Result log

msg:0,success:true,log:,events:[]

← Back to block 271,987