Skip to content

Commit d4f291c

Browse files
Merge pull request #8459 from BitGo/fix/eip1559-priority-fee-validation
fix(abstract-eth): validate maxPriorityFeePerGas <= maxFeePerGas (CGD-573)
2 parents 34d622e + 0b1de3b commit d4f291c

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ module.exports = {
7575
'ME-',
7676
'ANT-',
7777
'CGARD-',
78+
'CGD-',
7879
'CHALO-',
7980
'CECHO-',
8081
'CSHLD-',

modules/abstract-eth/src/lib/transactionBuilder.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,13 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
539539
this.validateValue(new BigNumber(fee.gasLimit));
540540
}
541541
if (fee.eip1559) {
542-
this.validateValue(new BigNumber(fee.eip1559.maxFeePerGas));
543-
this.validateValue(new BigNumber(fee.eip1559.maxPriorityFeePerGas));
542+
const maxFee = new BigNumber(fee.eip1559.maxFeePerGas);
543+
const priorityFee = new BigNumber(fee.eip1559.maxPriorityFeePerGas);
544+
this.validateValue(maxFee);
545+
this.validateValue(priorityFee);
546+
if (priorityFee.isGreaterThan(maxFee)) {
547+
throw new BuildTransactionError('maxPriorityFeePerGas cannot exceed maxFeePerGas');
548+
}
544549
}
545550
if (fee.gasPrice) {
546551
this.validateValue(new BigNumber(fee.gasPrice));

modules/abstract-eth/test/unit/transactionBuilder/walletInitialization.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,17 @@ export async function testRecoveryTransactionWithoutData(txBuilder: TransactionB
129129
await txBuilder.build().should.be.rejectedWith('Invalid transaction: missing contract call data field');
130130
});
131131
}
132+
133+
export function testEip1559PriorityFeeExceedsMaxFee(txBuilder: TransactionBuilder) {
134+
it('fail when maxPriorityFeePerGas exceeds maxFeePerGas', () => {
135+
(() =>
136+
txBuilder.fee({
137+
eip1559: {
138+
maxFeePerGas: '1000000000',
139+
maxPriorityFeePerGas: '9000000000',
140+
},
141+
fee: '1000000000',
142+
gasLimit: '21000',
143+
})).should.throw('maxPriorityFeePerGas cannot exceed maxFeePerGas');
144+
});
145+
}

modules/sdk-coin-eth/test/unit/transactionBuilder/walletInitialization.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,26 @@ describe('Eth Transaction builder wallet initialization', function () {
301301
should.doesNotThrow(() => txBuilder.fee({ fee: '10' }));
302302
});
303303

304+
it('eip1559 maxPriorityFeePerGas must not exceed maxFeePerGas', () => {
305+
const txBuilder: any = getBuilder('eth');
306+
assert.throws(
307+
() =>
308+
txBuilder.fee({
309+
fee: '1000000000',
310+
gasLimit: '21000',
311+
eip1559: { maxFeePerGas: '1000000000', maxPriorityFeePerGas: '9000000000' },
312+
}),
313+
/maxPriorityFeePerGas cannot exceed maxFeePerGas/
314+
);
315+
should.doesNotThrow(() =>
316+
txBuilder.fee({
317+
fee: '1000000000',
318+
gasLimit: '21000',
319+
eip1559: { maxFeePerGas: '1000000000', maxPriorityFeePerGas: '1000000000' },
320+
})
321+
);
322+
});
323+
304324
it('a private key', () => {
305325
const txBuilder: any = getBuilder('eth');
306326
assert.throws(() => txBuilder.validateKey({ key: 'abc' }), /Invalid key/);

0 commit comments

Comments
 (0)