nervosnetwork / mruby-contracts

mruby based contract creator, allows writing contracts using Ruby
MIT License
8 stars 7 forks source link

aborts when ARGV contains non-utf8 characters #11

Open keroro520 opened 5 years ago

keroro520 commented 5 years ago

c/{entry.c,argv_entry.c,argv_source_entry.c} ignores non-utf8 characters in ARGV.

for (int i = 2; i < argc; i++) {
    char* utf8 = mrb_utf8_from_locale(argv[i], -1);
    if (utf8) {
      mrb_ary_push(mrb, margv, mrb_str_new_cstr(mrb, utf8));
      mrb_utf8_free(utf8);
    }
  }

What I concern about is, is it possible that cause inconsistency? That is undesired on blockchain. For example, Alice write a lock-script like

left = "我是个非UTF8的字符串"
hash = "12345678901234567890"

right =  $UNLOCK_ARGUMENT[1]
return hash(left, right) == hash

Alice has to provide an unlock argument $UNLOCK_ARGUMENT, which meets the hash condition, to unlock the lock-script above. But since left is an non-utf8 string, the hash results of Alice computes offline and CKB-VM are difference. Then Alice has no way to unlock that script.

So, I think aborting for non-utf8 may be better here.

keroro520 commented 5 years ago

mirb aborts if ruby code contains non-utf8: https://github.com/mruby/mruby/blob/master/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c#L577-L578