From 28461edbe3e2b280cf11665aff5ce34e59299765 Mon Sep 17 00:00:00 2001 From: iamacook Date: Thu, 13 Apr 2023 10:38:08 +0200 Subject: [PATCH 1/4] fix: check simulation call trace for reversion --- .../tx/TxSimulation/SimulationResult.tsx | 16 +++++++++++++++- src/components/tx/TxSimulation/types.ts | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/tx/TxSimulation/SimulationResult.tsx b/src/components/tx/TxSimulation/SimulationResult.tsx index f4cbd8a0da..a5735775ad 100644 --- a/src/components/tx/TxSimulation/SimulationResult.tsx +++ b/src/components/tx/TxSimulation/SimulationResult.tsx @@ -15,6 +15,20 @@ type SimulationResultProps = { onClose: () => void } +const didRevert = (simulation: TenderlySimulation): boolean => { + if (!simulation.simulation.status) { + return true + } + + // Safe emits `ExecutionFailure` when the gas/safeTxGas is too low + // but the Tenderly simulation can still succeed + const callErrors = simulation.transaction.call_trace.filter((call) => { + return call.error + }) + + return callErrors.length > 0 +} + export const SimulationResult = ({ simulationRequestStatus, simulation, @@ -31,7 +45,7 @@ export const SimulationResult = ({ } // Error - if (requestError || !simulation?.simulation.status) { + if (requestError || !simulation || didRevert(simulation)) { return ( diff --git a/src/components/tx/TxSimulation/types.ts b/src/components/tx/TxSimulation/types.ts index 8ea3446a11..a15dedfb6b 100644 --- a/src/components/tx/TxSimulation/types.ts +++ b/src/components/tx/TxSimulation/types.ts @@ -256,6 +256,11 @@ interface Transaction { timestamp: Date method: string decoded_input: null + // Note: manually added (partial keys of `call_trace`) + call_trace: Array<{ + error?: string + input: string + }> } interface TransactionInfo { From 6274755e61b02e3d46619fe6203bc7530bf40b68 Mon Sep 17 00:00:00 2001 From: iamacook Date: Thu, 13 Apr 2023 11:29:54 +0200 Subject: [PATCH 2/4] fix: adjust error message for call trace --- .../tx/TxSimulation/SimulationResult.tsx | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/components/tx/TxSimulation/SimulationResult.tsx b/src/components/tx/TxSimulation/SimulationResult.tsx index a5735775ad..4283056e7f 100644 --- a/src/components/tx/TxSimulation/SimulationResult.tsx +++ b/src/components/tx/TxSimulation/SimulationResult.tsx @@ -15,18 +15,12 @@ type SimulationResultProps = { onClose: () => void } -const didRevert = (simulation: TenderlySimulation): boolean => { - if (!simulation.simulation.status) { - return true +const getCallTraceErrors = (simulation?: TenderlySimulation) => { + if (!simulation) { + return [] } - // Safe emits `ExecutionFailure` when the gas/safeTxGas is too low - // but the Tenderly simulation can still succeed - const callErrors = simulation.transaction.call_trace.filter((call) => { - return call.error - }) - - return callErrors.length > 0 + return simulation.transaction.call_trace.filter((call) => call.error) } export const SimulationResult = ({ @@ -44,8 +38,14 @@ export const SimulationResult = ({ return null } + const callTraceErrors = getCallTraceErrors(simulation) + const isCallTraceError = callTraceErrors.length > 0 + + // Safe can emit `ExecutionFailure` even though Tenderly simulation succeeds + const didRevert = !simulation || !simulation.simulation.status || isCallTraceError + // Error - if (requestError || !simulation || didRevert(simulation)) { + if (requestError || didRevert) { return ( @@ -58,8 +58,18 @@ export const SimulationResult = ({ ) : ( - The transaction failed during the simulation throwing error {simulation?.transaction.error_message}{' '} - in the contract at {simulation?.transaction.error_info?.address}. Full simulation report is available{' '} + The transaction failed during the simulation{' '} + {isCallTraceError ? ( + <> + with error {callTraceErrors[0].error}. + + ) : ( + <> + throwing error {simulation?.transaction.error_message} in the contract at{' '} + {simulation?.transaction.error_info?.address}. + + )}{' '} + Full simulation report is available on Tenderly. )} From 114b1a41f4c2319efb939476f55af4386a5e68c8 Mon Sep 17 00:00:00 2001 From: iamacook Date: Thu, 13 Apr 2023 11:43:03 +0200 Subject: [PATCH 3/4] fix: error message priority --- src/components/tx/TxSimulation/SimulationResult.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/tx/TxSimulation/SimulationResult.tsx b/src/components/tx/TxSimulation/SimulationResult.tsx index 4283056e7f..6010d6f64c 100644 --- a/src/components/tx/TxSimulation/SimulationResult.tsx +++ b/src/components/tx/TxSimulation/SimulationResult.tsx @@ -38,14 +38,14 @@ export const SimulationResult = ({ return null } - const callTraceErrors = getCallTraceErrors(simulation) - const isCallTraceError = callTraceErrors.length > 0 + const isSuccess = !simulation?.simulation.status + const callTraceErrors = getCallTraceErrors(simulation) // Safe can emit `ExecutionFailure` even though Tenderly simulation succeeds - const didRevert = !simulation || !simulation.simulation.status || isCallTraceError + const isCallTraceError = !isSuccess && callTraceErrors.length > 0 // Error - if (requestError || didRevert) { + if (requestError || !isSuccess || isCallTraceError) { return ( From d82f1e6db8a3e09c249d04d65ec7b85df5d1073f Mon Sep 17 00:00:00 2001 From: iamacook Date: Thu, 13 Apr 2023 13:04:16 +0200 Subject: [PATCH 4/4] fix: generalise error --- .../tx/TxSimulation/SimulationResult.tsx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/components/tx/TxSimulation/SimulationResult.tsx b/src/components/tx/TxSimulation/SimulationResult.tsx index 6010d6f64c..f4bd9ec4ff 100644 --- a/src/components/tx/TxSimulation/SimulationResult.tsx +++ b/src/components/tx/TxSimulation/SimulationResult.tsx @@ -38,11 +38,10 @@ export const SimulationResult = ({ return null } - const isSuccess = !simulation?.simulation.status + const isSuccess = simulation?.simulation.status - const callTraceErrors = getCallTraceErrors(simulation) - // Safe can emit `ExecutionFailure` even though Tenderly simulation succeeds - const isCallTraceError = !isSuccess && callTraceErrors.length > 0 + // Safe can emit failure event even though Tenderly simulation succeeds + const isCallTraceError = isSuccess && getCallTraceErrors(simulation).length > 0 // Error if (requestError || !isSuccess || isCallTraceError) { @@ -58,19 +57,16 @@ export const SimulationResult = ({ ) : ( - The transaction failed during the simulation{' '} {isCallTraceError ? ( - <> - with error {callTraceErrors[0].error}. - + <>The transaction failed during the simulation. ) : ( <> - throwing error {simulation?.transaction.error_message} in the contract at{' '} + The transaction failed during the simulation throwing error{' '} + {simulation?.transaction.error_message} in the contract at{' '} {simulation?.transaction.error_info?.address}. )}{' '} - Full simulation report is available - on Tenderly. + Full simulation report is available on Tenderly. )}