Skip to content
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
7 changes: 2 additions & 5 deletions arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,8 @@ func InitializeArbosState(stateDB vm.StateDB, burner burn.Burner, chainConfig *p
merkleAccumulator.InitializeMerkleAccumulator(sto.OpenSubStorage(sendMerkleSubspace))
blockhash.InitializeBlockhashes(sto.OpenSubStorage(blockhashesSubspace))

// by default, the remapped zero address is the initial chain owner
initialChainOwner := util.RemapL1Address(common.Address{})
if chainConfig.ArbitrumChainParams.InitialChainOwner != (common.Address{}) {
initialChainOwner = chainConfig.ArbitrumChainParams.InitialChainOwner
}
// may be the zero address
initialChainOwner := chainConfig.ArbitrumChainParams.InitialChainOwner
ownersStorage := sto.OpenSubStorage(chainOwnerSubspace)
_ = addressSet.Initialize(ownersStorage)
_ = addressSet.OpenAddressSet(ownersStorage).Add(initialChainOwner)
Expand Down
15 changes: 10 additions & 5 deletions arbos/incomingmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (msg *L1IncomingMessage) ParseL2Transactions(chainId *big.Int, batchFetcher
ChainId: chainId,
L1RequestId: depositRequestId,
// Matches the From of parseUnsignedTx
To: util.RemapL1Address(msg.Header.Poster),
To: msg.Header.Poster,
Value: tx.Value(),
})
return types.Transactions{deposit, tx}, nil
Expand Down Expand Up @@ -380,7 +380,7 @@ func parseUnsignedTx(rd io.Reader, poster common.Address, requestId *common.Hash
case L2MessageKind_UnsignedUserTx:
inner = &types.ArbitrumUnsignedTx{
ChainId: chainId,
From: util.RemapL1Address(poster),
From: poster,
Nonce: nonce,
GasFeeCap: maxFeePerGas.Big(),
Gas: gasLimit.Big().Uint64(),
Expand All @@ -395,7 +395,7 @@ func parseUnsignedTx(rd io.Reader, poster common.Address, requestId *common.Hash
inner = &types.ArbitrumContractTx{
ChainId: chainId,
RequestId: *requestId,
From: util.RemapL1Address(poster),
From: poster,
GasFeeCap: maxFeePerGas.Big(),
Gas: gasLimit.Big().Uint64(),
To: destination,
Expand All @@ -410,6 +410,10 @@ func parseUnsignedTx(rd io.Reader, poster common.Address, requestId *common.Hash
}

func parseEthDepositMessage(rd io.Reader, header *L1IncomingMessageHeader, chainId *big.Int) (*types.Transaction, error) {
to, err := util.AddressFromReader(rd)
if err != nil {
return nil, err
}
balance, err := util.HashFromReader(rd)
if err != nil {
return nil, err
Expand All @@ -420,7 +424,8 @@ func parseEthDepositMessage(rd io.Reader, header *L1IncomingMessageHeader, chain
tx := &types.ArbitrumDepositTx{
ChainId: chainId,
L1RequestId: *header.RequestId,
To: util.RemapL1Address(header.Poster),
From: header.Poster,
To: to,
Value: balance.Big(),
}
return types.NewTx(tx), nil
Expand Down Expand Up @@ -491,7 +496,7 @@ func parseSubmitRetryableMessage(rd io.Reader, header *L1IncomingMessageHeader,
tx := &types.ArbitrumSubmitRetryableTx{
ChainId: chainId,
RequestId: *header.RequestId,
From: util.RemapL1Address(header.Poster),
From: header.Poster,
L1BaseFee: header.L1BaseFee,
DepositValue: depositValue.Big(),
GasFeeCap: maxFeePerGas.Big(),
Expand Down
3 changes: 0 additions & 3 deletions arbos/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ func (p *TxProcessor) StartTxHook() (endTxNow bool, gasUsed uint64, err error, r
switch tx := underlyingTx.GetInner().(type) {
case *types.ArbitrumDepositTx:
defer (startTracer())()
if p.msg.From() != arbosAddress {
return false, 0, errors.New("deposit not from arbAddress"), nil
}
util.MintBalance(p.msg.To(), p.msg.Value(), evm, util.TracingDuringEVM)
return true, 0, nil, nil
case *types.ArbitrumInternalTx:
Expand Down
9 changes: 8 additions & 1 deletion arbstate/geth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func TestEthDepositMessage(t *testing.T) {
L1BaseFee: big.NewInt(10000000000000),
}
msgBuf := bytes.Buffer{}
if err := util.AddressToWriter(addr, &msgBuf); err != nil {
t.Error(err)
}
if err := util.HashToWriter(balance, &msgBuf); err != nil {
t.Error(err)
}
Expand All @@ -88,7 +91,11 @@ func TestEthDepositMessage(t *testing.T) {

secondRequestId := common.BigToHash(big.NewInt(4))
header.RequestId = &secondRequestId
header.Poster = util.RemapL1Address(addr)
msgBuf2 := bytes.Buffer{}
if err := util.AddressToWriter(addr, &msgBuf2); err != nil {
t.Error(err)
}
if err := util.HashToWriter(balance2, &msgBuf2); err != nil {
t.Error(err)
}
Expand All @@ -103,7 +110,7 @@ func TestEthDepositMessage(t *testing.T) {

RunMessagesThroughAPI(t, [][]byte{serialized, serialized2}, statedb)

balanceAfter := statedb.GetBalance(util.RemapL1Address(addr))
balanceAfter := statedb.GetBalance(addr)
if balanceAfter.Cmp(new(big.Int).Add(balance.Big(), balance2.Big())) != 0 {
Fail(t)
}
Expand Down
17 changes: 10 additions & 7 deletions contracts/src/bridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,23 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
/// Look into retryable tickets if you are interested in this functionality.
/// @dev this function should not be called inside contract constructors
function depositEth() public payable override whenNotPaused returns (uint256) {
address sender = msg.sender;
address dest = msg.sender;

// solhint-disable-next-line avoid-tx-origin
if (!AddressUpgradeable.isContract(sender) && tx.origin == msg.sender) {
if (AddressUpgradeable.isContract(msg.sender) || tx.origin != msg.sender) {
// isContract check fails if this function is called during a contract's constructor.
// We don't adjust the address for calls coming from L1 contracts since their addresses get remapped
// If the caller is an EOA, we adjust the address.
// This is needed because unsigned messages to the L2 (such as retryables)
// have the L1 sender address mapped.
// Here we preemptively reverse the mapping for EOAs so deposits work as expected
sender = AddressAliasHelper.undoL1ToL2Alias(sender);
dest = AddressAliasHelper.applyL1ToL2Alias(msg.sender);
}

return
_deliverMessage(
L1MessageType_ethDeposit,
sender, // arb-os will add the alias to this value
abi.encodePacked(msg.value)
msg.sender,
abi.encodePacked(dest, msg.value)
);
}

Expand Down Expand Up @@ -405,7 +404,11 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
) internal returns (uint256) {
if (_messageData.length > MAX_DATA_SIZE)
revert DataTooLarge(_messageData.length, MAX_DATA_SIZE);
uint256 msgNum = deliverToBridge(_kind, _sender, keccak256(_messageData));
uint256 msgNum = deliverToBridge(
_kind,
AddressAliasHelper.applyL1ToL2Alias(_sender),
keccak256(_messageData)
);
emit InboxMessageDelivered(msgNum, _messageData);
return msgNum;
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/contract/sequencerInboxForceInclude.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
SequencerInbox__factory,
TransparentUpgradeableProxy__factory,
} from '../../build/types'
import { initializeAccounts } from './utils'
import { applyAlias, initializeAccounts } from './utils'
import { Event } from '@ethersproject/contracts'
import { Interface } from '@ethersproject/abi'
import {
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('SequencerInboxForceInclude', async () => {
const countAfter = (await bridge.functions.delayedMessageCount())[0].toNumber()
expect(countAfter, 'Unexpected inbox count').to.eq(countBefore + 1)

const senderAddr = await sender.getAddress()
const senderAddr = applyAlias(await sender.getAddress())

const messageDeliveredEvent = getMessageDeliveredEvents(
sendUnsignedTxReceipt,
Expand Down
16 changes: 16 additions & 0 deletions contracts/test/contract/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { ethers } from 'hardhat'
import { Signer } from '@ethersproject/abstract-signer'
import { getAddress } from '@ethersproject/address'

const ADDRESS_ALIAS_OFFSET = BigInt("0x1111000000000000000000000000000000001111");
const ADDRESS_BIT_LENGTH = 160;
const ADDRESS_NIBBLE_LENGTH = ADDRESS_BIT_LENGTH / 4;

export const applyAlias = (addr: string) => {
// we use BigInts in here to allow for proper overflow behaviour
// BigInt.asUintN calculates the correct positive modulus
return getAddress(
"0x" +
BigInt.asUintN(ADDRESS_BIT_LENGTH, BigInt(addr) + ADDRESS_ALIAS_OFFSET)
.toString(16)
.padStart(ADDRESS_NIBBLE_LENGTH, "0")
);
};

export async function initializeAccounts(): Promise<Signer[]> {
const [account0] = await ethers.getSigners()
Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
3 changes: 1 addition & 2 deletions precompiles/ArbOwner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func TestAddressSet(t *testing.T) {
callCtx := testContext(caller, evm)

// the zero address is an owner by default
ZeroAddressL2 := util.RemapL1Address(common.Address{})
Require(t, prec.RemoveChainOwner(callCtx, evm, ZeroAddressL2))
Require(t, prec.RemoveChainOwner(callCtx, evm, common.Address{}))

Require(t, prec.AddChainOwner(callCtx, evm, addr1))
Require(t, prec.AddChainOwner(callCtx, evm, addr2))
Expand Down