Commit 6749ab3d authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #1999 from indeavr/develop

Makes sure that the Default sender is address(0)
parents d27e841d 1bc6898a
---
'@eth-optimism/l2geth': patch
---
changed the default address to be address(0) in `call`
module.exports = {
...require('../.prettierrc.js'),
}
../.prettierrc.json
\ No newline at end of file
......@@ -23,6 +23,10 @@ contract ValueContext {
function getCallValue() public payable returns(uint256) {
return msg.value;
}
function getCaller() external view returns (address){
return msg.sender;
}
}
contract ValueCalls is ValueContext {
......
import { expect } from './shared/setup'
import { expectApprox, injectL2Context } from '@eth-optimism/core-utils'
import { Wallet, BigNumber, Contract, ContractFactory } from 'ethers'
import { Wallet, BigNumber, Contract, ContractFactory, constants } from 'ethers'
import { serialize } from '@ethersproject/transactions'
import { ethers } from 'hardhat'
import {
......@@ -233,6 +233,53 @@ describe('Basic RPC tests', () => {
expect(res).to.eq(BigNumber.from(value))
})
// https://github.com/ethereum-optimism/optimism/issues/1998
it('should use address(0) as the default "from" value', async () => {
// Deploy a contract to check msg.caller
const Factory__ValueContext: ContractFactory =
await ethers.getContractFactory('ValueContext', wallet)
const ValueContext: Contract = await Factory__ValueContext.deploy()
await ValueContext.deployTransaction.wait()
// Do the call and check msg.sender
const data = ValueContext.interface.encodeFunctionData('getCaller')
const res = await provider.call({
to: ValueContext.address,
data,
})
const [paddedRes] = ValueContext.interface.decodeFunctionResult(
'getCaller',
res
)
expect(paddedRes).to.eq(constants.AddressZero)
})
it('should correctly use the "from" value', async () => {
// Deploy a contract to check msg.caller
const Factory__ValueContext: ContractFactory =
await ethers.getContractFactory('ValueContext', wallet)
const ValueContext: Contract = await Factory__ValueContext.deploy()
await ValueContext.deployTransaction.wait()
const from = wallet.address
// Do the call and check msg.sender
const data = ValueContext.interface.encodeFunctionData('getCaller')
const res = await provider.call({
to: ValueContext.address,
from,
data,
})
const [paddedRes] = ValueContext.interface.decodeFunctionResult(
'getCaller',
res
)
expect(paddedRes).to.eq(from)
})
})
describe('eth_getTransactionReceipt', () => {
......
......@@ -799,9 +799,11 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
// Set sender address or use a default if none specified
var addr common.Address
if args.From == nil {
if wallets := b.AccountManager().Wallets(); len(wallets) > 0 {
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
addr = accounts[0].Address
if !rcfg.UsingOVM {
if wallets := b.AccountManager().Wallets(); len(wallets) > 0 {
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
addr = accounts[0].Address
}
}
}
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment