Skip to content

Commit 9ececec

Browse files
vm: fix state tests for EIP2930
vm/tx/block: add changelog tx: add some docs tx: check s value OK, make json-tx geth compatible common: remove empty test vm: remove unnecesary comment
1 parent 4a7a547 commit 9ececec

File tree

10 files changed

+59
-18
lines changed

10 files changed

+59
-18
lines changed

packages/block/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
(modification: no type change headlines) and this project adheres to
77
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

9+
## UNRELEASED
10+
11+
- Integration of [EIP2718](https://eips.ethereum.org/EIPS/eip-2718) (Typed Transactions) and [EIP2930](https://eips.ethereum.org/EIPS/eip-2930) (Access List Transaction), PR [#1048](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1048). It is now possible to create blocks with access list transactions.
12+
913
## 3.1.0 - 2021-02-22
1014

1115
### Clique/PoA Support

packages/common/tests/eips.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,4 @@ tape('[Common]: Initialization / Chain params', function (t: tape.Test) {
5757

5858
st.end()
5959
})
60-
61-
t.test('Initialization', function (st: tape.Test) {
62-
st.end()
63-
})
6460
})

packages/tx/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
(modification: no type change headlines) and this project adheres to
77
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

9+
## UNRELEASED
10+
11+
- Integration of [EIP2718](https://eips.ethereum.org/EIPS/eip-2718) (Typed Transactions) and [EIP2930](https://eips.ethereum.org/EIPS/eip-2930) (Access List Transaction), PR [#1048](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1048).
12+
13+
This PR integrates the Typed Transactions. In order to produce the right transactions, there is a new class called the `TransactionFactory`. This factory helps to create the correct transaction. When decoding directly from blocks, use the `fromBlockBodyData` method. The PR also refactors the internals of the legacy transaction and the new typed transaction: there is a base transaction class, which both transaction classes extends. It is also possible to import `EIP2930Transaction` (an access list transaction).
14+
15+
### How to migrate
16+
17+
The old `Transaction` class has been renamed to `LegacyTransaction`. This class works just how it used to work.
18+
919

1020
## 3.0.2 - 2021-02-16
1121

packages/tx/src/baseTransaction.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ export abstract class BaseTransaction<TransactionObject> {
160160
}
161161
}
162162

163-
// In case of a LegacyTransaction, this is a Buffer[]
164-
// For a TypedTransaction, this is a Buffer
163+
/**
164+
* Returns the raw `Buffer[]` (LegacyTransaction) or `Buffer` (typed transaction).
165+
* This is the data which is found in the transactions of the block body.
166+
*/
165167
abstract raw(): Buffer[] | Buffer
166168
abstract hash(): Buffer
167169

packages/tx/src/eip2930Transaction.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ecrecover,
88
keccak256,
99
rlp,
10+
setLengthLeft,
1011
toBuffer,
1112
} from 'ethereumjs-util'
1213
import { BaseTransaction } from './baseTransaction'
@@ -183,7 +184,11 @@ export default class EIP2930Transaction extends BaseTransaction<EIP2930Transacti
183184
throw new Error('The y-parity of the transaction should either be 0 or 1')
184185
}
185186

186-
// todo verify max BN of r,s
187+
if (this.common.gteHardfork('homestead') && this.s && this.s.gt(N_DIV_2)) {
188+
throw new Error(
189+
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
190+
)
191+
}
187192

188193
// Verify the access list format.
189194
for (let key = 0; key < this.accessList.length; key++) {
@@ -247,8 +252,8 @@ export default class EIP2930Transaction extends BaseTransaction<EIP2930Transacti
247252

248253
/**
249254
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
250-
* TODO: check what raw means - is this the raw transaction as in block body?
251-
* If that is the case, it is only callable if it is signed.
255+
* @param asList - By default, this method returns a concatenated Buffer
256+
* If this is not desired, then set this to `true`, to get a Buffer array.
252257
*/
253258
raw(asList = false): Buffer[] | Buffer {
254259
const base = <Buffer[]>[
@@ -272,7 +277,8 @@ export default class EIP2930Transaction extends BaseTransaction<EIP2930Transacti
272277
}
273278

274279
/**
275-
* Returns the rlp encoding of the transaction.
280+
* Returns the encoding of the transaction. For typed transaction, this is the raw Buffer.
281+
* In LegacyTransaction, this is a Buffer array.
276282
*/
277283
serialize(): Buffer {
278284
return <Buffer>this.raw()
@@ -282,18 +288,19 @@ export default class EIP2930Transaction extends BaseTransaction<EIP2930Transacti
282288
* Returns an object with the JSON representation of the transaction
283289
*/
284290
toJSON(): JsonTx {
285-
// TODO: fix type
286291
const accessListJSON = []
292+
287293
for (let index = 0; index < this.accessList.length; index++) {
288294
const item: any = this.accessList[index]
289-
const JSONItem: any = ['0x' + (<Buffer>item[0]).toString('hex')]
295+
const JSONItem: any = {
296+
address: '0x' + setLengthLeft(<Buffer>item[0], 20).toString('hex'),
297+
storageKeys: [],
298+
}
290299
const storageSlots: Buffer[] = item[1]
291-
const JSONSlots = []
292300
for (let slot = 0; slot < storageSlots.length; slot++) {
293301
const storageSlot = storageSlots[slot]
294-
JSONSlots.push('0x' + storageSlot.toString('hex'))
302+
JSONItem.storageKeys.push('0x' + setLengthLeft(storageSlot, 32).toString('hex'))
295303
}
296-
JSONItem.push(JSONSlots)
297304
accessListJSON.push(JSONItem)
298305
}
299306

packages/tx/src/transactionFactory.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export default class TransactionFactory {
1010
// It is not possible to instantiate a TransactionFactory object.
1111
private constructor() {}
1212

13+
/**
14+
* Create a transaction from a `txData` object
15+
* @param txData - The transaction data. The `type` field will determine which transaction type is returned (if undefined, create a LegacyTransaction)
16+
* @param txOptions - Options to pass on to the constructor of the transaction
17+
*/
1318
public static fromTxData(txData: TxData, txOptions: TxOptions = {}): Transaction {
1419
const common = txOptions.common ?? DEFAULT_COMMON
1520
if (txData.type === undefined) {
@@ -107,6 +112,11 @@ export default class TransactionFactory {
107112
throw new Error(`TypedTransaction with ID ${transactionID} unknown`)
108113
}
109114

115+
/**
116+
* Check if a typed transaction eip is supported by common
117+
* @param common - The common to use
118+
* @param eip - The EIP to check
119+
*/
110120
public static eipSupport(common: Common, eip: number): boolean {
111121
if (!common.isActivatedEIP(2718)) {
112122
return false

packages/tx/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ export type BaseTransactionData = {
165165
data?: BufferLike
166166
}
167167

168+
type JsonAccessListItem = { address: string; storageKeys: string[] }
169+
168170
/**
169171
* An object with all of the transaction's values represented as strings.
170172
*/
@@ -179,7 +181,7 @@ export interface JsonTx {
179181
s?: string
180182
value?: string
181183
chainId?: string
182-
accessList?: string[]
184+
accessList?: JsonAccessListItem[]
183185
type?: string
184186
}
185187

packages/vm/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
(modification: no type change headlines) and this project adheres to
77
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

9+
## UNRELEASED
10+
11+
- Fixes for [EIP2929](https://eips.ethereum.org/EIPS/eip-2929) (Gas cost increases for state access opcodes), PR [#1124](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1124)
12+
- Integration of [EIP2718](https://eips.ethereum.org/EIPS/eip-2718) (Typed Transactions) and [EIP2930](https://eips.ethereum.org/EIPS/eip-2930) (Access List Transaction), PR [#1048](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1048). VM now has support for access list transactions.
13+
914
### 5.1.0 - 2021-02-22
1015

1116
### Clique/PoA Support

packages/vm/lib/runBlock.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ async function applyTransactions(this: VM, block: Block, opts: RunBlockOpts) {
360360
...abstractTxReceipt,
361361
} as EIP2930Receipt
362362

363-
// rlp([status, cumulativeGasUsed, logsBloom, logs])
364-
365363
encodedReceipt = Buffer.concat([Buffer.from('01', 'hex'), encode(Object.values(txReceipt))])
366364
} else {
367365
throw new Error(`Unsupported transaction type ${tx.transactionType}`)

packages/vm/tests/GeneralStateTestsRunner.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ function parseTestCases(
3434
tx.gasLimit = testData.transaction.gasLimit[testIndexes['gas']]
3535
tx.value = testData.transaction.value[testIndexes['value']]
3636

37+
if (tx.accessLists) {
38+
tx.accessList = testData.transaction.accessLists[testIndexes['data']]
39+
if (tx.chainId == undefined) {
40+
tx.chainId = 1
41+
}
42+
}
43+
3744
return {
3845
transaction: tx,
3946
postStateRoot: testCase['hash'],

0 commit comments

Comments
 (0)