Skip to content

Commit

Permalink
remove builtin random function (#1041)
Browse files Browse the repository at this point in the history
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
  • Loading branch information
xermicus authored Oct 19, 2022
1 parent ab82d7c commit cb3b8b0
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 100 deletions.
15 changes: 0 additions & 15 deletions docs/language/builtins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ Returns the blockhash for a particular block. This not possible for the current
block, or any block except for the most recent 256. Do not use this a source of
randomness unless you know what you are doing.

.. note::
This function is not available on Parity Substrate. When using Parity Substrate,
use ``random()`` as a source of random data.

.. note::
This function is not available on Solana. There is the
`recent block hashes account <https://edge.docs.solana.com/developing/runtime-facilities/sysvars#recentblockhashes>`_
Expand All @@ -44,17 +40,6 @@ randomness unless you know what you are doing.
- It does not give any slot of block number, so it is not possible to provide a matching
function signature.

random(bytes subject) returns (bytes32)
+++++++++++++++++++++++++++++++++++++++

Returns random bytes based on the subject. The same subject for the same transaction
will return the same random bytes, so the result is deterministic. The chain has
a ``max_subject_len``, and if *subject* exceeds that, the transaction will be aborted.

.. note::

This function is only available on Parity Substrate.

``msg`` properties
++++++++++++++++++

Expand Down
13 changes: 0 additions & 13 deletions integration/substrate/randomizer.sol

This file was deleted.

45 changes: 0 additions & 45 deletions integration/substrate/randomizer.spec.ts

This file was deleted.

13 changes: 1 addition & 12 deletions src/sema/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Prototype {
}

// A list of all Solidity builtins functions
static BUILTIN_FUNCTIONS: Lazy<[Prototype; 28]> = Lazy::new(|| {
static BUILTIN_FUNCTIONS: Lazy<[Prototype; 27]> = Lazy::new(|| {
[
Prototype {
builtin: Builtin::Assert,
Expand Down Expand Up @@ -187,17 +187,6 @@ static BUILTIN_FUNCTIONS: Lazy<[Prototype; 28]> = Lazy::new(|| {
doc: "Returns the block hash for given block number",
constant: false,
},
Prototype {
builtin: Builtin::Random,
namespace: None,
method: None,
name: "random",
params: vec![Type::DynamicBytes],
ret: vec![Type::Bytes(32)],
target: vec![Target::default_substrate()],
doc: "Returns deterministic random bytes",
constant: false,
},
Prototype {
builtin: Builtin::AbiDecode,
namespace: Some("abi"),
Expand Down
15 changes: 0 additions & 15 deletions tests/substrate_tests/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,6 @@ fn functions() {
);

runtime.function("test", Vec::new());

let mut runtime = build_solidity(
r##"
contract c {
function test() public {
bytes32 o = random(
"abcd"
);
assert(o == hex"429ccf3ebce07f0c6d7cd0d1dead74459f753cdf53ed8359e42728042a91c39c");
}
}"##,
);

runtime.function("test", Vec::new());
}

#[test]
Expand Down

0 comments on commit cb3b8b0

Please sign in to comment.