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

1484 net v2 #1586

Draft
wants to merge 114 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
f383915
docs: account-module.md
lucanicoladebiasi Nov 27, 2024
41c5438
docs: transaction-module.md
lucanicoladebiasi Nov 27, 2024
5909d12
docs: blocks-module.md
lucanicoladebiasi Nov 27, 2024
0315e90
docs: blocks-module.md
lucanicoladebiasi Nov 27, 2024
24ed557
docs: logs-module.md
lucanicoladebiasi Nov 27, 2024
e31b8bc
docs: logs-module.md
lucanicoladebiasi Nov 27, 2024
bfbba27
docs: node-module.md
lucanicoladebiasi Nov 27, 2024
3760d1b
Merge branch 'refs/heads/main' into v2
lucanicoladebiasi Nov 28, 2024
aaf95ba
docs: node-module.md
lucanicoladebiasi Nov 28, 2024
def5905
Merge branch 'main' into v2
lucanicoladebiasi Nov 29, 2024
36a0d13
docs: subscriptions-module.md
lucanicoladebiasi Nov 29, 2024
288e905
docs: debug-module.md
lucanicoladebiasi Nov 29, 2024
b25891b
feat: v2 network dev...
lucanicoladebiasi Nov 29, 2024
4a1e775
feat: v2 http dev...
lucanicoladebiasi Nov 30, 2024
5f8a6df
feat: v2 http dev...
lucanicoladebiasi Nov 30, 2024
58606c7
feat: v2 http dev...
lucanicoladebiasi Nov 30, 2024
5cdd9a2
feat: v2 thor node dev...
lucanicoladebiasi Dec 1, 2024
af56fe6
feat: v2 thor node dev...
lucanicoladebiasi Dec 1, 2024
8f7d167
feat: v2 thor node dev...
lucanicoladebiasi Dec 2, 2024
9b231f0
feat: v2 thor node dev...
lucanicoladebiasi Dec 2, 2024
73f1d54
feat: v2 thor account dev...
lucanicoladebiasi Dec 2, 2024
d9eafd3
feat: v2 thor account dev...
lucanicoladebiasi Dec 2, 2024
96eb3b1
feat: v2 thor account dev...
lucanicoladebiasi Dec 3, 2024
cc9e728
feat: v2 thor account dev...
lucanicoladebiasi Dec 3, 2024
f99f3f5
feat: v2 thor account dev...
lucanicoladebiasi Dec 3, 2024
81610c6
feat: v2 thor account dev...
lucanicoladebiasi Dec 3, 2024
c0c2b73
feat: v2 thor account dev...
lucanicoladebiasi Dec 3, 2024
6bcd7e3
feat: v2 thor transactions dev...
lucanicoladebiasi Dec 5, 2024
236a784
feat: v2 thor transactions dev...
lucanicoladebiasi Dec 6, 2024
b6e518f
feat: v2 thor transactions dev...
lucanicoladebiasi Dec 6, 2024
c702280
feat: v2 thor transactions dev...
lucanicoladebiasi Dec 7, 2024
f73ad0d
feat: v2 thor transactions dev...
lucanicoladebiasi Dec 8, 2024
9c2c1e1
Merge branch 'main' into 1484-v2-network-httpclient
lucanicoladebiasi Dec 9, 2024
3475fcb
feat: v2 thor transactions dev...
lucanicoladebiasi Dec 9, 2024
f1dffc4
feat: v2 thor transactions dev...
lucanicoladebiasi Dec 9, 2024
d6bfea4
Merge branch 'main' into 1484-v2-network-httpclient
lucanicoladebiasi Dec 9, 2024
eab7a7f
fix: 1560 Transaction.ts allows making of incomplete signed instances
lucanicoladebiasi Dec 10, 2024
6ced514
feat: 1484 net in dev...
lucanicoladebiasi Dec 11, 2024
af7bb8b
feat: 1484 net in dev...
lucanicoladebiasi Dec 11, 2024
02a86e6
feat: 1484 net in dev...
lucanicoladebiasi Dec 12, 2024
d374fc7
Merge branch 'main' into 1484-v2-network-httpclient
lucanicoladebiasi Dec 15, 2024
ac090e7
feat: 1484 additional VCDM classes direct import: to fix...
lucanicoladebiasi Dec 16, 2024
b8536e9
feat: 1484 additional VCDM classes direct import: to fix...
lucanicoladebiasi Dec 16, 2024
85e7ce4
feat: 1484 additional VCDM classes direct import: to fix...
lucanicoladebiasi Dec 17, 2024
1abd01b
feat: 1484 logs in dev...
lucanicoladebiasi Dec 17, 2024
3a82860
Merge branch 'main' into 1484-net
lucanicoladebiasi Dec 17, 2024
c94537f
feat: 1484 logs in dev...
lucanicoladebiasi Dec 18, 2024
f1c6589
feat: 1484 logs in dev...
lucanicoladebiasi Dec 18, 2024
23e26d1
feat: 1484 log in dev...
lucanicoladebiasi Dec 18, 2024
c589254
feat: 1484 log in dev...
lucanicoladebiasi Dec 18, 2024
febf364
feat: 1484 log in dev...
lucanicoladebiasi Dec 18, 2024
c1d2257
feat: 1484 log in dev...
lucanicoladebiasi Dec 18, 2024
da976d2
feat: 1484 log in dev...
lucanicoladebiasi Dec 18, 2024
c390fc7
feat: 1484 log in dev...
lucanicoladebiasi Dec 19, 2024
4b4c15f
feat: 1484 debug in dev...
lucanicoladebiasi Dec 19, 2024
cc7f3e3
Merge branch 'main' into 1484-net
lucanicoladebiasi Dec 19, 2024
549acc0
feat: 1484 debug in dev...
lucanicoladebiasi Dec 19, 2024
0423a91
feat: 1484 debug in dev...
lucanicoladebiasi Dec 19, 2024
dbc0862
feat: 1484 debug in dev...
lucanicoladebiasi Dec 19, 2024
8f9922f
feat: 1484 debug in dev...
lucanicoladebiasi Dec 19, 2024
c064133
Merge remote-tracking branch 'origin/1484-net' into 1484-net
lucanicoladebiasi Dec 19, 2024
1a8b28d
Merge branch 'main' into 1484-net
fabiorigam Dec 20, 2024
12ecaa4
feat: 1484 account clauses in dev...
lucanicoladebiasi Dec 21, 2024
20fba38
feat: 1484 account clauses prototype
lucanicoladebiasi Dec 21, 2024
4e4b8b9
Merge branch 'refs/heads/main' into 1484-net
lucanicoladebiasi Dec 23, 2024
c528979
feat: 1484 ws in dev...
lucanicoladebiasi Dec 24, 2024
13c98d8
feat: 1484 ws in dev...
lucanicoladebiasi Dec 24, 2024
b32cca1
feat: 1484 ws in dev...
lucanicoladebiasi Dec 24, 2024
a45098e
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 24, 2024
7342e45
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 24, 2024
88faf21
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 24, 2024
4c82215
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 25, 2024
70739ed
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 25, 2024
b7b0282
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 25, 2024
0fec0f5
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 25, 2024
07e252c
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 25, 2024
3d1715b
feat: 1484 subscriptions in dev...
lucanicoladebiasi Dec 25, 2024
b832d3d
feat: 1484 subscriptions prototype
lucanicoladebiasi Dec 25, 2024
769eb89
feat: 1484 subscriptions documenting...
lucanicoladebiasi Dec 26, 2024
3c1292d
feat: 1484 subscriptions documenting...
lucanicoladebiasi Dec 26, 2024
958a411
feat: 1484 subscriptions documenting...
lucanicoladebiasi Dec 26, 2024
f1b124b
feat: 1484 subscriptions documenting...
lucanicoladebiasi Dec 26, 2024
184f590
feat: 1484 subscriptions documenting...
lucanicoladebiasi Dec 27, 2024
0cbaabf
feat: 1484 subscriptions documenting...
lucanicoladebiasi Dec 27, 2024
ab71726
feat: 1484 account and subscriptions documented
lucanicoladebiasi Dec 28, 2024
e0c98c3
feat: 1484 blocks documented
lucanicoladebiasi Dec 28, 2024
bbe0bcf
feat: 1484 blocks documented
lucanicoladebiasi Dec 28, 2024
2ce7e99
feat: 1484 blocks documented
lucanicoladebiasi Dec 28, 2024
f8fd51b
feat: 1484 blocks documented
lucanicoladebiasi Dec 28, 2024
d3b495d
feat: 1484 debug documented
lucanicoladebiasi Dec 29, 2024
c8a2992
feat: 1484 debug documented
lucanicoladebiasi Dec 29, 2024
e1f4e0d
feat: 1484 debug documented
lucanicoladebiasi Dec 29, 2024
9873bee
Merge branch 'refs/heads/main' into 1484-net
lucanicoladebiasi Dec 30, 2024
1759bb8
Merge branch 'main' into 1484-net
fabiorigam Dec 30, 2024
5264651
feat: 1484 logs documented
lucanicoladebiasi Dec 30, 2024
18ed3c3
Merge remote-tracking branch 'origin/1484-net' into 1484-net
lucanicoladebiasi Dec 30, 2024
fa93b40
feat: 1484 logs documented
lucanicoladebiasi Dec 30, 2024
19bd10e
feat: 1484 node documented
lucanicoladebiasi Dec 30, 2024
066f0c4
feat: 1484 node documented
lucanicoladebiasi Dec 30, 2024
c7f4f97
feat: 1484 node documented
lucanicoladebiasi Dec 30, 2024
37bfe66
feat: 1484 node documented
lucanicoladebiasi Dec 30, 2024
f619998
feat: 1484 node documented
lucanicoladebiasi Dec 30, 2024
320173d
feat: 1484 node documented
lucanicoladebiasi Jan 1, 2025
4e22ce0
feat: 1484 node documented
lucanicoladebiasi Jan 1, 2025
7f8d35f
feat: 1484 node documented
lucanicoladebiasi Jan 1, 2025
e115940
Merge branch 'main' into 1484-net
lucanicoladebiasi Jan 2, 2025
24645b8
Merge branch 'main' into 1484-net
lucanicoladebiasi Jan 6, 2025
70469df
Merge branch 'refs/heads/main' into 1484-net
lucanicoladebiasi Jan 7, 2025
602153e
feat: 1484 transaction id flowchart
lucanicoladebiasi Jan 7, 2025
0d0f3e1
feat: 1484 transaction id flowchart
lucanicoladebiasi Jan 7, 2025
fa68478
feat: 1484 transaction id flowchart
lucanicoladebiasi Jan 7, 2025
9bccf8d
feat: 1484 transaction id flowchart
lucanicoladebiasi Jan 7, 2025
7dd2907
Merge branch 'main' into 1484-net
lucanicoladebiasi Jan 8, 2025
8e167d9
feat: 1484 transaction id flowchart
lucanicoladebiasi Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions docs/diagrams/v2/core/transaction/transaction_id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# Transaction IDs May Collide

The class [`Transaction`](../../../../../packages/core/src/transaction/Transaction.ts)
provides the computed property `Transaction.id()` to compute the transaction's identifier
as (l.242)

```typescript
public get id(): Blake2b256 {
if (this.isSigned) {
return Blake2b256.of(
nc_utils.concatBytes(
this.getTransactionHash().bytes,
this.origin.bytes
)
);
}
throw new UnavailableTransactionField(
'Transaction.id()',
'not signed transaction: id unavailable',
{fieldName: 'id'}
);
}
```

The following flowchart shows the inputs, methods and properties involved.

```mermaid
flowchart TD
start((Start))
stop(((stop)))
body[/TransactionBody/]
subgraph origin
origin_txHash[["getTransactionHash()"]]
origin_signature[\signature\]
origin_recover[["Secp256k1.recover(txHash,signature)"]]
origin_address["Address.ofPublicKey(publicKey)"]
origin_recover --> origin_address
origin_signature --> origin_recover

end
subgraph tx_hash["Transaction.getTransactionHash(gasPayer?)"]
txHash_encodeHash[Blake256.of]
txHash_encodePayer[Blake2b256.of]
txHash_encode[[encode]]
txHash_payer?{gasPayer?}
txHash_payer[/gasPayer/]
txHash_encode --> txHash_encodeHash
txHash_encodeHash --> txHash_payer?
txHash_payer? -. yes .-> txHash_encodePayer
txHash_payer --> txHash_encodePayer
end
subgraph tx_id["Transaction.id()"]
id_hash[Blake2b256.of]
id_origin[["origin()"]]
id_txHash[["getTransactionHash()"]]
id_origin --> id_hash
id_txHash --> id_hash
end
body --> txHash_encode
id_hash --> stop
origin_address --> id_origin
origin_txHash --> origin_recover
start --> body
txHash_encodePayer --> id_txHash
txHash_payer? -- no --> id_txHash

```

## Not Delegated Transaction ID

NCC claims

_1. ... The transaction signature is not incorporated into the hash computation; only the transaction hash as well as
the
originator’s address are taken into account._ (p.12)

but we observe **the origin's address is derived by the origin's signature because the computed property**
`Transaction.origin` (l.304).

```typescript
public get origin(): Address
{
if (this.signature !== undefined) {
return Address.ofPublicKey(
// Get the origin public key.
Secp256k1.recover(
this.getTransactionHash().bytes,
// Get the (r, s) of ECDSA digital signature without gas payer params.
this.signature.slice(0, Secp256k1.SIGNATURE_LENGTH)
)
);
}
throw new UnavailableTransactionField(
'Transaction.origin()',
'not signed transaction, no origin',
{fieldName: 'origin'}
);
}
```

NCC clams

_ ... if a transaction was signed by a signer multiple times (or in case of different
transactions with colliding getTransactionHash()), the resulting signed transactions would
have the same ID._ (p.13)

We observe if the transaction is signed multiple times, it results the same id if the
`TransactionBody` object is equal and the origin's signature is the same.

### Question - ask NCC

Since the origin's address is a function of the origin's signature, **what is the difference
between to compute BLAKE2B256**

* **from the transaction hash and the origin's signature**, and
* **from the transaction hash and the origin's address derived from its signature?**

