Skip to content

Commit dd4a186

Browse files
authored
GH-4057 [Ceres]: Tamper protection for GAMetaTx (#513)
* GH-4057 [Ceres]: Tamper protection for GAMetaTx * fix: locally consistent s/z
1 parent fc82301 commit dd4a186

File tree

2 files changed

+55
-23
lines changed

2 files changed

+55
-23
lines changed

generalized_accounts/README.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
## Motivation
55

6-
Plain old accounts (POA) have very little flexibility when it comes to the logic
7-
controlling them. While this results in a uniform user experience and makes
8-
development easier, e.g. a wallet only needs to handle a single method of
6+
Plain old accounts (POA) have very little flexibility when it comes to the
7+
logic controlling them. While this results in a uniform user experience and
8+
makes development easier, e.g. a wallet only needs to handle a single method of
99
accessing accounts, it also ignores that people may have varying needs when
1010
managing their accounts.
1111

1212
This has led to a variety of smart contract wallets being developed, which can
13-
enforce spending limits, enable more sophisticated authorisation schemes via
13+
enforce spending limits, enable more sophisticated authorization schemes via
1414
multi-signatures and other things. The biggest drawback of this approach is the
1515
need to still own a "normal" account, in order to invoke the smart contract and
1616
pay for its execution.
@@ -25,7 +25,7 @@ system.
2525
## Approaches
2626

2727
We give a brief overview of some of the different approaches, that would allow
28-
for authorisation logic to be more flexible.
28+
for authorization logic to be more flexible.
2929

3030
They lie on a spectrum from the current fixed signature and nonce scheme to
3131
having full fledged smart contracts.
@@ -41,22 +41,22 @@ do it:
4141
In either case, signature logic will need to be touched, s.t. an empty signature
4242
can be accepted.
4343

44-
Additionally, the more flexible authorisation logic will make transaction
44+
Additionally, the more flexible authorization logic will make transaction
4545
validation costlier and therefore also increase the associated fees.
4646

4747

4848
### Side-effect free
4949

5050
A fairly non-invasive solution would be to attach a pure function to accounts.
51-
This means that all relevant authorisation code and data, e.g. public keys for
51+
This means that all relevant authorization code and data, e.g. public keys for
5252
signature checks, have to be included directly in the function body and can not
5353
be updated. Nonce handling would still be handled implicitly, i.e. stay
5454
unchanged.
5555

56-
Making the authorisation function optional ensures POAs to not be impacted.
56+
Making the authorization function optional ensures POAs to not be impacted.
5757

5858
The downsides of this would be the need to for special handling of the
59-
authorisation code because execution would not happen in the normal VM context
59+
authorization code because execution would not happen in the normal VM context
6060
and thus likely end up with a lot of implementation complexity.
6161

6262
This approach would be a slight improvement over the status quo but still leave
@@ -80,11 +80,11 @@ transaction types.
8080
### Hybrid
8181

8282
For the hybrid solution POAs and smart contracts stay separate, meaning that
83-
accounts can still be used with the implicit nonce and signature authorisation.
83+
accounts can still be used with the implicit nonce and signature authorization.
8484
But accounts are extended with two new fields, allowing its owner to specify the
8585
address of a smart contract and name of a function, which will be called
8686
whenever a transaction needs to be authorised.
87-
As soon as the new authorisation contract is attached to an account, it is no
87+
As soon as the new authorization contract is attached to an account, it is no
8888
longer possible to author transactions with the old nonce plus signature method.
8989

9090

@@ -122,11 +122,11 @@ prevents replay of old transactions.
122122

123123
In addition to integrity, the signature is used to prove that the issuer knows
124124
the private key for the public key specified in the `from` field, i.e. used as
125-
authorisation.
125+
authorization.
126126

127127
The above scheme is the only one natively supported via the POA.
128128

129-
If the authorisation were to be abstracted as well, then we end up with:
129+
If the authorization were to be abstracted as well, then we end up with:
130130

131131
```
132132
Fieldname Size (bytes)
@@ -188,18 +188,18 @@ to
188188
-------------- -----
189189
```
190190

191-
For the actual wire format please consult the [serialisation](../serializations.md) document.
191+
For the actual wire format please consult the [serialization](../serializations.md) document.
192192

193193
The `ga_contract` MUST be the identifier of a deployed contract or empty.
194194
The `ga_auth_fun` MUST be the identifier of a function to be called or empty.
195195

196196
If the `ga_contract` field is not empty, then the `ga_auth_fun` field MUST NOT
197197
be empty.
198198

199-
If `ga_contract` is not empty, then authorisation MUST be done by calling the
199+
If `ga_contract` is not empty, then authorization MUST be done by calling the
200200
`ga_auth_fun` of the contract located at `ga_contract`. The data provided to the
201201
`ga_auth_fun` is supplied via a [`meta_tx`](#meta_tx). The `ga_auth_fun` MUST
202-
return `true` for the authorisation to succeed.
202+
return `true` for the authorization to succeed.
203203

204204
The `nonce` field is irrelevant if the account is a GA.
205205

@@ -209,7 +209,7 @@ i.e. after a POA has been converted to a GA it cannot be undone.
209209
The `ga_contract` and `ga_auth_fun` fields MUST NOT change after they have been
210210
set once.
211211

212-
If the `ga_contract` field is empty, then authorisation MUST be done via the old
212+
If the `ga_contract` field is empty, then authorization MUST be done via the old
213213
verification of the signature attached to transactions. In this case, a
214214
transaction MUST only be considered valid, if
215215
1. a signature is attached, that has been produced by the private key that
@@ -252,7 +252,7 @@ Afterwards the new `meta_tx` is used to interact with the GA.
252252
-------------- -----
253253
```
254254

255-
For the actual wire format please consult the [serialisation](../serializations.md) document.
255+
For the actual wire format please consult the [serialization](../serializations.md) document.
256256

257257
The semantics of this transaction are almost identical to the [Create Contract Transaction](../contracts/contract_transactions.md#create-contract-transaction).
258258
As such, only the additional logic not covered by the `Create Contract
@@ -268,7 +268,7 @@ considered invalid.
268268
The transaction MUST include a signature created by the private key belonging to
269269
the `owner_id`.
270270

271-
The `auth_fun` is a function hash as described in the
271+
The `auth_fun` is a function hash as described in the
272272
[Sophia](https://github.com/aeternity/aesophia/blob/master/docs/sophia.md)
273273
section.
274274

@@ -322,7 +322,7 @@ After Iris, version 2:
322322
-------------- -----
323323
```
324324

325-
For the actual wire format please consult the [serialisation](../serializations.md) document.
325+
For the actual wire format please consult the [serialization](../serializations.md) document.
326326

327327
The semantics of this transaction are similar to the [Call Contract Transaction](../contracts/contract_transactions.md#contract-call-transaction).
328328

@@ -341,6 +341,11 @@ used instead.
341341
The `tx`, or inner transaction, MUST be a well formed transaction with nonce set
342342
to `0`. The `tx` MUST NOT be a `ga_attach_tx` transaction.
343343

344+
The `authorization` function is executed in a special FATE environment where
345+
`Auth.tx_hash` and `Auth.tx` are available. These can (and should!) be used to
346+
securely authorize a transaction. Note: `Auth.tx_hash` computation differs
347+
between protocol versions, see [serialization](../serializations.md)
348+
specification for details.
344349

345350
## Backwards compatibility
346351

@@ -352,7 +357,7 @@ without problems.
352357

353358
### Threat model/attack vectors
354359

355-
Special care needs to be taken when writing contracts, that handle authorisation
360+
Special care needs to be taken when writing contracts, that handle authorization
356361
logic for a GA. If the contract does not enforce integrity checking or replay
357362
protection, then it will be vulnerable to abuse.
358363

serializations.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ authorization data.
10721072

10731073
#### Generalized accounts meta transaction
10741074

1075-
##### Meta transaction version 1, pre Iris
1075+
##### Meta transaction version 1, pre Iris
10761076

10771077
```
10781078
[ <ga_id> :: id()
@@ -1086,7 +1086,7 @@ authorization data.
10861086
]
10871087
```
10881088

1089-
##### Meta transaction version 2, from Iris on
1089+
##### Meta transaction version 2, from Iris on
10901090

10911091
```
10921092
[ <ga_id> :: id()
@@ -1099,6 +1099,33 @@ authorization data.
10991099
]
11001100
```
11011101

1102+
##### Auth.tx\_hash, pre Ceres
1103+
1104+
The Blake2b hash of:
1105+
```
1106+
[ <fee> :: int()
1107+
, <gas_price> :: int()
1108+
, <tx_hash> :: binary()
1109+
]
1110+
```
1111+
1112+
Where `tx_hash` is the hash of the inner transaction.
1113+
1114+
##### Auth.tx\_hash, from Ceres on
1115+
1116+
The Blake2b hash of:
1117+
1118+
```
1119+
[ <fee> :: int()
1120+
, <gas_price> :: int()
1121+
, <tx_hash> :: binary()
1122+
]
1123+
```
1124+
1125+
Where `tx_hash` is the hash of the inner transaction. The change ensure that a
1126+
rouge miner can not tamper with the `fee` or the `gas_price`.
1127+
1128+
11021129
### PayingFor
11031130
The `PayingFor` transaction is available from version 5, Iris release. By using
11041131
it, an account `P` can pay for the transaction (transaction fee + gas) of another

0 commit comments

Comments
 (0)