oasisprotocol / oasis-web3-gateway

Web3 Gateway for the Oasis SDK EVM ParaTime module.
GNU General Public License v3.0
27 stars 14 forks source link

Non-standard empty response for eth_getStorageAt? #595

Open lukaw3d opened 3 months ago

lukaw3d commented 3 months ago

Copied from slack before it's lost

Luka:

do our JSON RPCs return nonstandard empty responses? (I had to change detectUsingEIP1967LogicSlot in abi-playground https://github.com/oasisprotocol/abi-playground/commit/e9646c5cc0001ddcbdb66be0162b090fa2ec18f9)

curl 'https://eth-mainnet.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' \
  -H 'content-type: application/json' \
  --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
# {"jsonrpc":"2.0","id":4,"result":"0x0000000000000000000000000000000000000000000000000000000000000000"}

# vs ours
curl 'https://sapphire.oasis.io/' \
  -H 'content-type: application/json' \
  --data-raw '{"jsonrpc":"2.0","id":1,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
# {"jsonrpc":"2.0","id":1,"result":"0x0"}

curl 'https://emerald.oasis.io/' \
  -H 'content-type: application/json' \
  --data-raw '{"jsonrpc":"2.0","id":1,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
# {"jsonrpc":"2.0","id":1,"result":"0x0"}

Peter:

should be an easy fix But apparently some app in the past did not expect leading zeroes (https://github.com/oasisprotocol/oasis-web3-gateway/blob/b8072325e4b3c4a6411bb87222dc1e574d4c0b71/rpc/eth/api.go#L251). But I have no idea what I tested this with at that time. Can change if it thats nonstandard

Luka:

(btw I don't know if there is a standard for it, or how tools other than abi.ninja check it) This might be the closest to defining the API https://github.com/ethereum/execution-apis/blob/main/tests/eth_getStorageAt/get-storage-unknown-account.io blockscout is forgiving https://github.com/oasisprotocol/emerald-blockscout/blob/oasis-v4.1.2-beta/apps/explorer/lib/explorer/chain.ex#L6800 when empty_address in ["0x", "0x0", "0x0000000000000000000000000000000000000000000000000000000000000000"] these all return 0x0000000000000000000000000000000000000000000000000000000000000000:

curl 'https://opt-mainnet.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://arb-mainnet.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://polygon-mainnet.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://polygonzkevm-mainnet.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://astar-mainnet.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://starknet-mainnet.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://eth-sepolia.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://base-sepolia.g.alchemy.com/v2/upUGXHgfmYdHJlxmsq5INODNexAwPVdD' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://bsc-dataseed1.defibit.io/' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://avalanche.public-rpc.com/' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
curl 'https://nova.arbitrum.io/rpc' -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","id":4,"method":"eth_getStorageAt","params":["0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3","0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc","latest"]}'
lukaw3d commented 3 months ago

From discord: ethers v5 provider.getStorageAt throws

Error: bad result from backend (
  method="getStorageAt",
  params={"address":"0x52Dcf311dc34Ac9373a4A4cfF37A3292487F273D","blockTag":"latest","position":"0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103"},
  result="0x0",
  error={"reason":"hex data is odd-length","code":"INVALID_ARGUMENT","argument":"value","value":"0x0"},
  code=SERVER_ERROR,
  version=providers/5.7.2
)
<script type="module">
import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.2/ethers.esm.js";
const provider = new ethers.providers.Web3Provider(window.ethereum)
console.log(await provider.getStorageAt(
  "0x52Dcf311dc34Ac9373a4A4cfF37A3292487F273D",
  "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103",
  "latest",
))
</script>

https://github.com/ethers-io/ethers.js/blob/d7e8ad1da5ae554739ba93bc4980c3ec25c43c91/packages/providers/src.ts/base-provider.ts#L1505-L1510

https://github.com/ethers-io/ethers.js/blob/d7e8ad1da5ae554739ba93bc4980c3ec25c43c91/packages/bytes/src.ts/index.ts#L237

lukaw3d commented 3 months ago

Ethers v6 throws

TypeError: invalid BytesLike value (
  argument="value",
  value="0x0",
  code=INVALID_ARGUMENT,
  version=6.13.2
)
<script type="module">
import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/6.13.2/ethers.js";
const provider6 = new ethers.BrowserProvider(window.ethereum)
console.log(await provider6.getStorage(
  "0x52Dcf311dc34Ac9373a4A4cfF37A3292487F273D",
  "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103",
  "latest",
))
</script>

https://github.com/ethers-io/ethers.js/blob/72c2182d01afa855d131e82635dca3da063cfb31/src.ts/utils/data.ts#L44

lukaw3d commented 3 months ago

Related https://github.com/ethers-io/ethers.js/issues/1132