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

ckb-run-scripts #1943

Closed
doitian opened this issue Feb 18, 2020 · 1 comment
Closed

ckb-run-scripts #1943

doitian opened this issue Feb 18, 2020 · 1 comment

Comments

@doitian
Copy link
Member

@doitian doitian commented Feb 18, 2020

A utility to run CKB VM scripts

Usage

ckb-run-scripts chain-manifest.yaml

The process MUST exit with code 0 if all scripts succeed, otherwise exit with the status code which the last failed script returns.

The process MUST print enough context so the user knows when a script is running, which transaction it belongs to, and which inputs and outputs belong to the current script group.

The file chain-manifest.yaml describes a chain and marked the scripts to run. I use YAML as an example, the script SHOULD use a format which is easy to read and edit.

Following is an example of the manifest file.

# Consesus configures parameters to generate the chain.
#
# ckb-run-scripts MUST use persistent difficulty and dummy PoW engine.
#
# The consensus configuration SHOULD be optional, when omitted, the following default values are used.
#
# ckb-run-scripts COULD skip the consensus verification entirely but only run the scripts in transactions.
consensus:
  # Used to generate the Epoch in block header.
  epoch_length: 100
  # ckb-run-scripts MUST use process start time as genesis timestamp by default.
  genesis_timestamp: 1000

transactions:
  - skip: false # Skip running the scripts in this transactions. Optional (default: false)

    # By default, all transactions are included in the genesis block, which timestamp is the process start time. A transaction can specify the block parameter to expliclity start a new block. Optional.
    start_new_block:
      # It must be larger than the previous block
      number: 1
      # Optional, default: previous block timestamp + 1000 * (current block number - previous block number)
      timestamp: 2000

      cell_deps:
        - out_point:
            ref: 'ducktape'
            # Whenever there's out_point require, it is possible to specify a ref instead.
            # See Out Point Ref.
            # Or specify the outpoint explicitly.
            # tx_hash: '0x...'
            # index: 0

          dep_type: 'code'

      # There are two ways to specify a header deps: via hash or via number.
      # If via number, it must be a previous block, and that block's header hash will be used here automatically.
      header_deps:
        - header_hash = '0x...'
        # - header_number = 0

      inputs:
        - previous_output:
            ref: 'genesis_output'
            # Or alternatively
            # tx_hash: '0x...'
            # index: 0
          # Optional, default to 0
          since: 0

          # Skip the type script group containing this input. Optional, default to false
          # skip_type_script_group: false
          # Skip the lock script group containing this input. Optional, default to false
          # skip_lock_script_group: false

      witnesses:
        # There are two ways to specify the witness, and only one way should be used for a single witness.
        # 1.a Raw bytes of the whole witness
        - raw: '0x...'
        # 1.b Read the whole witness from a file
        # - file: 'witness.bin'
        # 2. Split into lock, input_type, output_type, which will be serialized as WitnessArgs via Molecule
        - lock: { raw: '0x...' }
          input_type: { raw: '0x...' }
          output_type: { raw: '0x...' }

      outputs:
        # Gives the output an ID thus it can be used as a ref later. Optional.
        id: 'new_cell'
        # The capacity of last output in a transaction is optional, which is computed automatically.
        capacity: 100

        # Skip the type script group containing this output. Optional, default to false.
        # skip_type_script_group: false

        lock:
          # Use a cell to deduce the lock automatically,
          # - If hash_type is data, code_hash is set to the cell data hash.
          # - If hash_type is type, code_hash is set to the hash of the cell type script.
          code_hash:
            ref: 'ducktape'
          # Or
          # code_hash: { hash: 'ox...' }
          hash_type: 'data'

          # There are two ways to specify a binary:
          # - raw: Inline hex
          # - file: Read the bytes from a file
          args:
            - file: 'lock.js'
            - raw: '0x...'

        outputs_data:
          raw: '0x...'

The utility MUST allow reference a previous cell in cell_deps.out_point, inputs.previous_output and script code_hash.

The utility MUST support reading binary from file instead of giving them directly in the manifest file. The utility MUST support relative file path and absolute file path.

The utility MUST print the ckb_debug logs.

The utility MUST generate a bootstrap manifest, which contains examples to run a C contract and ducktape contract.

The utility MUST bundle extra cells beside the default system scripts in mainnet.

  • Duktape VM: which cell ref id is duktape
  • mruby VM: which cell ref id is mruby
  • Always success script: which cell ref id is always_success

For the system default scripts, following ref ids SHOULD be used:

  • secp256k1_code: Default secp256k1 lock code cell
  • secp256k1_data: The cell containing secp256k1 multiplication table
  • secp256k1_multisig_code: Default secp256k1 multisig code cell
  • secp256k1: The dep group which bundles secp256k1_code and secp256k1_data
  • secp256k1_multisig: The dep group which bundles secp256k1_multisig_code and secp256k1_data.

The utility MUST issue an output with enough capacity (8,400,000,000 CKBytes) for test. The issued output cell ref id MUST be genesis_output.

@doitian

This comment has been minimized.

Copy link
Member Author

@doitian doitian commented Feb 18, 2020

A minimal manifest to run a js file type.js as type script:

transactions:
  - cell_deps:
      - out_point:
          ref: 'ducktape'
        dep_type: 'code'

    inputs:
      - previous_output:
          ref: 'genesis_output'

    witnesses:
      - raw: '0x...'

    outputs:
      - type:
          code_hash:
            ref: 'ducktape'
          hash_type: 'data'
          args:
            - file: 'type.js'
@doitian doitian added this to 📬 Inbox in CKB - Issues Feb 19, 2020
@doitian doitian closed this Feb 24, 2020
CKB - Issues automation moved this from 📬 Inbox to ✅ Closed Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
CKB - Issues
  
✅ Closed
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.