From b6cc2ee0db02004fadeccdd80d810fd536056d21 Mon Sep 17 00:00:00 2001 From: Ignacio Piris Date: Mon, 17 Mar 2025 20:07:55 -0300 Subject: [PATCH 1/6] replace code on wallet implementation address --- estimator.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/estimator.go b/estimator.go index dad210a1..c9165896 100644 --- a/estimator.go +++ b/estimator.go @@ -603,8 +603,18 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T Data: hexutil.Encode(callData), } + encodedImpAddr, err := provider.ContractQuery(context.Background(), wallet.Hex(), "PROXY_getImplementation()", "address", nil) + if err != nil { + return nil, err + } + if len(encodedImpAddr) == 0 { + return nil, fmt.Errorf("cannot get implementation address of wallet %v", wallet.Hex()) + } + + impAddr := common.HexToAddress(encodedImpAddr[0]) + allOverrides := map[common.Address]*CallOverride{ - wallet: {Code: walletGasEstimatorCodeV2}, + impAddr: {Code: walletGasEstimatorCodeV2}, } for address, override := range overrides { if address == wallet { From 82da1b44c6cb6112499a548daaa6abf2542eb440 Mon Sep 17 00:00:00 2001 From: Ignacio Piris Date: Tue, 18 Mar 2025 00:17:18 -0300 Subject: [PATCH 2/6] fix --- estimator.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/estimator.go b/estimator.go index c9165896..8b093dc0 100644 --- a/estimator.go +++ b/estimator.go @@ -603,18 +603,24 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T Data: hexutil.Encode(callData), } - encodedImpAddr, err := provider.ContractQuery(context.Background(), wallet.Hex(), "PROXY_getImplementation()", "address", nil) + addrToOverride := wallet + + // Get implementation address and override code with walletGasEstimatorCodeV2 + var storageValue string + rpcCall := ethrpc.NewCallBuilder[string]("eth_getStorageAt", nil, wallet.Hex(), common.BytesToHash(common.LeftPadBytes(wallet.Bytes(), 32)).Hex(), block) + _, err = provider.Do(context.Background(), rpcCall.Into(&storageValue)) if err != nil { return nil, err } - if len(encodedImpAddr) == 0 { - return nil, fmt.Errorf("cannot get implementation address of wallet %v", wallet.Hex()) - } - impAddr := common.HexToAddress(encodedImpAddr[0]) + impAddr := common.BytesToAddress(common.FromHex(storageValue)[12:]) + + if impAddr != (common.Address{}) { + addrToOverride = impAddr + } allOverrides := map[common.Address]*CallOverride{ - impAddr: {Code: walletGasEstimatorCodeV2}, + addrToOverride: {Code: walletGasEstimatorCodeV2}, } for address, override := range overrides { if address == wallet { @@ -625,7 +631,7 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T } var response string - rpcCall := ethrpc.NewCallBuilder[string]("eth_call", nil, params, block, allOverrides) + rpcCall = ethrpc.NewCallBuilder[string]("eth_call", nil, params, block, allOverrides) _, err = provider.Do(context.Background(), rpcCall.Into(&response)) if err != nil { return nil, err From d3b4f4c68d4baa5cab6e2c73d58a6f66b0e06eda Mon Sep 17 00:00:00 2001 From: Ignacio Piris Date: Tue, 18 Mar 2025 00:22:24 -0300 Subject: [PATCH 3/6] check implementation address not in overrides --- estimator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/estimator.go b/estimator.go index 8b093dc0..426005f2 100644 --- a/estimator.go +++ b/estimator.go @@ -623,8 +623,8 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T addrToOverride: {Code: walletGasEstimatorCodeV2}, } for address, override := range overrides { - if address == wallet { - return nil, fmt.Errorf("cannot override wallet address %v", wallet.Hex()) + if address == addrToOverride { + return nil, fmt.Errorf("cannot override wallet or implementation address %v", addrToOverride.Hex()) } allOverrides[address] = override From 9f4c4a0703a43316ee0af04e109b6befbc15ad91 Mon Sep 17 00:00:00 2001 From: Ignacio Piris Date: Tue, 18 Mar 2025 00:25:12 -0300 Subject: [PATCH 4/6] fix last added condition --- estimator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/estimator.go b/estimator.go index 426005f2..5de3c4c0 100644 --- a/estimator.go +++ b/estimator.go @@ -623,7 +623,7 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T addrToOverride: {Code: walletGasEstimatorCodeV2}, } for address, override := range overrides { - if address == addrToOverride { + if address == addrToOverride || address == wallet { return nil, fmt.Errorf("cannot override wallet or implementation address %v", addrToOverride.Hex()) } From 53d82c1696f9e178933bad4b864a7411f5904007 Mon Sep 17 00:00:00 2001 From: Ignacio Piris Date: Tue, 18 Mar 2025 00:38:14 -0300 Subject: [PATCH 5/6] last fix --- estimator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/estimator.go b/estimator.go index 5de3c4c0..050600d7 100644 --- a/estimator.go +++ b/estimator.go @@ -623,7 +623,7 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T addrToOverride: {Code: walletGasEstimatorCodeV2}, } for address, override := range overrides { - if address == addrToOverride || address == wallet { + if address == wallet || address == addrToOverride { return nil, fmt.Errorf("cannot override wallet or implementation address %v", addrToOverride.Hex()) } From 7269ee491dfe91483d8570a1d8a1b36c17886821 Mon Sep 17 00:00:00 2001 From: Ignacio Piris Date: Tue, 18 Mar 2025 11:38:44 -0300 Subject: [PATCH 6/6] remove comment --- estimator.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/estimator.go b/estimator.go index 050600d7..4141d1a1 100644 --- a/estimator.go +++ b/estimator.go @@ -605,7 +605,6 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T addrToOverride := wallet - // Get implementation address and override code with walletGasEstimatorCodeV2 var storageValue string rpcCall := ethrpc.NewCallBuilder[string]("eth_getStorageAt", nil, wallet.Hex(), common.BytesToHash(common.LeftPadBytes(wallet.Bytes(), 32)).Hex(), block) _, err = provider.Do(context.Background(), rpcCall.Into(&storageValue)) @@ -623,7 +622,7 @@ func V2Simulate(provider *ethrpc.Provider, wallet common.Address, transactions T addrToOverride: {Code: walletGasEstimatorCodeV2}, } for address, override := range overrides { - if address == wallet || address == addrToOverride { + if address == addrToOverride || address == wallet { return nil, fmt.Errorf("cannot override wallet or implementation address %v", addrToOverride.Hex()) }