Skip to content

Commit

Permalink
Showing 5 changed files with 1,106 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cfg/cspell-dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ADBEEF
adbeef
aland
allowlister
aptn
aptos
aptoslabs
auid
autoscale
barthelemy
bento
@@ -66,6 +67,7 @@ marino
mayen
melilla
merperson
metadatas
moai
mosquitto
mqtt
18 changes: 18 additions & 0 deletions src/move/emojicoin_arena/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[addresses]
arena = "_"
integrator = "_"

[dependencies.EmojicoinDotFun]
local = "../emojicoin_dot_fun"

[dev-addresses]
arena = "0xaaa"
coin_factory = "0xbbb"
emojicoin_dot_fun = "0xc0de"
integrator = "0xddd"

[package]
authors = ["Econia Labs (developers@econialabs.com)"]
name = "EmojicoinArena"
upgrade_policy = "compatible"
version = "1.0.0"
11 changes: 11 additions & 0 deletions src/move/emojicoin_arena/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Emojicoin Arena

## A note on pseudo-randomness

Since randomness is not supported in `init_module` per [`aptos-core` #15436],
pseudo-random substitute implementations are used for the first crank. For a
detailed rationale that explains how this is effectively random in practice, see
[this `emojicoin-dot-fun` pull request comment].

[this `emojicoin-dot-fun` pull request comment]: https://github.com/econia-labs/emojicoin-dot-fun/pull/408#discussion_r1887856202
[`aptos-core` #15436]: https://github.com/aptos-labs/aptos-core/issues/15436
1,038 changes: 1,038 additions & 0 deletions src/move/emojicoin_arena/sources/emojicoin_arena.move

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions src/move/emojicoin_arena/sources/pseudo_randomness.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module arena::pseudo_randomness {

use aptos_framework::transaction_context;
use std::bcs;
use std::vector;

friend arena::emojicoin_arena;

/// Pseudo-random substitute for `aptos_framework::randomness::u64_range`, since
/// the randomness API is not available during `init_module`.
public(friend) inline fun u64_range(min_incl: u64, max_excl: u64): u64 {
let range = ((max_excl - min_incl) as u256);
let sample = ((u256_integer() % range) as u64);

min_incl + sample
}

/// Pseudo-random substitute for `aptos_framework::randomness::next_32_bytes`, since
/// the randomness API is not available during `init_module`.
inline fun next_32_bytes(): vector<u8> {
bcs::to_bytes(&transaction_context::generate_auid_address())
}

/// Pseudo-random substitute for `aptos_framework::randomness::u256_integer`, since
/// the randomness API is not available during `init_module`.
inline fun u256_integer(): u256 {
let raw = next_32_bytes();
let i = 0;
let ret: u256 = 0;
while (i < 32) {
ret = ret * 256 + (vector::pop_back(&mut raw) as u256);
i = i + 1;
};
ret
}
}

0 comments on commit a79759e

Please sign in to comment.