EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

transaction validation exception #64

Closed nsjames closed 6 years ago

nsjames commented 6 years ago

Version: 8.0.1

Error Message

code: 3030000, name: "transaction_exception", what: "transaction validation exception"
message: "condition: assertion failed: read"

image

It seems like perhaps nodeos isn't liking the packing for this method. When sending through cleos this works fine.

eosjs

// Method use
contract.user(user, user.key, sig, options)...

// Verified using `fc.fromBuffer`
{ user:
   { keyid: '0',
     key: 'EOS5YfsbxrWXPb6XnKy7R2JMV41JeLNsoePuGxvE1tenD4WEqJBL5',
     name: 'TestName',
     type: 'Whatever',
     bio: '',
     links: [],
     last_active: '0' },
  strkey: 'EOS5YfsbxrWXPb6XnKy7R2JMV41JeLNsoePuGxvE1tenD4WEqJBL5',
  sig: 'EOSKXwVayHuwGMmuFXEjdwRRjFZXe9f8TsnGnXgkmkptGP3zwWkbpFmfVMTps5M8qRFB7yvVQn5nVyyhiZwCyYZT7MdiN3bjB' }

cleos

cleos push action hackathon user '{"user":{
"keyid": 0,
"key":"EOS5YfsbxrWXPb6XnKy7R2JMV41JeLNsoePuGxvE1tenD4WEqJBL5",
"name":"TestName",
"type":"Whatever",
"bio": "",
"links": [],
"last_active": 0 
}, "strkey":"EOS5YfsbxrWXPb6XnKy7R2JMV41JeLNsoePuGxvE1tenD4WEqJBL5", 
"sig":"EOSKXwVayHuwGMmuFXEjdwRRjFZXe9f8TsnGnXgkmkptGP3zwWkbpFmfVMTps5M8qRFB7yvVQn5nVyyhiZwCyYZT7MdiN3bjB"}' -p eosio

Relevant ABI

"types": [{
    "new_type_name": "uuid",
    "type": "uint64"
}]
"name": "User",
"base": "",
"fields": [{
    "name": "keyid",
    "type": "uuid"
},{
    "name": "key",
    "type": "public_key"
},{
    "name": "name",
    "type": "string"
},{
    "name": "type",
    "type": "string"
},{
    "name": "bio",
    "type": "string"
},{
    "name": "links",
    "type": "Link[]"
},{
    "name": "last_active",
    "type": "uint64"
}]
{
"name": "user",
"base": "",
"fields": [{
    "name": "user",
    "type": "User"
},{
    "name": "strkey",
    "type": "string"
},{
    "name": "sig",
    "type": "signature"
}]
}

From empty action method contract.user()

EXAMPLE
{
    "user": {
        "keyid": "0",
        "key": "EOS6MRy..",
        "name": "",
        "type": "",
        "bio": "",
        "links": [
            {
                "name": "",
                "url": ""
            }
        ],
        "last_active": "0"
    },
    "strkey": "",
    "sig": "SIGnature.."
}
nsjames commented 6 years ago

This happens due to the "signature" field. When removed it works fine.

jcalfee commented 6 years ago

Do you know the matching eosio branch or tag? I want to lookup wasm_interface.cpp line 808 ..

nsjames commented 6 years ago

I'm on master but it looks like i'm a bit behind. I'll pull, rebuild, try again and report back.

Your branch is behind 'origin/master' by 273 commits, and can be fast-forwarded.

nsjames commented 6 years ago

Yup looks like there's still an issue

image

image

nsjames commented 6 years ago

Here's a comment from Jonathan Giszczak about this on Telegram

I'd say the signature hasn't been packaged up quite right. The actual error looks more or less unrelated, or misdirected, as if it were trying to interpret the signature as a contract action.

jcalfee commented 6 years ago

I think I found it.. I need an extra prefixing byte in the binary format. Where I still have 65 bytes there are 66 bytes now:

struct signature {
   uint8_t data[66];
};

They have K1 and R1 signatures so the first byte identifies which type. I'm pretty sure I'm after the first format in the ecc name space:

using storage_type = static_variant<ecc::signature_shim, r1::signature_shim>;

ref

jcalfee commented 6 years ago

npm published eosjs@9.0.1 (eosjs@dawn3) .. should be fixed

nsjames commented 6 years ago

image

Yup that was definitely it! Thanks for the quick turnaround.

By the way it seems ecc is not defined in the structs.js which leads to an error when trying to use it. I've put up a pull request fix for it but you might want to pull out the deeper Signature object instead.