Kaynağa Gözat

remove builtin random function (#1041)

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Cyrill Leutwiler 3 yıl önce
ebeveyn
işleme
cb3b8b083f

+ 0 - 15
docs/language/builtins.rst

@@ -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>`_
@@ -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
 ++++++++++++++++++
 

+ 0 - 13
integration/substrate/randomizer.sol

@@ -1,13 +0,0 @@
-contract randomizer {
-    bytes32 public value;
-
-    function get_random(bytes subject) public returns (bytes32) {
-        bytes32 r1 = random(subject);
-        // if we call random again in the same transaction, we should get the same result
-        bytes32 r2 = random(subject);
-
-        assert(r1 == r2);
-        value = r1;
-        return r1;
-    }
-}

+ 0 - 45
integration/substrate/randomizer.spec.ts

@@ -1,45 +0,0 @@
-import expect from 'expect';
-import { gasLimit, createConnection, deploy, transaction, aliceKeypair, daveKeypair } from './index';
-import { ContractPromise } from '@polkadot/api-contract';
-import { ApiPromise } from '@polkadot/api';
-
-describe('Deploy randomizer contract and test', () => {
-    let conn: ApiPromise;
-
-    before(async function () {
-        conn = await createConnection();
-    });
-
-    after(async function () {
-        await conn.disconnect();
-    });
-
-    it('randomizer', async function () {
-        this.timeout(50000);
-
-        const alice = aliceKeypair();
-        const dave = daveKeypair();
-
-        // call the constructors
-        let deploy_contract = await deploy(conn, alice, 'randomizer.contract', BigInt(0));
-
-        let contract = new ContractPromise(conn, deploy_contract.abi, deploy_contract.address);
-
-        let { output: queryOutput } = await contract.query.getRandom(alice.address, {}, '01234567');
-
-        let tx = contract.tx.getRandom({ gasLimit }, '01234567');
-
-        await transaction(tx, alice);
-
-        let { output: txOutput } = await contract.query.value(alice.address, {});
-
-        let queryRandom = queryOutput!.toU8a();
-        let txRandom = txOutput!.toU8a();
-
-        expect(queryRandom.length).toBe(32);
-        expect(txRandom.length).toBe(32);
-        expect(txRandom).not.toBe(queryRandom);
-        expect(queryRandom).not.toBe(Buffer.alloc(32));
-        expect(txRandom).not.toBe(Buffer.alloc(32));
-    });
-});

+ 1 - 12
src/sema/builtin.rs

@@ -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,
@@ -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"),

+ 0 - 15
tests/substrate_tests/builtins.rs

@@ -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]