Skip to content

Conversation

@brenzi
Copy link
Collaborator

@brenzi brenzi commented Oct 1, 2024

A little game for fun

  1. once per week, a new round starts at 0:00 GMT
  2. at the start of the round, the enclave draws a random lucky number from [0..10_000] (confidential)
  3. during the week, players can guess up to 10 times
  4. at the end of the round, winner(s) are rewarded

implementation notes:

  • inspired by Raffle Demo #1583 I introduced a generic randomness tool using SgxRnd exposed to pallets
  • Sidechain blocks now have on_initialize and on_finalize hooks we use here for OnTimestampSet
  • extended the cli to accept mnemonic or hex seed instead of account in keystore as well (C&P from Encointer)
  • find solution to make CI work without pre-funding Alice. or strictly divide production/test
  • test multiple rounds, temporarily setting round duration to 10min
  • charge fees for guessing

testing

# node
./target/release/integritee-node --dev --unsafe-rpc-external --rpc-cors all
# worker (in docker)
SGX_MODE=SW WORKER_MODE=sidechain WORKER_FEATURES=dcap make
./integritee-service -u ws://172.17.0.1 --ws-external -c run --skip-ra --dev &> worker.log

verify that a new round has started with the first produced sidechain block and a random number has been drawn

MRENCLAVE=$(./integritee-cli trusted get-shard)
VAULT=$(./integritee-cli trusted get-shard-vault)
./integritee-cli trusted --mrenclave $MRENCLAVE guess-the-number get-info
# GuessTheNumberInfo { account: 5d38b13719a9f34591ef9ced18ce03dbc45d0b9ffcba69ebcbae06464952ae41 (5EAw9k5U...), balance: 0, winnings: 0, next_round_timestamp: 1728432000000, last_winners: [], maybe_last_lucky_number: None, maybe_last_winning_distance: None }
# pot account: 5EAw9k5U5ERbUkNEmAmMWb1JigzYNrTKXfukfrWDy92gq62w

# shield 100 TEER for Alice
./integritee-cli -u ws://172.17.0.1 transfer //Alice $VAULT 111000000000000
./integritee-cli trusted --mrenclave $MRENCLAVE balance //Alice

# fill the pot with 33 TEER
./integritee-cli trusted --mrenclave $MRENCLAVE --direct transfer //Alice 5EAw9k5U5ERbUkNEmAmMWb1JigzYNrTKXfukfrWDy92gq62w 33000000000000
# verify with public getter:
./integritee-cli trusted --mrenclave $MRENCLAVE guess-the-number get-info
# balance should be 33000000000000

# set winning amount to 22 TEER as GameMaster (5FRMoVZyb7X32tvzdPxtbYhTjb4y7e7ynWdt8AArJsqr7xBn)
./integritee-cli trusted --mrenclave $MRENCLAVE --direct guess-the-number set-winnings "<mnemonic>" 22000000000000

# verify with public getter:
./integritee-cli trusted --mrenclave $MRENCLAVE guess-the-number get-info
# winnings should be 22000000000000

# now guess
./integritee-cli trusted --mrenclave $MRENCLAVE --direct guess-the-number guess //Alice 42

# try several times. 10x should work (status: `InSidechainBlock`). the eleventh time should fail (status: `Invalid`)

@brenzi brenzi added F8-enhancement New feature or request A0-core Affects a core part A3-sidechain C1-low 📌 Does not elevate a release containing this beyond "low priority" E0-breaksnothing labels Oct 2, 2024
@brenzi brenzi requested a review from clangenb October 2, 2024 12:47
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Looks good to me, only a few minor remarks!

@brenzi brenzi merged commit 9bab2c3 into master Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A0-core Affects a core part A3-sidechain B1-releasenotes C1-low 📌 Does not elevate a release containing this beyond "low priority" E0-breaksnothing F8-enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants