0

I have a stellar account say "ACCOUNT1" with the following attributes:

  • MasterWeight = 2
  • Threshold [ 1, 2, 3]
  • Signers:
    • Masterkey with weight 2
    • ed25519_public_key with weight 1 (say ACCOUNT2)
    • sha256_hash key with weight 2

Now, I am trying to send a transaction with ACCOUNT2 (weight 1) and sha256 key (weight 2) as signers.

The operation trying to make:

ACCOUNT1's weight to 0
Threshold [1, 1, 1]
Remove sha256_hash key from the signer list

Following are the code snippets of how I am trying to achieve this using go sdk:

1. Create TransactionBuilder with appropriate operations set

tx, err := build.Transaction(....)

2. Sign the tx with ACCOUNT2's seed and create TransactionEnvelopBuilder

txBEnv, err := tx.Sign("ACCOUNT2's Seed")

3. Create DecoratedSignature array to populate one more signature

signaturearr := make([]xdr.DecoratedSignature, len(txBEnv.E.Signatures)+1)

4. Populate existing signatures from the txBEnv

for i, element := range txBEnv.E.Signatures{
     signaturearr[i] = element
}

5. Create new DecoratedSignature using Hash(x) key's x

key := getEncodedKey("WORLDISBEAUTIFUL") key := "WORLDISBEAUTIFUL"

where,


func getEncodedKey(key string ) ([]byte) {
     src := []byte(key)

     dst := make([]byte, hex.EncodedLen(len(src)))
     hex.Encode(dst, src)

     return dst
 }

 ds0 := xdr.DecoratedSignature{
      Hint: xdr.SignatureHint(Hint(key)),
      Signature: xdr.Signature(key[:]),
      Hint: xdr.SignatureHint(Hint([]byte(key))),
      Signature: xdr.Signature([]byte(key)),
 }

where,


func Hint(publickey []byte) (r [4]byte) {
    hasher := sha256.New()
    hasher.Write(publickey)

    bytekey := hasher.Sum(nil)
    copy(r[:], bytekey[len(bytekey) - 4 :])
    return
}

6. Finally, insert the DecoratedSignature of Hash(x) into the array and assign back


signaturearr[len(signaturearr) - 1] = ds0
txBEnv.E.Signatures = signaturearr

txeB64, err := txBEnv.Base64()

I am always receiving Submit transaction error: TransactionResultCodeTxFailed 300 48 as response in my application.

If I use the constructed signed txn and post using Stellar laboratory, I am getting following result.

"result_codes": { "transaction": "tx_failed", "operations": [ "op_bad_auth", "op_success", "op_success" ] },

Well, first operation is failing, where as the next two succeeds!

I am not sure which part I am missing at the moment while creating new DecoratedSignature for sha256 key.

Looking forward to hear from you all on where I am doing wrong.

Update: I am attaching the XDR data as well:

AAAAALrCb69T8V68CmP1PIWYtwGctqvGyy+F418kuSjdJEsgAAABLACdzCoAAAAOAAAAAAAAAAAAAAADAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAALeMMq1cEGEDyDX3wMdlwSy3a/rQI1S8v4Y8Kd671Ed9QAAAAAAAAAAAAAAAkKMrOAAAABAkUzVA5sa7989N9gPfWZgRtI/X56N9wkndB5XZJEARq4KuY/qcbM7j11Zf7dn1WMRCi+/zyQf/Tb6vpjhB8YEA9fYiPIAAAAgNTc0ZjUyNGM0NDQ5NTM0MjQ1NDE1NTU0NDk0NjU1NGM=

Final Update: I have modified the code where I went wrong. Thanks everyone for your time and help. Let this thread help someone in need.

1
  • Hey! It may help if you also paste either a link to the Stellar Lab transaction or the raw xdr.
    – Rob
    Aug 6, 2018 at 21:16

3 Answers 3

3

It looks like the SignatureHint for hash(x) in your transaction is invalid. Signature hint for hash(x) is the 4 last bytes of the hash, not the preimage. Fix required around:

Hint: xdr.SignatureHint(Hint(key)),

The sha256 hash is equal:

de30cab57041840f20d7df031d9704b2ddafeb408d52f2fe18f0a77aef511df5

