@@ -2,43 +2,45 @@ package execution
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"math"
6
7
"math/big"
7
8
8
9
"github.com/ethereum/go-ethereum/accounts/abi/bind"
9
10
"github.com/ethereum/go-ethereum/common"
10
11
"github.com/ethereum/go-ethereum/common/hexutil"
11
12
"github.com/ethereum/go-ethereum/ethclient"
12
- "github.com/ethereum/go-ethereum/rpc"
13
+ ethRpc "github.com/ethereum/go-ethereum/rpc"
13
14
"github.com/stackup-wallet/stackup-bundler/pkg/entrypoint"
15
+ "github.com/stackup-wallet/stackup-bundler/pkg/entrypoint/reverts"
14
16
"github.com/stackup-wallet/stackup-bundler/pkg/entrypoint/utils"
15
17
"github.com/stackup-wallet/stackup-bundler/pkg/errors"
16
18
"github.com/stackup-wallet/stackup-bundler/pkg/tracer"
17
19
"github.com/stackup-wallet/stackup-bundler/pkg/userop"
18
20
)
19
21
20
22
func TraceSimulateHandleOp (
21
- rpc * rpc .Client ,
23
+ rpc * ethRpc .Client ,
22
24
entryPoint common.Address ,
23
25
op * userop.UserOperation ,
24
26
chainID * big.Int ,
25
27
customTracer string ,
26
28
target common.Address ,
27
29
data []byte ,
28
- ) error {
30
+ ) ( * reverts. ExecutionResultRevert , error ) {
29
31
ep , err := entrypoint .NewEntrypoint (entryPoint , ethclient .NewClient (rpc ))
30
32
if err != nil {
31
- return err
33
+ return nil , err
32
34
}
33
35
auth , err := bind .NewKeyedTransactorWithChainID (utils .DummyPk , chainID )
34
36
if err != nil {
35
- return err
37
+ return nil , err
36
38
}
37
39
auth .GasLimit = math .MaxUint64
38
40
auth .NoSend = true
39
41
tx , err := ep .SimulateHandleOp (auth , entrypoint .UserOperation (* op ), target , data )
40
42
if err != nil {
41
- return err
43
+ return nil , err
42
44
}
43
45
44
46
var res tracer.BundlerErrorReturn
@@ -51,24 +53,37 @@ func TraceSimulateHandleOp(
51
53
Tracer : customTracer ,
52
54
}
53
55
if err := rpc .CallContext (context .Background (), & res , "debug_traceCall" , & req , "latest" , & opts ); err != nil {
54
- return err
56
+ return nil , err
57
+ }
58
+ outErr , err := errors .ParseHexToRpcDataError (res .Output )
59
+ if err != nil {
60
+ return nil , err
61
+ }
62
+
63
+ sim , simErr := reverts .NewExecutionResult (outErr )
64
+ if simErr != nil {
65
+ fo , foErr := reverts .NewFailedOp (outErr )
66
+ if foErr != nil {
67
+ return nil , fmt .Errorf ("%s, %s" , simErr , foErr )
68
+ }
69
+ return nil , errors .NewRPCError (errors .REJECTED_BY_EP_OR_ACCOUNT , fo .Reason , fo )
55
70
}
56
71
57
72
if len (res .Reverts ) != 0 {
58
73
data , err := hexutil .Decode (res .Reverts [len (res .Reverts )- 1 ])
59
74
if err != nil {
60
- return err
75
+ return sim , err
61
76
}
62
77
63
78
if len (data ) == 0 {
64
- return errors .NewRPCError (errors .EXECUTION_REVERTED , "execution reverted" , nil )
79
+ return sim , errors .NewRPCError (errors .EXECUTION_REVERTED , "execution reverted" , nil )
65
80
}
66
81
67
82
reason , err := errors .DecodeRevert (data )
68
83
if err != nil {
69
- return err
84
+ return sim , err
70
85
}
71
- return errors .NewRPCError (errors .EXECUTION_REVERTED , reason , reason )
86
+ return sim , errors .NewRPCError (errors .EXECUTION_REVERTED , reason , reason )
72
87
}
73
- return nil
88
+ return sim , nil
74
89
}
0 commit comments