Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix provider encoding #358

Merged
merged 4 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/provider",
"version": "0.0.1-alpha.9",
"version": "0.0.1-alpha.11",
"description": "Web3 provider for Optimism",
"main": "build/index.js",
"files": [
Expand All @@ -23,6 +23,7 @@
"license": "MIT",
"dependencies": {
"@eth-optimism/core-utils": "0.0.1-alpha.30",
"@ethersproject/abi": "^5.0.7",
"@ethersproject/abstract-provider": "^5.0.3",
"@ethersproject/abstract-signer": "^5.0.3",
"@ethersproject/bignumber": "^5.0.6",
Expand Down
28 changes: 14 additions & 14 deletions packages/provider/src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Networkish } from '@ethersproject/networks'
import { hexStrToBuf, isHexString, remove0x } from '@eth-optimism/core-utils'
import { arrayify, Bytes, zeroPad } from '@ethersproject/bytes'
import { BigNumberish, BigNumber } from '@ethersproject/bignumber'
import { AbiCoder } from '@ethersproject/abi'
import { Deferrable, deepCopy } from '@ethersproject/properties'
import { TransactionRequest } from '@ethersproject/abstract-provider'
import { keccak256 } from '@ethersproject/keccak256'
Expand Down Expand Up @@ -76,21 +77,20 @@ export const allowedTransactionKeys: { [key: string]: boolean } = {
}

export function serializeEthSignTransaction(transaction): Bytes {
const nonce = zeroPad(transaction.nonce, 32)
const gasLimit = zeroPad(transaction.gasLimit, 32)
const gasPrice = zeroPad(transaction.gasPrice, 32)
const chainId = zeroPad(transaction.chainId, 32)
const to = hexStrToBuf(transaction.to)
const data = toBuffer(transaction.data)
const abi = new AbiCoder()
const encoded = abi.encode(
['uint256', 'uint256', 'uint256', 'uint256', 'address', 'bytes'],
[
transaction.nonce,
transaction.gasLimit,
transaction.gasPrice,
transaction.chainId,
transaction.to,
transaction.data,
]
)

return Buffer.concat([
Buffer.from(nonce),
Buffer.from(gasLimit),
Buffer.from(gasPrice),
Buffer.from(chainId),
to,
data,
])
return Buffer.from(encoded.slice(2), 'hex')
}

// Use this function as input to `eth_sign`. It does not
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
"@ethersproject/properties" "^5.0.3"
"@ethersproject/strings" "^5.0.4"

"@ethersproject/abi@5.0.7", "@ethersproject/abi@^5.0.5":
"@ethersproject/abi@5.0.7", "@ethersproject/abi@^5.0.5", "@ethersproject/abi@^5.0.7":
version "5.0.7"
resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.0.7.tgz#79e52452bd3ca2956d0e1c964207a58ad1a0ee7b"
integrity sha512-Cqktk+hSIckwP/W8O47Eef60VwmoSC/L3lY0+dIBhQPCNn9E4V7rwmm2aFrNRRDJfFlGuZ1khkQUOc3oBX+niw==
Expand Down