nervosnetwork / capsule

Capsule is an out-of-box development framework for creating smart contract on Nervos' CKB.
MIT License
60 stars 34 forks source link

A difference between capsule-env and real ckb-vm #11

Closed cosinlink closed 4 years ago

cosinlink commented 4 years ago

Describe the bug in capsule, I can use the code 'load_cell_data_hash(0, Source::Input)?' to get the hash of CellData from tx.inputs[0], however, I failed to get the hash of CellData from tx.inputs[0] by using the same code in ckb-vm. Ckb-vm is not allowed user to get the CellDataHash from tx.inputs.

Additional context I use the typescript contract by c to check if I can get the CellDataHash in ckb chain:

int main() {
  ckb_debug( "begin" );
  uint8_t buffer[1000];
  uint64_t len_data = 1;
  int ret_data = ckb_load_cell_data(buffer, &len_data, 0, 0, CKB_SOURCE_INPUT);
  if (ret_data != CKB_SUCCESS) {
    return ret_data;
  }
  ckb_debug( "ckb_load_cell_data success" );
  // get data hash
  uint64_t len = BLAKE2B_BLOCK_SIZE;
  unsigned char data_hash[BLAKE2B_BLOCK_SIZE];
  int ret = ckb_load_cell_by_field( data_hash,  &len, 0, 0, CKB_SOURCE_INPUT, CKB_CELL_FIELD_DATA_HASH);
  if (ret != CKB_SUCCESS) {
    return ret;
  }
  ckb_debug( "SUCCESS CKB_SOURCE_INPUT Datahash!" );
  return 0;
}

It failed.

jjyr commented 4 years ago
cosinlink commented 4 years ago
xxuejie commented 4 years ago

In capsule, the contract code load_cell_datahash(index, Source::Input) should return Err() under any circumstances;

I don't really understand this, why load_cell_data_hash should return an error?