Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use quip10 when returning hash #124

Merged
merged 4 commits into from
May 15, 2024
Merged

use quip10 when returning hash #124

merged 4 commits into from
May 15, 2024

Conversation

robertlincecum
Copy link
Contributor

No description provided.

Copy link
Member

@rileystephens28 rileystephens28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is my understanding that QIP10 hashes are deterministic and the way we compute and compare this is not. We compute QIP10 hash that appears to be valid as a string but is not equal to what go-quai returns so we then compare the hashes on a range basis rather than for equality.

@@ -84,14 +69,23 @@ export class QiTransaction extends AbstractTransaction<string> implements QiTran
throw new Error("Cross-shard & cross-ledger transactions are not supported");
}

let hash = keccak256(data)
let hash = keccak256(this.serialized)
hash = '0x' + this.originShard+ (originUtxo ? 'F' : '1') + hash.charAt(5) + this.originShard+ (destUtxo ? 'F' : '1') + hash.slice(9)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation for getting the permuted QIP10 hash of a transaction should, for all intents and purposes, match that of go-quai. This means that we should be manipulating the hash as a uint8[] rather than string and setting the values that correspond to the first 4 elements of the uint8[]. Here is the implementation for how go-quai handles computing a Qi tx hash:

hash = crypto.Keccak256Hash(data)
// the origin of this tx is the *destination* of the utxos being spent
origin := tx.TxIn()[0].PreviousOutPoint.TxHash[1]
hash[0] = origin
hash[1] |= 0x80 // 10000000 in binary (set first bit to 1)
hash[2] = origin
hash[3] |= 0x80

@@ -142,12 +128,21 @@ export class QuaiTransaction extends AbstractTransaction<Signature> implements Q
throw new Error("Cross-shard & cross-ledger transactions are not supported");
}

let hash = keccak256(data)
let hash = keccak256(this.serialized)
hash = '0x' + this.originShard+ (originUtxo ? 'F' : '1') + hash.charAt(5) + this.originShard+ (destUtxo ? 'F' : '1') + hash.slice(9)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation for getting the permuted QIP10 hash of a transaction should, for all intents and purposes, match that of go-quai. This means that we should be manipulating the hash as a uint8[] rather than string and setting the values that correspond to the first 4 elements of the uint8[]. Here is the implementation for how go-quai handles computing a Quai tx hash:

hash = crypto.Keccak256Hash(data)
// the origin of this tx is the *destination* of the utxos being spent
if len(location) == 2 {
  origin := (uint8(location[0]) * 16) + uint8(location[1])
  hash[0] = origin
  hash[1] &= 0x7F // 01111111 in binary (set first bit to 0)
  hash[2] = origin
  hash[3] &= 0x7F
} else {
  from, err := Sender(NewSigner(tx.ChainId(), common.Location{0, 0}), tx) // location not important when performing ecrecover
  if err != nil {
    return h // Caller of this function will fail with wrong tx hash and will appropriately handle the error
  }
  location := *from.Location()
  origin := (uint8(location[0]) * 16) + uint8(location[1])
  hash[0] = origin
  hash[1] &= 0x7F
  hash[2] = origin
  hash[3] &= 0x7F
}

@rileystephens28 rileystephens28 merged commit e7ffbda into master May 15, 2024
@rileystephens28 rileystephens28 deleted the qip10-hash branch June 7, 2024 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants