From bbda2e47896886cccf3fcf1708d7f79b59bc1224 Mon Sep 17 00:00:00 2001 From: rodrigoherrerai Date: Fri, 5 Apr 2024 19:25:43 -0600 Subject: [PATCH 1/4] modify rpcStataManager getAccount --- packages/statemanager/src/rpcStateManager.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/statemanager/src/rpcStateManager.ts b/packages/statemanager/src/rpcStateManager.ts index 885fa5168b..54082049d6 100644 --- a/packages/statemanager/src/rpcStateManager.ts +++ b/packages/statemanager/src/rpcStateManager.ts @@ -252,10 +252,8 @@ export class RPCStateManager implements EVMStateManagerInterface { } /** - * Gets the code corresponding to the provided `address`. - * @param address - Address to get the `account` for - * @returns {Promise} - Resolves with the code corresponding to the provided address. - * Returns an empty `Uint8Array` if the account has no associated code. + * Gets the account associated with `address` or `undefined` if account does not exist + * @param address - Address of the `account` to get */ async getAccount(address: Address): Promise { const elem = this._accountCache?.get(address) @@ -265,11 +263,14 @@ export class RPCStateManager implements EVMStateManagerInterface { : undefined } - const rlp = (await this.getAccountFromProvider(address)).serialize() - const account = - equalsBytes(rlp, KECCAK256_RLP_EMPTY_ACCOUNT) === false - ? Account.fromRlpSerializedAccount(rlp) - : undefined + let account = await this.getAccountFromProvider(address) + + if (account.codeHash.every((e:any)=> e === 0) || equalsBytes(account.serialize(), KECCAK256_RLP_EMPTY_ACCOUNT)) { + account = undefined + } else { + account = Account.fromRlpSerializedAccount(account.serialize()) + } + this._accountCache?.put(address, account) return account From 608830deaef63e93f6cb1a6ef588d2b6b8e4afd8 Mon Sep 17 00:00:00 2001 From: rodrigoherrerai Date: Fri, 5 Apr 2024 21:11:52 -0600 Subject: [PATCH 2/4] fix type error --- packages/statemanager/src/rpcStateManager.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/statemanager/src/rpcStateManager.ts b/packages/statemanager/src/rpcStateManager.ts index 54082049d6..49f36d7373 100644 --- a/packages/statemanager/src/rpcStateManager.ts +++ b/packages/statemanager/src/rpcStateManager.ts @@ -263,13 +263,13 @@ export class RPCStateManager implements EVMStateManagerInterface { : undefined } - let account = await this.getAccountFromProvider(address) + const accountFromProvider = await this.getAccountFromProvider(address) - if (account.codeHash.every((e:any)=> e === 0) || equalsBytes(account.serialize(), KECCAK256_RLP_EMPTY_ACCOUNT)) { - account = undefined - } else { - account = Account.fromRlpSerializedAccount(account.serialize()) - } + const account = + accountFromProvider.codeHash.every((e: any) => e === 0) || + equalsBytes(accountFromProvider.serialize(), KECCAK256_RLP_EMPTY_ACCOUNT) + ? undefined + : Account.fromRlpSerializedAccount(accountFromProvider.serialize()) this._accountCache?.put(address, account) From 4a09aa810f83fb7f857f0fc064b8db1723f92c85 Mon Sep 17 00:00:00 2001 From: acolytec3 <17355484+acolytec3@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:02:01 -0400 Subject: [PATCH 3/4] Update mock provider response for getProof on non-existent account to mirror infura --- .../statemanager/test/testdata/providerData/mockProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/statemanager/test/testdata/providerData/mockProvider.ts b/packages/statemanager/test/testdata/providerData/mockProvider.ts index 7683c9a6b9..4e56e4d128 100644 --- a/packages/statemanager/test/testdata/providerData/mockProvider.ts +++ b/packages/statemanager/test/testdata/providerData/mockProvider.ts @@ -68,9 +68,9 @@ const getProofValues = async (params: [address: string, _: [], blockTag: bigint return { address, balance: '0x0', - codeHash: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', + codeHash: '0x0000000000000000000000000000000000000000000000000000000000000000', nonce: '0x0', - storageHash: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', + storageHash: '0x0000000000000000000000000000000000000000000000000000000000000000', storageProof: [], } } From fab52c9eb345d04316ae6269219f5edbe4131115 Mon Sep 17 00:00:00 2001 From: acolytec3 <17355484+acolytec3@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:05:56 -0400 Subject: [PATCH 4/4] Update nonexistent account check to compare bytes --- packages/statemanager/src/rpcStateManager.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/statemanager/src/rpcStateManager.ts b/packages/statemanager/src/rpcStateManager.ts index 49f36d7373..f1a8298b66 100644 --- a/packages/statemanager/src/rpcStateManager.ts +++ b/packages/statemanager/src/rpcStateManager.ts @@ -264,9 +264,8 @@ export class RPCStateManager implements EVMStateManagerInterface { } const accountFromProvider = await this.getAccountFromProvider(address) - const account = - accountFromProvider.codeHash.every((e: any) => e === 0) || + equalsBytes(accountFromProvider.codeHash, new Uint8Array(32).fill(0)) || equalsBytes(accountFromProvider.serialize(), KECCAK256_RLP_EMPTY_ACCOUNT) ? undefined : Account.fromRlpSerializedAccount(accountFromProvider.serialize())