From dbe2f717eb62988df82e5dcf4dd161ff13d0fda5 Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 5 Nov 2024 18:31:59 +0100 Subject: [PATCH] allow eip 7702 delegation prefix in is-contract check (fix #308) --- src/eth/EthWalletManager.ts | 2 +- tests/modules/EthInfoModule.spec.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/eth/EthWalletManager.ts b/src/eth/EthWalletManager.ts index a23ab898b..e5d435efd 100644 --- a/src/eth/EthWalletManager.ts +++ b/src/eth/EthWalletManager.ts @@ -280,7 +280,7 @@ export class EthWalletManager { } public checkIsContract(addr: string): Promise { - return this.web3.eth.getCode(addr).then((res) => res && !!res.match(/^0x[0-9a-f]{2,}$/)); + return this.web3.eth.getCode(addr).then((res) => res && !!res.match(/^0x[0-9a-f]{2,}$/) && !res.match(/^0xef0100/)); } public getFaucetBalance(native?: boolean): bigint | null { diff --git a/tests/modules/EthInfoModule.spec.ts b/tests/modules/EthInfoModule.spec.ts index bb38c5828..3b813ab52 100644 --- a/tests/modules/EthInfoModule.spec.ts +++ b/tests/modules/EthInfoModule.spec.ts @@ -105,4 +105,26 @@ describe("Faucet module: ethinfo", () => { expect(error?.getCode()).to.equal("CONTRACT_ADDR", "unexpected error code"); }); + it("Start session for wallet with eip7702 delegation", async () => { + faucetConfig.modules["ethinfo"] = { + enabled: true, + maxBalance: 1000, + denyContract: true, + } as IEthInfoConfig; + fakeProvider.injectResponse("eth_getBalance", "1000"); + fakeProvider.injectResponse("eth_getCode", "0xef010012345678"); + await ServiceManager.GetService(ModuleManager).initialize(); + let sessionManager = ServiceManager.GetService(SessionManager); + let testSession = await sessionManager.createSession("::ffff:8.8.8.8", { + addr: "0x0000000000000000000000000000000000001337", + }); + expect(testSession.getSessionStatus()).to.equal("claimable", "unexpected session status"); + let balanceReq = fakeProvider.getLastRequest("eth_getBalance"); + expect(balanceReq).to.not.equal(null, "no eth_getBalance request"); + expect(balanceReq.params[0]).to.equal("0x0000000000000000000000000000000000001337", "unexpected target address in eth_getBalance request"); + let codeReq = fakeProvider.getLastRequest("eth_getCode"); + expect(codeReq).to.not.equal(null, "no eth_getCode request"); + expect(codeReq.params[0]).to.equal("0x0000000000000000000000000000000000001337", "unexpected target address in eth_getCode request"); + }); + }); \ No newline at end of file