Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pseudo-random generator statistical tests #4

Merged
merged 56 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
74898bf
add initial go tests
sisyphusSmiling Oct 26, 2023
4f0cb30
add ci workflow
sisyphusSmiling Oct 26, 2023
96d6e4c
update flow config with RandomBeaconHistory aliases
sisyphusSmiling Oct 26, 2023
0dc510a
update go test package
sisyphusSmiling Oct 26, 2023
e65b0aa
add go script & txn templates
sisyphusSmiling Oct 26, 2023
b8d5739
update contracts/go.mod formatting
sisyphusSmiling Oct 26, 2023
29c63a0
add prg distribution test
sisyphusSmiling Oct 27, 2023
e156b1b
pin flow-cli version to v1.4.5 in ci workflow
sisyphusSmiling Oct 28, 2023
6adf6f5
fix implementation detail in prg_tests & update comments
sisyphusSmiling Oct 28, 2023
654b4b7
update flow.json with contract aliases
sisyphusSmiling Oct 30, 2023
db70090
move PRG test to root & update to use overflow
sisyphusSmiling Oct 30, 2023
17a1416
Apply suggestions from code review
sisyphusSmiling Nov 6, 2023
30bbdc4
update bigEndianBytesToWord64() pre-condition & message
sisyphusSmiling Nov 6, 2023
19c1190
update instances of PRG.bytesToWord64() to .bigEndianBytesToWord64()
sisyphusSmiling Nov 6, 2023
f1d006f
remove PRG.sourceOfRandomness field - state storage not necessary
sisyphusSmiling Nov 6, 2023
3645694
update PRG.nextUInt64() final xor shift
sisyphusSmiling Nov 6, 2023
90ca8fe
rename PseudoRandomGenerator to XorShift128Plus & rename instances
sisyphusSmiling Nov 6, 2023
8e7f756
update prg.next_uint64() calling transactions distinguishing single v…
sisyphusSmiling Nov 6, 2023
d1dd0fc
rename PseudoRandomGenerator.cdc to XorShift128Plus.cdc
sisyphusSmiling Nov 6, 2023
7e44dda
remove RandomBeaconHistory transactions
sisyphusSmiling Nov 7, 2023
9e5e9c4
rename XorShift128Plus to Xorshift128plus & update instances
sisyphusSmiling Nov 7, 2023
ce51fcd
refactor Xorshift128plus.PRG from resource to struct & update its ins…
sisyphusSmiling Nov 7, 2023
d980bae
add getter script for array of random UInt64 from prg
sisyphusSmiling Nov 7, 2023
8a392d0
simplify next_uint64 script & add comment
sisyphusSmiling Nov 7, 2023
e05641a
clarify script comments
sisyphusSmiling Nov 7, 2023
850cca7
fix iterative_next_uint64 txn and clarify comments
sisyphusSmiling Nov 7, 2023
d9eecda
fix PRG instantiation in CoinToss to match new interface
sisyphusSmiling Nov 7, 2023
6e963b3
fix iterative_next_uint64 PRG instantiation
sisyphusSmiling Nov 7, 2023
5f5ea13
add clarifying comments to Xorshift128plus contract
sisyphusSmiling Nov 7, 2023
c439f1c
fix PRG instantiation in script to match new interface
sisyphusSmiling Nov 7, 2023
1f72ce7
update CONTRIBUTING to name random-coin-toss repo
sisyphusSmiling Nov 7, 2023
cbf5d3e
Apply suggestions from code review
sisyphusSmiling Nov 7, 2023
e9157d5
update Xorshift128plus contract with PR feedback
sisyphusSmiling Nov 7, 2023
61cc807
Rename XorShift128Plus.cdc to Xorshift128plus.cdc
sisyphusSmiling Nov 7, 2023
ccf6d0e
update Xorshift128plus comments & error messages
sisyphusSmiling Nov 7, 2023
2f578d6
add comments to CoinToss contract
sisyphusSmiling Nov 8, 2023
256c1b2
Update CoinToss.cdc
sisyphusSmiling Nov 8, 2023
bf00c4e
update README info dialog about WIP status
sisyphusSmiling Nov 8, 2023
c4d2b21
Merge pull request #6 from onflow/update-prg-impl
sisyphusSmiling Nov 8, 2023
5f32620
Merge branch 'update-prg-impl' into prg-tests
sisyphusSmiling Nov 8, 2023
bfcc703
remove references to PseudoRandomGenerator in favor of renamed Xorshi…
sisyphusSmiling Nov 8, 2023
500777a
update ci workflow to run prg tests on PR only
sisyphusSmiling Nov 8, 2023
36a077d
bump flow-go/crypto to v0.24.10
sisyphusSmiling Nov 8, 2023
b7e34c8
fix bug in PRG state initialization
sisyphusSmiling Nov 8, 2023
d23fbc6
add prg test cases
sisyphusSmiling Nov 8, 2023
4dff925
update next_uint64 script signature & instance in tests
sisyphusSmiling Nov 8, 2023
62ef960
remove WIP notice from README
sisyphusSmiling Nov 8, 2023
cb10350
add RandomResultStorage helper contract & scripts to persist PRG stat…
sisyphusSmiling Nov 8, 2023
9ce0fed
add RandomBeaconHistory aliases in flow.json
sisyphusSmiling Nov 8, 2023
dbad339
fix bug in prg_test_helpers ProcessBatches method
sisyphusSmiling Nov 8, 2023
0a03bb4
add comments to RandomResultStorage scripts & txns
sisyphusSmiling Nov 8, 2023
3e70948
add clarifying comments to CoinToss contract & scripts
sisyphusSmiling Nov 8, 2023
cb62aac
fix distribution test sampleSize calculation
sisyphusSmiling Nov 8, 2023
3db48f2
update ci workflow to only run on PR with changes to Xorshift128plus
sisyphusSmiling Nov 8, 2023
2d32ea7
add @onflow/flow-smart-contracts as CODEOWNERS
sisyphusSmiling Nov 8, 2023
10596ce
Update prg_test_helpers.go
sisyphusSmiling Nov 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.19'
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.4.5
- name: Flow CLI Version
run: flow version
- name: Update PATH
run: echo "/root/.local/bin" >> $GITHUB_PATH
- name: Run tests
run: make ci

6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: test
test:
go test -v ./...

.PHONY: ci
ci: test
40 changes: 33 additions & 7 deletions flow.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,62 @@
{
"contracts": {
"CoinToss": "./contracts/CoinToss.cdc",
"CoinToss": {
"source": "./contracts/CoinToss.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7"
}
},
"FlowToken": {
"source": "./contracts/utility/FlowToken.cdc",
"aliases": {
"emulator": "0ae53cb6e3f42a79"
"emulator": "0ae53cb6e3f42a79",
"mainnet": "1654653399040a61",
"testnet": "7e60df042a9c0868"
}
},
"FungibleToken": {
"source": "./contracts/utility/FungibleToken.cdc",
"aliases": {
"emulator": "ee82856bf20e2aa6"
"emulator": "ee82856bf20e2aa6",
"mainnet": "f233dcee88fe0abe",
"testnet": "9a0766d93b6608b7"
}
},
"MetadataViews": {
"source": "./contracts/utility/MetadataViews.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7"
"emulator": "f8d6e0586b0a20c7",
"mainnet": "1d7e57aa55817448",
"testnet": "631e88ae7f1d7c20"
}
},
"NonFungibleToken": {
"source": "./contracts/utility/NonFungibleToken.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"mainnet": "1d7e57aa55817448",
"testnet": "631e88ae7f1d7c20"
}
},
"PseudoRandomGenerator": {
"source": "./contracts/PseudoRandomGenerator.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7"
}
},
"PseudoRandomGenerator": "./contracts/PseudoRandomGenerator.cdc",
"RandomBeaconHistory": "./contracts/RandomBeaconHistory.cdc",
"RandomBeaconHistory": {
"source": "./contracts/RandomBeaconHistory.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7",
"testnet": "8c5303eaa26202d6"
}
},
"ViewResolver": {
"source": "./contracts/utility/ViewResolver.cdc",
"aliases": {
"emulator": "f8d6e0586b0a20c7"
"emulator": "f8d6e0586b0a20c7",
"mainnet": "1d7e57aa55817448",
"testnet": "631e88ae7f1d7c20"
}
}
},
Expand Down
197 changes: 197 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
module github.com/onflow/random-coin-toss

go 1.19

require (
github.com/bjartek/overflow v1.14.1
github.com/onflow/cadence v0.42.2
github.com/onflow/flow-go/crypto v0.24.9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a recent PR to improve the statistical tests (onflow/flow-go#4844). It can help reduce flakiness in the test. Maybe I can merge that PR and tag a new version to be used here first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll bump the version once it's ready to go.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just merged the PR and tagged a new version v0.24.10 that you can use

github.com/stretchr/testify v1.8.4
)

require (
cloud.google.com/go/compute v1.21.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/kms v1.12.1 // indirect
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.5.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ef-ds/deque v1.0.4 // indirect
github.com/enescakir/emoji v1.0.0 // indirect
github.com/ethereum/go-ethereum v1.10.22 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c // indirect
github.com/fxamacker/circlehash v0.3.0 // indirect
github.com/glebarez/go-sqlite v1.21.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gosuri/uilive v0.0.4 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hexops/autogold v1.3.1 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/hexops/valast v1.4.3 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.7.0 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-block-format v0.1.2 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-ipfs-blockstore v1.3.0 // indirect
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
github.com/ipfs/go-ipfs-util v0.0.2 // indirect
github.com/ipfs/go-ipld-format v0.5.0 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/k0kubun/pp/v3 v3.2.0 // indirect
github.com/kevinburke/go-bindata v3.23.0+incompatible // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.28.1 // indirect
github.com/lmars/go-slip10 v0.0.0-20190606092855-400ba44fee12 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.9.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/nightlyone/lockfile v1.0.0 // indirect
github.com/onflow/atree v0.6.0 // indirect
github.com/onflow/flow-cli/flowkit v1.4.5 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20230703193002-53362441b57d // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.3 // indirect
github.com/onflow/flow-emulator v0.56.0 // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230711213910-baad011d2b13 // indirect
github.com/onflow/flow-go v0.32.2-0.20231017202518-0b275f42906c // indirect
github.com/onflow/flow-go-sdk v0.41.12 // indirect
github.com/onflow/flow-nft/lib/go/contracts v1.1.0 // indirect
github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231017162044-5d0f9b6dfdb2 // indirect
github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20221222181731-14b90207cead // indirect
github.com/onflow/sdks v0.5.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/psiemens/graceland v1.0.0 // indirect
github.com/psiemens/sconfig v0.1.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/sanity-io/litter v1.5.5 // indirect
github.com/sethvargo/go-retry v0.2.3 // indirect
github.com/slok/go-http-metrics v0.10.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/texttheater/golang-levenshtein/levenshtein v0.0.0-20200805054039-cae8b0eaed6c // indirect
github.com/turbolent/prettier v0.0.0-20220320183459-661cc755135d // indirect
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.11 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.9.1 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
modernc.org/libc v1.22.3 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.21.1 // indirect
mvdan.cc/gofumpt v0.4.0 // indirect
)
Loading
Loading