Skip to content

Commit

Permalink
fix: getSignInput bug for zero maxPriorityFeePerGas
Browse files Browse the repository at this point in the history
Explicit zero value should not fallback to maxFeePerGas
  • Loading branch information
everdimension committed Dec 18, 2024
1 parent 6476368 commit 3952b49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class EIP712Signer {
static getSignInput(transaction: TransactionRequest) {
const maxFeePerGas = transaction.maxFeePerGas || transaction.gasPrice || 0n;
const maxPriorityFeePerGas =
transaction.maxPriorityFeePerGas || maxFeePerGas;
transaction.maxPriorityFeePerGas ?? maxFeePerGas;
const gasPerPubdataByteLimit =
transaction.customData?.gasPerPubdata || DEFAULT_GAS_PER_PUBDATA_LIMIT;
return {
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,35 @@ describe('EIP712Signer', () => {
});
expect(result).to.be.deep.equal(tx);
});

it('should correcly handle zero values', async () => {
const tx = {
txType: utils.EIP712_TX_TYPE,
from: ADDRESS1,
to: ADDRESS2,
gasLimit: 0n,
gasPerPubdataByteLimit: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
maxFeePerGas: 250_000_000n,
maxPriorityFeePerGas: 0n,
paymaster: ethers.ZeroAddress,
nonce: 0,
value: 0n,
data: '0x',
factoryDeps: [],
paymasterInput: '0x',
};

const result = EIP712Signer.getSignInput({
type: utils.EIP712_TX_TYPE,
to: ADDRESS2,
from: ADDRESS1,
maxFeePerGas: 250_000_000n,
maxPriorityFeePerGas: 0n,
});
expect(result).to.be.deep.equal(tx);
});
});
});

describe('#getSignedDigest()', () => {
it('should throw an error when chain ID is not specified', async () => {
Expand Down

0 comments on commit 3952b49

Please sign in to comment.