---

## Delegated Transaction ID

NCC claims

_2. In the case of delegated transactions, the function above also fails to take the gas
payer’s (aka delegator’s) signature and address into account._ (p.13)

We observe the claim is true: in the `Transaction.id` computed property at l.246

```typescript
this.getTransactionHash().bytes
```

does not pass the `gasPayer` as argument, hence NCC is right to claim

_... if a given to-be-delegated transaction were
signed by multiple different gas payers, the resulting IDs would all be equal (and would also
be equal to the ID of a non-delegated transaction)._ (p.13)

We observe the `reserved` flag in the `Transaction` body participates in the computed hash, hence
a delegated transaction should result in a different id then a not delegated transaction,
this is the only input in the BLAKE2B256 hash to differentiate the id transactions of the same
`TransactionBody` between the cases when the transaction is delegated and when is not. Since a transaction must
include the origin signature and if is delegated, must include the `reserved` property and a gas payer's signature,
we do not think there is a real useful case to forge the `reserved` field, nevertheless we think **

NCC recommends

_Consider modifying the id() function such that it includes the signer’s signature, and the
delegator’s (wrong name for the "gas payer") address and signature, if the transaction is delegated._ (p.13)

We think this should be done, but we must evaluate what is done in Thor as well and if the Thor ID algorithm must change
following the NCC recommendations.

NCC recommends

_... reflect on whether the id() function should product a different digest than the
getTransactionHash() of a delegated transaction._ (p.13)

**We think the id of delegated transaction should be different form its transaction's hash, we observe they are
different - matter of test - because the `Transaction.id` hashes the result of `Transaction.getTransactionHash`
concatenated with the transaction;s origin address.**

---

### Question - ask the protocol team

**The `gasPayer` signature or its derived address is never considered in the computation of the transaction hash!**

* **What is the algorithm used in the protocol**?
* **Is the same algorithm implemented the in e SDK?**
* **The algorithm in the protocol does consider the `taxPayer` address and signature in the computation of the id?**

**According to our tests, Thor and SDK produce the same id for the same transaction!**
---

## ID Equality

We presume is correct to state equal
[`TransactionBody`](../../../../../packages/core/src/transaction/TransactionBody.d.ts)
instances signed by the same origin and gas payer should return the same id.
Since Thor rejects a transaction with a spent id, the above criteria should never be a problem;
Thor blockchain should never have two transaction with the same id, ids should be unique.
However, the `TransactionBody` class exposes the `nonce` property that is involved in the computation
of the transaction's hash.

### Question - ask the protocol team

The `Transaction.encode` method processes an object of the
[`TransactionBody`](../../../../../packages/core/src/transaction/TransactionBody.d.ts)
class, the class provides the `nonce` property
The `nonce` property should be different for each transaction even if
the other properties of the transaction are equal, however no assumption are made about `nonce`.
* **Who sets the `nonce` property?**

---


35 changes: 35 additions & 0 deletions docs/diagrams/v2/net/http/http.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```mermaid
classDiagram
class FetchHttpClient {
baseURL: string
onRequest: OnRequest
onResponse: OnResponse
at(baseURL: string, onRequest: OnRequest, onResponse: OnResponse) FetchHttpClient
}
class HttpClient {
<<interface>>
get(httpPath: HttpPath, httpQuery: HttpQuery) Promise~Response~
post(httpPath: HttpPath, httpQuery: HttpQuery, body?: unknown) Promise~Response~
}
class HttpPath {
<<interface>>
path: string
}
class HttpQuery {
<<interface>>
query(): string;
}
class OnRequest {
<<callback>>
onRequest(request: Request) Request
}
class OnResponse{
<<callback>>
onResponse(response: Response) Response
}
FetchHttpClient *--> OnRequest
FetchHttpClient *--> OnResponse
HttpClient <|.. FetchHttpClient
HttpPath <-- "get - post" HttpClient
HttpQuery <-- "get - post" HttpClient
```
Loading
Loading