Skip to content
Closed
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
4 changes: 2 additions & 2 deletions packages/provider/src/app/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class OptimismProvider extends JsonRpcProvider {

public prepareRequest(method: string, params: any): [string, any[]] {
switch (method) {
case 'sendTransaction':
case 'sendEthSignTransaction':
case 'sendRawEthSignTransaction':
case 'sendRawTransaction':
return ['eth_sendRawEthSignTransaction', [params.signedTransaction]]
}

Expand Down
73 changes: 62 additions & 11 deletions packages/provider/src/app/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
} from '@ethersproject/abstract-provider'
import { Signer } from '@ethersproject/abstract-signer'
import { BigNumberish, BigNumber } from '@ethersproject/bignumber'
import { Bytes, splitSignature } from '@ethersproject/bytes'
import { serialize, UnsignedTransaction } from '@ethersproject/transactions'
import { Bytes, splitSignature, joinSignature, SignatureLike } from '@ethersproject/bytes'
import { serialize, UnsignedTransaction, parse } from '@ethersproject/transactions'
import { hexStrToBuf, isHexString, remove0x } from '@eth-optimism/core-utils'
import { ConnectionInfo, fetchJson, poll } from '@ethersproject/web'
import { keccak256 } from '@ethersproject/keccak256'
Expand All @@ -41,7 +41,6 @@ import {

import {
allowedTransactionKeys,
serializeEthSignTransaction,
sighashEthSign,
} from './utils'

Expand Down Expand Up @@ -148,11 +147,42 @@ export class OptimismSigner implements JsonRpcSigner {
tx.from = sender
}

const hexTx = (this.provider.constructor as any).hexlifyTransaction(tx, {
from: true,
if (typeof tx.gasPrice !== 'undefined' && (tx.gasPrice as BigNumber)._isBigNumber) {
tx.gasPrice = (tx.gasPrice as BigNumber).toNumber()
}
if (typeof tx.gasLimit !== 'undefined' && (tx.gasLimit as BigNumber)._isBigNumber) {
tx.gasLimit = (tx.gasLimit as BigNumber).toNumber()
}
if (typeof tx.value !== 'undefined' && (tx.value as BigNumber)._isBigNumber) {
tx.value = (tx.value as BigNumber).toNumber()
}

const hexTx = (this.provider.constructor as any).hexlifyTransaction({
nonce: tx.nonce,
gasPrice: tx.gasPrice,
gasLimit: tx.gasLimit,
to: tx.to,
data: tx.data,
value: tx.value
})

return this.provider.send('eth_sendTransaction', [hexTx]).then(
// Contract creation
if (tx.to === '0x0000000000000000000000000000000000000000') {
tx.to = undefined
}

const sig = joinSignature(tx as SignatureLike)
const serialized = serialize({
chainId: tx.chainId,
data: hexTx.data,
gasLimit: hexTx.gas,
gasPrice: hexTx.gasPrice,
nonce: hexTx.nonce,
to: hexTx.to,
value: hexTx.value,
}, sig)

return this.provider.send('eth_sendRawEthSignTransaction', [serialized]).then(
(hash) => {
return hash
},
Expand Down Expand Up @@ -201,12 +231,16 @@ export class OptimismSigner implements JsonRpcSigner {
public async signTransaction(
transaction: Deferrable<TransactionRequest>
): Promise<string> {
const hash = sighashEthSign(transaction)
const sig = await this.signer.signMessage(hash)

if (transaction.chainId == null) {
transaction.chainId = await this.getChainId()
}
// If `to` is not specified, assume contract creation.
if (transaction.to == null) {
transaction.to = '0x0000000000000000000000000000000000000000'
}

const hash = sighashEthSign(transaction)
const sig = await this.signMessage(hash)

// Copy over "allowed" properties into new object so that
// `serialize` doesn't throw an error. A "from" property
Expand All @@ -230,8 +264,23 @@ export class OptimismSigner implements JsonRpcSigner {
): Promise<TransactionResponse> {
this._checkProvider('sendTransaction')
const tx = await this.populateTransaction(transaction)
const signed = await this.signTransaction(tx)
return this.provider.sendTransaction(signed)
const hex = await this.signTransaction(tx)

const signed = parse(hex)
signed.from = tx.from

//return this.provider.sendTransaction(tx)
const hash = await this.sendUncheckedTransaction(signed)

return poll(() => {
return this.provider.getTransaction(hash).then((txn: TransactionResponse) => {
if (txn === null) { return undefined; }
return this.provider._wrapTransaction(txn, hash);
});
}, { onceBlock: this.provider }).catch((error: Error) => {
(error as any).transactionHash = hash;
throw error;
});
}

public async signMessage(message: Bytes | string): Promise<string> {
Expand Down Expand Up @@ -386,6 +435,8 @@ export class OptimismSigner implements JsonRpcSigner {
tx.nonce = this.getTransactionCount('pending')
}

// The call to estimate gas is breaking
// Figure out why
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a dead comment, problem was solved

if (tx.gasLimit == null) {
tx.gasLimit = this.estimateGas(tx).catch((error) => {
return logger.throwError(
Expand Down
3 changes: 2 additions & 1 deletion packages/provider/src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ export const allowedTransactionKeys: { [key: string]: boolean } = {
nonce: true,
to: true,
value: true,
from: true,
}

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 to = hexStrToBuf(transaction.to) // this is empty for contract creation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ABI encoding, if to is null, should it commit to 0x00..00 or skip including to in the signature hash entirely?

const data = toBuffer(transaction.data)

return Buffer.concat([
Expand Down
Loading