diff --git a/package-lock.json b/package-lock.json index ce6242e..d926b54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@ethereumjs/util": "^9.0.3", "@google-cloud/kms": "^4.2.0", "asn1js": "^3.0.5", - "axios": "^1.6.8", + "axios": "^1.7.4", "bn.js": "^5.2.1", "ethers": "^6.13.1", "fast-crc32c": "github:ChainSafe/node-fast-crc32c", @@ -879,9 +879,9 @@ } }, "node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/package.json b/package.json index 2a57698..deaa5d8 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@ethereumjs/util": "^9.0.3", "@google-cloud/kms": "^4.2.0", "asn1js": "^3.0.5", - "axios": "^1.6.8", + "axios": "^1.7.4", "bn.js": "^5.2.1", "ethers": "^6.13.1", "fast-crc32c": "github:ChainSafe/node-fast-crc32c", diff --git a/src/server.ts b/src/server.ts index 5f35b65..e5df732 100644 --- a/src/server.ts +++ b/src/server.ts @@ -17,6 +17,8 @@ let PROJECT_ID = process.env.PROJECT_ID! let LOCATION_ID = process.env.LOCATION_ID! let keyRingId = process.env.KEY_RING_ID! let keyId = process.env.KEY_ID! +let TX_GASPRICE_LIMIT = BigInt(process.env.TXPRICE_LIMIT!) +let TX_BLOBPRICE_LIMIT = BigInt(process.env.TX_BLOBPRICE_LIMIT!) kmsProvider.setPath({ projectId: PROJECT_ID, @@ -35,6 +37,15 @@ app.post('/', async (request, reply) => { reply.code(400).send({error: 'Invalid request'}); return; } + + + if (TX_BLOBPRICE_LIMIT > 0 || TX_GASPRICE_LIMIT > 0) { + let areFeesTooHigh = await feesTooHigh(result.data); + if (areFeesTooHigh) { + reply.code(400).send({error: `Fees too high TX_GAS_LIMIT|TX_BLOBPRICE_LIMIT [${TX_GASPRICE_LIMIT} |${TX_BLOBPRICE_LIMIT}] reached`}); + return; + } + } let signedTx = await handleEthSignTransaction(result.data); reply.code(200).send({result: signedTx}); return; @@ -50,6 +61,38 @@ app.get('/address', async (_, reply) => { return reply.code(200).send(address); }) +async function feesTooHigh(transactionArgs: TransactionArgs) { + let maxFeePerGas = BigInt(0); + let maxPriorityFeePerGas = BigInt(0); + let maxFeePerBlobGas = BigInt(0); + + + + if (transactionArgs.maxFeePerGas ){ + maxFeePerGas = BigInt(transactionArgs.maxFeePerGas); + } + if (transactionArgs.maxPriorityFeePerGas) { + maxPriorityFeePerGas = BigInt(transactionArgs.maxPriorityFeePerGas); + } + if (transactionArgs.maxFeePerBlobGas) { + maxFeePerBlobGas = BigInt(transactionArgs.maxFeePerBlobGas); + } + + var gasPrice = (maxFeePerGas + maxPriorityFeePerGas); + if (gasPrice > TX_GASPRICE_LIMIT) { + console.error('Tx fees too high: %d > %d', gasPrice, TX_GASPRICE_LIMIT); + return true; + } + + if (transactionArgs.blobVersionedHashes && transactionArgs.blobVersionedHashes.length > 0) { + if (maxFeePerBlobGas > TX_BLOBPRICE_LIMIT) { + console.error('Blob fees too high: %d > %d', maxFeePerBlobGas, TX_BLOBPRICE_LIMIT ); + return true; + } + } + return false; +} + async function handleEthSignTransaction(transactionArgs: TransactionArgs) { console.log('Transaction Args:', transactionArgs); const kzg = await loadKZG()