diff --git a/contract/contract_module.c b/contract/contract_module.c index 7c6e12699..f095aa2ea 100644 --- a/contract/contract_module.c +++ b/contract/contract_module.c @@ -250,6 +250,7 @@ static int modulePcall(lua_State *L) int argc = lua_gettop(L) - 1; int *service = (int *)getLuaExecContext(L); struct LuaSetRecoveryPoint_return start_seq; + int ret; if (service == NULL) { luaL_error(L, "cannot find execution context"); @@ -261,7 +262,10 @@ static int modulePcall(lua_State *L) luaL_throwerror(L); } - if (lua_pcall(L, argc, LUA_MULTRET, 0) != 0) { + if ((ret = lua_pcall(L, argc, LUA_MULTRET, 0)) != 0) { + if (ret == LUA_ERRMEM) { + luaL_throwerror(L); + } lua_pushboolean(L, false); lua_insert(L, 1); if (start_seq.r0 > 0) { diff --git a/contract/lgmp.c b/contract/lgmp.c index 693c8895a..8998123c4 100644 --- a/contract/lgmp.c +++ b/contract/lgmp.c @@ -4,6 +4,7 @@ #include "lua.h" #include "lauxlib.h" #include "lgmp.h" +#include "math.h" #define lua_boxpointer(L,u) \ (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u)) @@ -83,6 +84,9 @@ static mp_num Bget(lua_State *L, int i) x = bn_alloc(BN_Integer); if (x == NULL) luaL_error(L, mp_num_memory_error); + if (isnan(d) || isinf(d)) { + luaL_error(L, "can't convert nan or infinity"); + } mpz_init_set_d(x->mpptr, d); Bnew(L, x); lua_replace(L, i); diff --git a/contract/state_module.c b/contract/state_module.c index bd896602f..dfa05116b 100644 --- a/contract/state_module.c +++ b/contract/state_module.c @@ -178,7 +178,11 @@ static void state_array_load_len(lua_State *L, state_array_t *arr) static void state_array_checkarg(lua_State *L, state_array_t *arr) { - int idx = luaL_checkint(L, -1); + int idx; + if (!luaL_isinteger(L, 2)) { + luaL_typerror(L, 2, "integer"); + } + idx = luaL_checkint(L, 2); luaL_argcheck(L, idx >= 1 && idx <= arr->len, 2, "index out of range"); } @@ -192,15 +196,14 @@ static void state_array_push_key(lua_State *L, const char *id) static int state_array_get(lua_State *L) { - const char *method; - const char *idx; state_array_t *arr; + int key_type = LUA_TNONE; arr = luaL_checkudata(L, 1, STATE_ARRAY_ID); state_array_load_len(L, arr); - method = lua_tostring(L, 2); - if (method != NULL) { /* methods */ + if (lua_type(L, 2) == LUA_TSTRING) { /* methods */ + const char *method = lua_tostring(L, 2); if (strcmp(method, "append") == 0) { lua_pushcfunction(L, state_array_append); return 1; @@ -211,6 +214,7 @@ static int state_array_get(lua_State *L) lua_pushcfunction(L, state_array_len); return 1; } + luaL_typerror(L, 2, "integer"); } state_array_checkarg(L, arr); /* a i */ lua_pushcfunction(L, getItemWithPrefix); /* a i f */ @@ -222,16 +226,12 @@ static int state_array_get(lua_State *L) static int state_array_set(lua_State *L) { - const char *idx; state_array_t *arr; arr = luaL_checkudata(L, 1, STATE_ARRAY_ID); state_array_load_len(L, arr); - lua_pushvalue(L, 1); /* a i v a */ - lua_pushvalue(L, 2); /* a i v a i */ - state_array_checkarg(L, arr); /* a i v a i */ - lua_pop(L, 2); /* a i v */ + state_array_checkarg(L, arr); /* a i v */ lua_pushcfunction(L, setItemWithPrefix); /* a i v f */ state_array_push_key(L, arr->id); /* a i v f id-i */ lua_pushvalue(L, 3); /* a i v f id-i v */ diff --git a/contract/system_module.c b/contract/system_module.c index 41c56c578..62ad6f07b 100644 --- a/contract/system_module.c +++ b/contract/system_module.c @@ -18,7 +18,7 @@ static int systemPrint(lua_State *L) if (jsonValue == NULL) { luaL_throwerror(L); } - LuaPrint(service, jsonValue); + LuaPrint(L, service, jsonValue); free(jsonValue); return 0; } @@ -89,6 +89,7 @@ int getItemWithPrefix(lua_State *L) if (ret.r0 == NULL) return 0; + minus_inst_count(L, strlen(ret.r0)); if (lua_util_json_to_lua(L, ret.r0, false) != 0) { strPushAndRelease(L, ret.r0); luaL_error(L, "getItem error : can't convert %s", lua_tostring(L, -1)); @@ -378,38 +379,33 @@ static int os_difftime(lua_State *L) static int lua_random(lua_State *L) { int *service = (int *)getLuaExecContext(L); - lua_Number n; - lua_Number min, max; - double d; + int min, max; if (service == NULL) { luaL_error(L, "cannot find execution context"); } switch (lua_gettop(L)) { - case 0: - d = LuaRandomNumber(L, *service); - lua_pushnumber(L, d); - break; case 1: - n = luaL_checkinteger(L, 1); - if (n < 1) { + max = luaL_checkint(L, 1); + if (max < 1) { luaL_error(L, "system.random: the maximum value must be greater than zero"); } - n = LuaRandomInt(L, n, 0, *service); - lua_pushinteger(L, n); + lua_pushinteger(L, LuaRandomInt(1, max, *service)); break; - default: - min = luaL_checkinteger(L, 1); - max = luaL_checkinteger(L, 2); + case 2: + min = luaL_checkint(L, 1); + max = luaL_checkint(L, 2); if (min < 1) { luaL_error(L, "system.random: the minimum value must be greater than zero"); } if (min > max) { luaL_error(L, "system.random: the maximum value must be greater than the minimum value"); } - n = LuaRandomInt(L, min, max, *service); - lua_pushinteger(L, n); + lua_pushinteger(L, LuaRandomInt(min, max, *service)); + break; + default: + luaL_error(L, "system.random: 1 or 2 arguments required"); break; } diff --git a/contract/util.c b/contract/util.c index faa3a1d32..e014fc2c5 100644 --- a/contract/util.c +++ b/contract/util.c @@ -166,16 +166,30 @@ static bool lua_util_dump_json (lua_State *L, int idx, sbuff_t *sbuf, bool json_ switch (lua_type(L, idx)) { case LUA_TNUMBER: { if (json_form && iskey) { - if (luaL_isinteger(L, idx)) + if (luaL_isinteger(L, idx)) { len = sprintf (tmp, "\"%ld\",", lua_tointeger(L, idx)); - else - len = sprintf (tmp, "\"%.14g\",", lua_tonumber(L, idx)); + } + else { + double d = lua_tonumber(L, idx); + if (isinf(d) || isnan(d)) { + lua_pushstring(L, "not support nan or infinity"); + return false; + } + len = sprintf (tmp, "\"%.14g\",", d); + } } else { - if (luaL_isinteger(L, idx)) + if (luaL_isinteger(L, idx)) { len = sprintf (tmp, "%ld,", lua_tointeger(L, idx)); - else - len = sprintf (tmp, "%.14g,", lua_tonumber(L, idx)); + } + else { + double d = lua_tonumber(L, idx); + if (isinf(d) || isnan(d)) { + lua_pushstring(L, "not support nan or infinity"); + return false; + } + len = sprintf (tmp, "%.14g,", lua_tonumber(L, idx)); + } } src_val = tmp; break; @@ -549,6 +563,15 @@ static int json_to_lua (lua_State *L, char **start, bool check, bool is_bignum) return 0; } +void minus_inst_count(lua_State *L, int count) { + int cnt = luaL_instcount(L); + + cnt -= count; + if (cnt <= 0) + cnt = 1; + luaL_setinstcount(L, cnt); +} + int lua_util_json_to_lua (lua_State *L, char *json, bool check) { if (json_to_lua (L, &json, check, false) != 0) @@ -586,6 +609,7 @@ char *lua_util_get_json_from_stack (lua_State *L, int start, int end, bool json_ sbuf.buf[sbuf.idx] = '\0'; } + minus_inst_count(L, strlen(sbuf.buf)); return sbuf.buf; } @@ -605,6 +629,7 @@ char *lua_util_get_json (lua_State *L, int idx, bool json_form) if (sbuf.idx != 0) sbuf.buf[sbuf.idx - 1] = '\0'; + minus_inst_count(L, strlen(sbuf.buf)); return sbuf.buf; } @@ -623,6 +648,7 @@ static int lua_json_decode (lua_State *L) char *org = (char *)luaL_checkstring(L, -1); char *json = strdup(org); + minus_inst_count(L, strlen(json)); if (lua_util_json_to_lua(L, json, true) != 0) { free (json); luaL_error(L, "not proper json format"); diff --git a/contract/util.h b/contract/util.h index 9496c60a4..a853788d2 100644 --- a/contract/util.h +++ b/contract/util.h @@ -5,6 +5,7 @@ char *lua_util_get_json (lua_State *L, int idx, bool json_form); int lua_util_json_to_lua (lua_State *L, char *json, bool check); char *lua_util_get_json_from_stack (lua_State *L, int start, int end, bool json_form); +void minus_inst_count(lua_State *L, int count); int luaopen_json(lua_State *L); diff --git a/contract/vm.c b/contract/vm.c index 3c1366503..6887ab86a 100644 --- a/contract/vm.c +++ b/contract/vm.c @@ -189,6 +189,7 @@ const char *vm_copy_result(lua_State *L, lua_State *target, int cnt) if (json == NULL) return lua_tostring(L, -1); + minus_inst_count(L, strlen(json)); lua_util_json_to_lua(target, json, false); free (json); } diff --git a/contract/vm_callback.go b/contract/vm_callback.go index f9f08586c..7354b5d5a 100644 --- a/contract/vm_callback.go +++ b/contract/vm_callback.go @@ -140,8 +140,12 @@ func setInstCount(parent *LState, child *LState) { C.luaL_setinstcount(parent, C.luaL_instcount(child)) } -func minusCallCount(curCount C.int) C.int { - remain := curCount - luaCallCountDeduc +func setInstMinusCount(L *LState, deduc C.int) { + C.luaL_setinstcount(L, minusCallCount(C.luaL_instcount(L), deduc)) +} + +func minusCallCount(curCount C.int, deduc C.int) C.int { + remain := curCount - deduc if remain <= 0 { remain = 1 } @@ -214,7 +218,7 @@ func LuaCallContract(L *LState, service *C.int, contractId *C.char, fname *C.cha stateSet.curContract = newContractInfo(callState, prevContractInfo.contractId, cid, callState.curState.SqlRecoveryPoint, amountBig) - ce.setCountHook(minusCallCount(C.luaL_instcount(L))) + ce.setCountHook(minusCallCount(C.luaL_instcount(L), luaCallCountDeduc)) defer setInstCount(L, ce.L) ret := ce.call(L) @@ -282,7 +286,7 @@ func LuaDelegateCallContract(L *LState, service *C.int, contractId *C.char, } } - ce.setCountHook(minusCallCount(C.luaL_instcount(L))) + ce.setCountHook(minusCallCount(C.luaL_instcount(L), luaCallCountDeduc)) defer setInstCount(L, ce.L) ret := ce.call(L) @@ -323,9 +327,6 @@ func LuaSendAmount(L *LState, service *C.int, contractId *C.char, amount *C.char if err != nil { return C.CString("[Contract.LuaSendAmount] invalid contractId: " + err.Error()) } - if amountBig.Cmp(zeroBig) == 0 { - return nil - } aid := types.ToAccountID(cid) callState, err := getCallState(stateSet, aid) @@ -354,17 +355,23 @@ func LuaSendAmount(L *LState, service *C.int, contractId *C.char, amount *C.char return C.CString("[Contract.LuaSendAmount] newExecutor error: " + ce.err.Error()) } - if r := sendBalance(L, senderState, callState.curState, amountBig); r != nil { - return r + if amountBig.Cmp(zeroBig) > 0 { + if r := sendBalance(L, senderState, callState.curState, amountBig); r != nil { + return r + } } if stateSet.lastRecoveryEntry != nil { - _ = setRecoveryPoint(aid, stateSet, senderState, callState, amountBig, true) + err = setRecoveryPoint(aid, stateSet, senderState, callState, amountBig, false) + if err != nil { + C.luaL_setsyserror(L) + return C.CString("[System.LuaSendAmount] database error: " + err.Error()) + } } prevContractInfo := stateSet.curContract stateSet.curContract = newContractInfo(callState, prevContractInfo.contractId, cid, callState.curState.SqlRecoveryPoint, amountBig) - ce.setCountHook(minusCallCount(C.luaL_instcount(L))) + ce.setCountHook(minusCallCount(C.luaL_instcount(L), luaCallCountDeduc)) defer setInstCount(L, ce.L) ce.call(L) @@ -375,6 +382,9 @@ func LuaSendAmount(L *LState, service *C.int, contractId *C.char, amount *C.char stateSet.curContract = prevContractInfo return nil } + if amountBig.Cmp(zeroBig) == 0 { + return nil + } if r := sendBalance(L, senderState, callState.curState, amountBig); r != nil { return r @@ -401,8 +411,9 @@ func sendBalance(L *LState, sender *types.State, receiver *types.State, amount * } //export LuaPrint -func LuaPrint(service *C.int, args *C.char) { +func LuaPrint(L *LState, service *C.int, args *C.char) { stateSet := curStateSet[*service] + setInstMinusCount(L, 1000) logger.Info().Str("Contract SystemPrint", types.EncodeAddress(stateSet.curContract.contractId)).Msg(C.GoString(args)) } @@ -516,6 +527,7 @@ func LuaGetBalance(L *LState, service *C.int, contractId *C.char) (*C.char, *C.c //export LuaGetSender func LuaGetSender(L *LState, service *C.int) *C.char { stateSet := curStateSet[*service] + setInstMinusCount(L, 1000) return C.CString(types.EncodeAddress(stateSet.curContract.sender)) } @@ -540,6 +552,7 @@ func LuaGetTimeStamp(L *LState, service *C.int) C.lua_Integer { //export LuaGetContractId func LuaGetContractId(L *LState, service *C.int) *C.char { stateSet := curStateSet[*service] + setInstMinusCount(L, 1000) return C.CString(types.EncodeAddress(stateSet.curContract.contractId)) } @@ -552,6 +565,7 @@ func LuaGetAmount(L *LState, service *C.int) *C.char { //export LuaGetOrigin func LuaGetOrigin(L *LState, service *C.int) *C.char { stateSet := curStateSet[*service] + setInstMinusCount(L, 1000) return C.CString(types.EncodeAddress(stateSet.origin)) } @@ -636,6 +650,7 @@ func LuaECVerify(L *LState, msg *C.char, sig *C.char, addr *C.char) (C.int, *C.c return -1, C.CString("[Contract.LuaEcVerify] invalid signature format: " + err.Error()) } address := C.GoString(addr) + setInstMinusCount(L, 10000) var pubKey *btcec.PublicKey var verifyResult bool @@ -733,11 +748,19 @@ func transformAmount(amountStr string) (*big.Int, error) { } if prev >= len(amountStr) { - return ret, nil + if ret != nil { + return ret, nil + } else { + return zeroBig, nil + } } num := strings.TrimSpace(amountStr[prev:]) if len(num) == 0 { - return ret, nil + if ret != nil { + return ret, nil + } else { + return zeroBig, nil + } } amountBig, _ := new(big.Int).SetString(num, 10) @@ -883,7 +906,7 @@ func LuaDeployContract( addr := C.CString(types.EncodeAddress(newContract.ID())) ret := C.int(1) if ce != nil { - ce.setCountHook(minusCallCount(C.luaL_instcount(L))) + ce.setCountHook(minusCallCount(C.luaL_instcount(L), luaCallCountDeduc)) defer setInstCount(L, ce.L) ret += ce.call(L) @@ -905,25 +928,13 @@ func IsPublic() C.int { } } -//export LuaRandomNumber -func LuaRandomNumber(L *LState, service C.int) C.double { - stateSet := curStateSet[service] - if stateSet.seed == nil { - setRandomSeed(stateSet) - } - return C.double(stateSet.seed.Float64()) -} - //export LuaRandomInt -func LuaRandomInt(L *LState, min, max C.int, service C.int) C.lua_Integer { +func LuaRandomInt(min, max, service C.int) C.int { stateSet := curStateSet[service] if stateSet.seed == nil { setRandomSeed(stateSet) } - if C.lua_gettop(L) == 1 { - return C.lua_Integer(stateSet.seed.Intn(int(min)) + int(1)) - } - return C.lua_Integer(stateSet.seed.Intn(int(max+C.int(1)-min)) + int(min)) + return C.int(stateSet.seed.Intn(int(max+C.int(1)-min)) + int(min)) } //export LuaEvent diff --git a/contract/vm_test.go b/contract/vm_test.go index 389a8a783..92bd71f30 100644 --- a/contract/vm_test.go +++ b/contract/vm_test.go @@ -1903,6 +1903,13 @@ func TestArray(t *testing.T) { NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[1]}`), NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[0]}`).Fail("index out of range"), NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[1]}`), + NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[1.00000001]}`).Fail("integer expected, got number"), + NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":["1"]}`).Fail("integer expected, got string)"), + NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[true]}`).Fail("integer expected, got boolean"), + NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[[1, 2]]}`).Fail("integer expected, got table"), + NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[null]}`).Fail("integer expected, got nil)"), + NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[{}]}`).Fail("integer expected, got table)"), + NewLuaTxCall("ktlee", "array", 0, `{"Name":"inc", "Args":[""]}`).Fail("integer expected, got string)"), NewLuaTxCall("ktlee", "array", 0, `{"Name":"set", "Args":[2,"ktlee"]}`), ) if err != nil { @@ -3431,22 +3438,14 @@ abi.register(random)` if err != nil { t.Error(err) } - tx := NewLuaTxCall("ktlee", "random", 0, `{"Name": "random", "Args":[]}`) - tx1 := NewLuaTxCall("ktlee", "random", 0, `{"Name": "random", "Args":[]}`) - err = bc.ConnectBlock(tx, tx1) + err = bc.ConnectBlock( + NewLuaTxCall("ktlee", "random", 0, `{"Name": "random", "Args":[]}`).Fail( + "1 or 2 arguments required", + ), + ) if err != nil { t.Error(err) } - receipt := bc.getReceipt(tx.hash()) - err = checkRandomFloatValue(receipt.GetRet()) - if err != nil { - t.Errorf("error: %s, return value: %s", err.Error(), receipt.GetRet()) - } - receipt = bc.getReceipt(tx1.hash()) - err = checkRandomFloatValue(receipt.GetRet()) - if err != nil { - t.Errorf("error: %s, return value: %s", err.Error(), receipt.GetRet()) - } err = bc.ConnectBlock( NewLuaTxCall( @@ -3459,12 +3458,12 @@ abi.register(random)` t.Error(err) } - tx = NewLuaTxCall("ktlee", "random", 0, `{"Name": "random", "Args":[3]}`) + tx := NewLuaTxCall("ktlee", "random", 0, `{"Name": "random", "Args":[3]}`) err = bc.ConnectBlock(tx) if err != nil { t.Error(err) } - receipt = bc.getReceipt(tx.hash()) + receipt := bc.getReceipt(tx.hash()) err = checkRandomIntValue(receipt.GetRet(), 1, 3) if err != nil { t.Errorf("error: %s, return value: %s", err.Error(), receipt.GetRet()) @@ -3804,11 +3803,21 @@ function oom() s = s .. s end end -abi.register(oom)` + +function p() + pcall(oom) +end + +function cp() + contract.pcall(oom) +end +abi.register(oom, p, cp)` err = bc.ConnectBlock( NewLuaTxAccount("ktlee", 100), NewLuaTxDef("ktlee", "oom", 0, definition), + ) + err = bc.ConnectBlock( NewLuaTxCall( "ktlee", "oom", @@ -3823,7 +3832,30 @@ abi.register(oom)` if err != nil && !strings.Contains(err.Error(), errMsg) { t.Error(err) } + err = bc.ConnectBlock( + NewLuaTxCall( + "ktlee", + "oom", + 0, + `{"Name":"p"}`, + ).Fail(errMsg), + ) + if err != nil { + t.Error(err) + } + err = bc.ConnectBlock( + NewLuaTxCall( + "ktlee", + "oom", + 0, + `{"Name":"cp"}`, + ).Fail(errMsg), + ) + if err != nil { + t.Error(err) + } } + func TestDeploy2(t *testing.T) { deploy := ` function hello() @@ -3892,4 +3924,116 @@ abi.payable(constructor) } } +func TestInvalidKey(t *testing.T) { + src := ` +state.var { + h = state.map(), + arr = state.array(10), + v = state.value() +} + +t = {} + +function key_table() + local k = {} + t[k] = "table" +end + +function key_func() + t[key_table] = "function" +end + +function key_statemap(key) + t[h] = "state.map" +end + +function key_statearray(key) + t[arr] = "state.array" +end + +function key_statevalue(key) + t[v] = "state.value" +end + +function key_upval(key) + local k = {} + local f = function() + t[k] = "upval" + end + f() +end + +function key_nil(key) + h[nil] = "nil" +end + +abi.register(key_table, key_func, key_statemap, key_statearray, key_statevalue, key_upval, key_nil) +` + bc, _ := LoadDummyChain() + err := bc.ConnectBlock( + NewLuaTxAccount("ktlee", 100), + NewLuaTxDef("ktlee", "invalidkey", 0, src), + ) + if err != nil { + t.Error(err) + } + + err = bc.ConnectBlock( + NewLuaTxCall("ktlee", "invalidkey", 0, `{"Name":"key_table"}`).Fail( + "cannot use 'table' as a key", + ), + ) + if err != nil { + t.Error(err) + } + err = bc.ConnectBlock( + NewLuaTxCall("ktlee", "invalidkey", 0, `{"Name":"key_func"}`).Fail( + "cannot use 'function' as a key", + ), + ) + if err != nil { + t.Error(err) + } + err = bc.ConnectBlock( + NewLuaTxCall("ktlee", "invalidkey", 0, `{"Name":"key_statemap"}`).Fail( + "cannot use 'table' as a key", + ), + ) + if err != nil { + t.Error(err) + } + err = bc.ConnectBlock( + NewLuaTxCall("ktlee", "invalidkey", 0, `{"Name":"key_statearray"}`).Fail( + "cannot use 'userdata' as a key", + ), + ) + if err != nil { + t.Error(err) + } + err = bc.ConnectBlock( + NewLuaTxCall("ktlee", "invalidkey", 0, `{"Name":"key_statevalue"}`).Fail( + "cannot use 'table' as a key", + ), + ) + if err != nil { + t.Error(err) + } + err = bc.ConnectBlock( + NewLuaTxCall("ktlee", "invalidkey", 0, `{"Name":"key_upval"}`).Fail( + "cannot use 'table' as a key", + ), + ) + if err != nil { + t.Error(err) + } + err = bc.ConnectBlock( + NewLuaTxCall("ktlee", "invalidkey", 0, `{"Name":"key_nil"}`).Fail( + "bad argument #2 to '__newindex' (number or string expected)", + ), + ) + if err != nil { + t.Error(err) + } +} + // end of test-cases diff --git a/libtool/src/luajit b/libtool/src/luajit index 317711e07..0343aa3b2 160000 --- a/libtool/src/luajit +++ b/libtool/src/luajit @@ -1 +1 @@ -Subproject commit 317711e07ccd239038309266f0c087f30c29e94e +Subproject commit 0343aa3b24b06b7167c8db41440c25cafc37b97b diff --git a/types/genesis_preset.go b/types/genesis_preset.go index 7ba2024fa..87a5b9a90 100644 --- a/types/genesis_preset.go +++ b/types/genesis_preset.go @@ -2,4 +2,4 @@ package types var MainNetGenesis = "7b22636861696e5f6964223a7b227075626c6963223a747275652c226d61696e6e6574223a747275652c226d61676963223a22616572676f2e696f222c22636f6e73656e737573223a2264706f73227d2c2274696d657374616d70223a313535353330343430313030303030303030302c2262616c616e6365223a7b22416d4c725637746736394b45355a5165686b6a47694137794a7944784a32357579463936504d527074667a776f7a68414a62614b223a22353030303030303030303030303030303030303030303030303030227d2c22627073223a5b2231365569753248416d4552726637577174567072367a727441595a57377737433974785134765036686145734b795347386332634a222c2231365569753248416d47384847453241663753595a51484d596568326b316e426667545962344c753268616641515050567a785175222c2231365569753248416b776a4a674c64726e5736546e6f4237676a386270576d6d516f79446550636971534c717953556e326d664563222c2231365569753248416d5539576b6f454a516765684a557438626850747a537139734e68394566585169586f746f745272796a696465222c2231365569753248416d5652436d4854707637724544706168486d486b544c6a33487a5970354343646a4c78737a45564e455a72336e222c2231365569753248416b7a374e524a357064617750667a52786969534d647070703673636d5238417741577969396f4d643647596346222c2231365569753248416b75653454626f394b394c7651396568774e5548525771344b5676465752764d77585a466b5078354a69615642222c2231365569753248416d56324b453251387654485941574278755246667562597578415052455939614b31475a3945573156614c4147222c2231365569753248416d5441656370703465644e575867517a754a354d58667a674672745563547970767562784e727a316f484e5575222c2231365569753248416d46576e6a63476a3270346f776472374d737550454b42326f4342424c647a3479456d477262324e3466765647222c2231365569753248416d424250325a33555632676a556a773143747068617a6b456e4c76786b6356374432354c434d3263633731696e222c2231365569753248416b783436616945354346697a6f624c3170345263784b483831383864515361485a747078746b39644e654e7671222c2231365569753248416d56685345723371754336416933644863554d48695552665a624865373358654a7446416d3857574a69547135225d7d" -var TestNetGenesis = "7b22636861696e5f6964223a7b227075626c6963223a747275652c226d61696e6e6574223a66616c73652c226d61676963223a22746573746e65742e616572676f2e696f222c22636f6e73656e737573223a2264706f73227d2c2274696d657374616d70223a313535333637393030303030303030303030302c2262616c616e6365223a7b22416d4c735366786f396151525a4a42764d426f4c466239515a4142514b32526947335571314a4268794166624459506633314a32223a22313030303030303030303030303030303030303030303030222c22416d4d4b334c5a6952316f45663636787a586972376d4135535556564853696e5755596d6835467775656f566d6369483343754a223a22343939313030303030303030303030303030303030303030303030222c22416d4d5231434c484e6e4243713769745935585258344c714c73355665316e5a4b7841634252565a74776373526472797446716b223a22313030303030303030303030303030303030303030303030222c22416d4d766d753648785268594d6a5667696834735853597944694d38487075765a466e50395648557455643935715455454e5236223a22313030303030303030303030303030303030303030303030222c22416d4e4566734b74317632676f73627536654d673766474263686b4a7a7645636d624738413445654d7975734155334d33386d6b223a22313030303030303030303030303030303030303030303030222c22416d4e4a5268346e745157543134356a5177444851477548596441546d4d57434562454e5732444e376d7a746672357071506250223a22313030303030303030303030303030303030303030303030222c22416d4e536d6b4474777753537247486b34455038794c5037596143363239666a6e50673937374a4a664c705465397a5874707364223a22313030303030303030303030303030303030303030303030222c22416d4e6d6b4b584b677758474c4263356f466869314d75784e786e4a4c7776575550485635777235756e48564e7758314d665865223a22313030303030303030303030303030303030303030303030222c22416d50357659586548426a47757671446147725a426f48795448454a63557a7455447654616d32487a717641396a736571656b64223a22313030303030303030303030303030303030303030303030222c22416d504a524c48444b747a4c707361433875626d5075526b786e4d437942537135774277594e444436444a646769526841685952223a22313030303030303030303030303030303030303030303030227d2c22627073223a5b2231365569753248416d416f6b5941744c625a784a4150526770326a43633462443335634a4439323174727155414e6835395263346e222c2231365569753248416d347859744773716b3757474b5578723870726656704a323568443233415133426536616e454c394b786b6777222c2231365569753248416d47694a325167564157484d55747a4c4b4b4e4d356546554a33447333464e376e594a71316d484e355a506a39222c2231365569753248416d524e59364345444d514b75556b5562697837514470703166464167337952564d6f4a4a444e7a7462477a6448222c2231365569753248416d31384c795462395757564e57636a35476e383366555034636b7178677939417a48677a59735870695a384a41222c2231365569753248416d4e6165727436487353615731626273384a6233685571326e57366979694d676a31684277546735466b427350222c2231365569753248416d5636695647754e3331735a547a32474469634650704272366561486e316d564d343939424777534266364e62222c2231365569753248416d376d763831676b654c4d747732376235646f58487668454c516e487766486842665a4c4771724c6a5a4c565a222c2231365569753248416d344e747663714e4b465755317a336f4d5242335a756765386a765a693379626e367842745a6b4c4145765557225d7d" +var TestNetGenesis = "7b22636861696e5f6964223a7b227075626c6963223a747275652c226d61696e6e6574223a66616c73652c226d61676963223a22746573746e65742e616572676f2e696f222c22636f6e73656e737573223a2264706f73227d2c2274696d657374616d70223a313535353035303630303030303030303030302c2262616c616e6365223a7b22416d4c735366786f396151525a4a42764d426f4c466239515a4142514b32526947335571314a4268794166624459506633314a32223a22313030303030303030303030303030303030303030303030222c22416d4d4b334c5a6952316f45663636787a586972376d4135535556564853696e5755596d6835467775656f566d6369483343754a223a22343939353030303030303030303030303030303030303030303030222c22416d4d5231434c484e6e4243713769745935585258344c714c73355665316e5a4b7841634252565a74776373526472797446716b223a22313030303030303030303030303030303030303030303030222c22416d4e536d6b4474777753537247486b34455038794c5037596143363239666a6e50673937374a4a664c705465397a5874707364223a22313030303030303030303030303030303030303030303030222c22416d4e6d6b4b584b677758474c4263356f466869314d75784e786e4a4c7776575550485635777235756e48564e7758314d665865223a22313030303030303030303030303030303030303030303030222c22416d504a524c48444b747a4c707361433875626d5075526b786e4d437942537135774277594e444436444a646769526841685952223a22313030303030303030303030303030303030303030303030227d2c22627073223a5b2231365569753248416d416f6b5941744c625a784a4150526770326a43633462443335634a4439323174727155414e6835395263346e222c2231365569753248416d347859744773716b3757474b5578723870726656704a323568443233415133426536616e454c394b786b6777222c2231365569753248416d47694a325167564157484d55747a4c4b4b4e4d356546554a33447333464e376e594a71316d484e355a506a39222c2231365569753248416d524e59364345444d514b75556b5562697837514470703166464167337952564d6f4a4a444e7a7462477a6448222c2231365569753248416d31384c795462395757564e57636a35476e383366555034636b7178677939417a48677a59735870695a384a41225d7d" diff --git a/types/receipt.go b/types/receipt.go index 896aa7acf..551c44d1b 100644 --- a/types/receipt.go +++ b/types/receipt.go @@ -560,7 +560,6 @@ func (ev *Event) MarshalJSON() ([]byte, error) { } func (ev *Event) SetMemoryInfo(receipt *Receipt, blkHash []byte, blkNo BlockNo, txIdx int32) { - ev.ContractAddress = AddressOrigin(ev.ContractAddress) ev.TxHash = receipt.TxHash ev.TxIndex = txIdx ev.BlockHash = blkHash @@ -613,6 +612,7 @@ func (ev *Event) Filter(filter *FilterInfo, argFilter []ArgFilter) bool { } } } + ev.ContractAddress = AddressOrigin(ev.ContractAddress) return true } @@ -677,7 +677,7 @@ func (fi *FilterInfo) GetExArgFilter() ([]ArgFilter, error) { for key, value := range argMap { idx, err := strconv.ParseInt(key, 10, 32) if err != nil || idx < 0 { - return nil, errors.New("invalid argument number:" + err.Error()) + return nil, errors.New("invalid argument number:" + key) } argFilter[i].argNo = int(idx) argFilter[i].value = value