github.com/phillinzzz/newBsc@v1.1.6/cmd/evm/transition-test.sh (about)

     1  #!/bin/bash
     2  ticks="\`\`\`"
     3  
     4  function showjson(){
     5    echo "\`$1\`:"
     6    echo "${ticks}json"
     7    cat $1
     8    echo ""
     9    echo "$ticks"
    10  }
    11  function demo(){
    12    echo "$ticks"
    13    echo "$1"
    14    echo "$ticks"
    15    echo ""
    16  }
    17  function tick(){
    18    echo "$ticks"
    19  }
    20  
    21  cat << EOF
    22  ## EVM state transition tool
    23  
    24  The \`evm t8n\` tool is a stateless state transition utility. It is a utility
    25  which can
    26  
    27  1. Take a prestate, including
    28    - Accounts,
    29    - Block context information,
    30    - Previous blockshashes (*optional)
    31  2. Apply a set of transactions,
    32  3. Apply a mining-reward (*optional),
    33  4. And generate a post-state, including
    34    - State root, transaction root, receipt root,
    35    - Information about rejected transactions,
    36    - Optionally: a full or partial post-state dump
    37  
    38  ## Specification
    39  
    40  The idea is to specify the behaviour of this binary very _strict_, so that other
    41  node implementors can build replicas based on their own state-machines, and the
    42  state generators can swap between a \`geth\`-based implementation and a \`parityvm\`-based
    43  implementation.
    44  
    45  ### Command line params
    46  
    47  Command line params that has to be supported are
    48  $(tick)
    49  
    50  ` ./evm t8n -h | grep "trace\|output\|state\."`
    51  
    52  $(tick)
    53  
    54  ### Error codes and output
    55  
    56  All logging should happen against the \`stderr\`.
    57  There are a few (not many) errors that can occur, those are defined below.
    58  
    59  #### EVM-based errors (\`2\` to \`9\`)
    60  
    61  - Other EVM error. Exit code \`2\`
    62  - Failed configuration: when a non-supported or invalid fork was specified. Exit code \`3\`.
    63  - Block history is not supplied, but needed for a \`BLOCKHASH\` operation. If \`BLOCKHASH\`
    64    is invoked targeting a block which history has not been provided for, the program will
    65    exit with code \`4\`.
    66  
    67  #### IO errors (\`10\`-\`20\`)
    68  
    69  - Invalid input json: the supplied data could not be marshalled.
    70    The program will exit with code \`10\`
    71  - IO problems: failure to load or save files, the program will exit with code \`11\`
    72  
    73  EOF
    74  
    75  # This should exit with 3
    76  ./evm t8n --input.alloc=./testdata/1/alloc.json --input.txs=./testdata/1/txs.json --input.env=./testdata/1/env.json --state.fork=Frontier+1346 2>/dev/null
    77  if [ $? !=  3 ]; then
    78  	echo "Failed, exitcode should be 3"
    79  fi
    80  cat << EOF
    81  ## Examples
    82  ### Basic usage
    83  
    84  Invoking it with the provided example files
    85  EOF
    86  cmd="./evm t8n --input.alloc=./testdata/1/alloc.json --input.txs=./testdata/1/txs.json --input.env=./testdata/1/env.json"
    87  tick;echo "$cmd"; tick
    88  $cmd 2>/dev/null
    89  echo "Two resulting files:"
    90  echo ""
    91  showjson alloc.json
    92  showjson result.json
    93  echo ""
    94  
    95  echo "We can make them spit out the data to e.g. \`stdout\` like this:"
    96  cmd="./evm t8n --input.alloc=./testdata/1/alloc.json --input.txs=./testdata/1/txs.json --input.env=./testdata/1/env.json --output.result=stdout --output.alloc=stdout"
    97  tick;echo "$cmd"; tick
    98  output=`$cmd 2>/dev/null`
    99  echo "Output:"
   100  echo "${ticks}json"
   101  echo "$output"
   102  echo "$ticks"
   103  
   104  cat << EOF
   105  
   106  ## About Ommers
   107  
   108  Mining rewards and ommer rewards might need to be added. This is how those are applied:
   109  
   110  - \`block_reward\` is the block mining reward for the miner (\`0xaa\`), of a block at height \`N\`.
   111  - For each ommer (mined by \`0xbb\`), with blocknumber \`N-delta\`
   112     - (where \`delta\` is the difference between the current block and the ommer)
   113     - The account \`0xbb\` (ommer miner) is awarded \`(8-delta)/ 8 * block_reward\`
   114     - The account \`0xaa\` (block miner) is awarded \`block_reward / 32\`
   115  
   116  To make \`state_t8n\` apply these, the following inputs are required:
   117  
   118  - \`state.reward\`
   119    - For ethash, it is \`5000000000000000000\` \`wei\`,
   120    - If this is not defined, mining rewards are not applied,
   121    - A value of \`0\` is valid, and causes accounts to be 'touched'.
   122  - For each ommer, the tool needs to be given an \`address\` and a \`delta\`. This
   123    is done via the \`env\`.
   124  
   125  Note: the tool does not verify that e.g. the normal uncle rules apply,
   126  and allows e.g two uncles at the same height, or the uncle-distance. This means that
   127  the tool allows for negative uncle reward (distance > 8)
   128  
   129  Example:
   130  EOF
   131  
   132  showjson ./testdata/5/env.json
   133  
   134  echo "When applying this, using a reward of \`0x08\`"
   135  cmd="./evm t8n --input.alloc=./testdata/5/alloc.json -input.txs=./testdata/5/txs.json --input.env=./testdata/5/env.json  --output.alloc=stdout --state.reward=0x80"
   136  output=`$cmd 2>/dev/null`
   137  echo "Output:"
   138  echo "${ticks}json"
   139  echo "$output"
   140  echo "$ticks"
   141  
   142  echo "### Future EIPS"
   143  echo ""
   144  echo "It is also possible to experiment with future eips that are not yet defined in a hard fork."
   145  echo "Example, putting EIP-1344 into Frontier: "
   146  cmd="./evm t8n --state.fork=Frontier+1344 --input.pre=./testdata/1/pre.json --input.txs=./testdata/1/txs.json --input.env=/testdata/1/env.json"
   147  tick;echo "$cmd"; tick
   148  echo ""
   149  
   150  echo "### Block history"
   151  echo ""
   152  echo "The \`BLOCKHASH\` opcode requires blockhashes to be provided by the caller, inside the \`env\`."
   153  echo "If a required blockhash is not provided, the exit code should be \`4\`:"
   154  echo "Example where blockhashes are provided: "
   155  cmd="./evm t8n --input.alloc=./testdata/3/alloc.json --input.txs=./testdata/3/txs.json --input.env=./testdata/3/env.json  --trace"
   156  tick && echo $cmd && tick
   157  $cmd 2>&1 >/dev/null
   158  cmd="cat trace-0-0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81.jsonl | grep BLOCKHASH -C2"
   159  tick && echo $cmd && tick
   160  echo "$ticks"
   161  cat trace-0-0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81.jsonl | grep BLOCKHASH -C2
   162  echo "$ticks"
   163  echo ""
   164  
   165  echo "In this example, the caller has not provided the required blockhash:"
   166  cmd="./evm t8n --input.alloc=./testdata/4/alloc.json --input.txs=./testdata/4/txs.json --input.env=./testdata/4/env.json  --trace"
   167  tick && echo $cmd && tick
   168  tick
   169  $cmd
   170  errc=$?
   171  tick
   172  echo "Error code: $errc"
   173  
   174  
   175  echo "### Chaining"
   176  echo ""
   177  echo "Another thing that can be done, is to chain invocations:"
   178  cmd1="./evm t8n --input.alloc=./testdata/1/alloc.json --input.txs=./testdata/1/txs.json --input.env=./testdata/1/env.json --output.alloc=stdout"
   179  cmd2="./evm t8n --input.alloc=stdin --input.env=./testdata/1/env.json --input.txs=./testdata/1/txs.json"
   180  echo "$ticks"
   181  echo "$cmd1 | $cmd2"
   182  output=$($cmd1 | $cmd2 )
   183  echo $output
   184  echo "$ticks"
   185  echo "What happened here, is that we first applied two identical transactions, so the second one was rejected. "
   186  echo "Then, taking the poststate alloc as the input for the next state, we tried again to include"
   187  echo "the same two transactions: this time, both failed due to too low nonce."
   188  echo ""
   189  echo "In order to meaningfully chain invocations, one would need to provide meaningful new \`env\`, otherwise the"
   190  echo "actual blocknumber (exposed to the EVM) would not increase."
   191  echo ""