Add protection from abusing relayers (force spending fee for reverted tx): fail if address is invalid or smart-contract (not EOA)

This commit is contained in:
Theo 2023-10-16 16:49:56 -07:00
parent 03c71f28bb
commit 1e99a136cc
2 changed files with 11 additions and 2 deletions

@ -2,7 +2,7 @@ require('dotenv').config()
const tornConfig = require('@tornado/tornado-config')
const { jobType, networkConfig } = require('./constants')
const { networkConfig } = require('./constants')
const netId = Number(process.env.NET_ID) || 56
const instances = tornConfig.instances[netId]

@ -1,5 +1,5 @@
const Web3 = require('web3')
const { toBN, fromWei } = require('web3-utils')
const { toBN, fromWei, isAddress, toChecksumAddress } = require('web3-utils')
const { redis } = require('./modules/redis')
const proxyLightABI = require('../abis/proxyLightABI.json')
const { queue } = require('./queue')
@ -87,6 +87,14 @@ async function getTxObject({ data }) {
return { ...incompleteTx, gasLimit, gasPrice }
}
async function checkRecipient({ data }) {
const recipient = data.args[2]
if (!isAddress(recipient)) throw new Error('Recipient address is invalid')
const addressCode = await web3.eth.getCode(toChecksumAddress(recipient))
if (addressCode !== '0x') throw new Error('Recipient cannot be a smart-contract, only EOA')
}
async function processJob(job) {
try {
if (!jobType[job.data.type]) {
@ -104,6 +112,7 @@ async function processJob(job) {
}
async function submitTx(job) {
await checkRecipient(job)
const tx = await getTxObject(job)
await checkTornadoFee(job, tx)
currentTx = await txManager.createTx(tx)