So the hint should be equal ef511df5 but it's d7d888f2.

Your transaction bytes:

00000000  00 00 00 00 ba c2 6f af  53 f1 5e bc 0a 63 f5 3c  |......o.S.^..c.<|
00000010  85 98 b7 01 9c b6 ab c6  cb 2f 85 e3 5f 24 b9 28  |........./.._$.(|
00000020  dd 24 4b 20 00 00 01 2c  00 9d cc 2a 00 00 00 12  |.$K ...,...*....|
00000030  00 00 00 00 00 00 00 00  00 00 00 03 00 00 00 00  |................|
00000040  00 00 00 05 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 01 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000070  00 00 00 05 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000080  00 00 00 00 00 00 00 01  00 00 00 01 00 00 00 01  |................|
00000090  00 00 00 01 00 00 00 01  00 00 00 01 00 00 00 00  |................|
000000a0  00 00 00 00 00 00 00 00  00 00 00 05 00 00 00 00  |................|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 01  |................|
000000d0  00 00 00 02 de 30 ca b5  70 41 84 0f 20 d7 df 03  |.....0..pA.. ...|
000000e0  1d 97 04 b2 dd af eb 40  8d 52 f2 fe 18 f0 a7 7a  |[email protected]|
000000f0  ef 51 1d f5 00 00 00 00  00 00 00 00 00 00 00 02  |.Q..............|
00000100  42 8c ac e0 00 00 00 40  db 24 7a 59 1c 73 4f 4f  |B......@.$zY.sOO|
00000110  6f e1 18 47 2e 5e b8 e7  57 e1 bb 08 e6 37 94 17  |o..G.^..W....7..|
00000120  09 6c 98 bf 80 01 f3 b1  0f 35 b0 82 dd 4a 95 c0  |.l.......5...J..|
00000130  23 63 9f 24 40 88 96 3f  d5 59 e5 cf 9d b1 8f 1f  |#c.$@..?.Y......|
00000140  4b 51 14 54 a3 b3 52 08  d7 d8 88 f2 00 00 00 20  |KQ.T..R........ |
                                   ^^ ^^ ^^ ^^ signature hint here
00000150  35 37 34 66 35 32 34 63  34 34 34 39 35 33 34 32  |574f524c44495342|
00000160  34 35 34 31 35 35 35 34  34 39 34 36 35 35 34 63  |454155544946554c|
00000170

Relevant code in js-stellar-base:

let signature = preimage;
let hash = crypto.createHash('sha256').update(preimage).digest();
let hint = hash.slice(hash.length - 4);
this.signatures.push(new xdr.DecoratedSignature({hint, signature}));
1
  • Can confirm this with the tool I opened a PR for: github.com/stellar/laboratory/pull/348. Using this tool I see that the regular key's signature is valid while the hashx one is not.
    – Rob
    Aug 7, 2018 at 21:48
0

So the actual issue in this transaction is you changed the threshold in the second operation to {1,1,1} and then in the 3rd operation your trying to remove one signer and that will fall under the high threshold.

As you changed the threshold to 1 in the 2nd transaction you only need to sign the 3rd operation using a signer (weight 1). But what you done is you signed using Account 2 (weight 1) and the hash key(weight 2) as well. so its a Bad Auth transaction.

what you can do is easily divide this in to 2 separate transactions. Or else use another signer or Account 1 key and change the order of the transactions.

4
  • I tried to execute txn with one operation also. and the result is always op_bad_auth. <br> Moreover, If i sign this 3 different operation in single txn with ACCOUNT1 and ACCOUNT2 all 3 operations get executed successfully.
    – Malavan
    Aug 7, 2018 at 8:27
  • can you tell me the order you are doing the txn and the source account as well. That will help me to provide some solutions.
    – Sharmilan
    Aug 7, 2018 at 10:52
  • I think I have explained the execution order.
    – Malavan
    Aug 7, 2018 at 11:18
  • 1
    Yeah but your execution order and the xdr you mentioned are different
    – Sharmilan
    Aug 7, 2018 at 11:35
0

So the actual issue is when you make the SHA256 as a signer then you can't sign using the same hash value. What you need to do is to convert the actual string that you used for the hashing and to HEX. Then sign using that hex value. This will solve your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.