Skip to content

Commit

Permalink
Merge pull request ethereum-optimism#91 from ethereum-optimism/m/add-…
Browse files Browse the repository at this point in the history
…l1-attributes-contract

Add L1Block values contract
  • Loading branch information
protolambda authored Dec 23, 2021
2 parents 95cd703 + 024d43f commit 9fa526b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 18 deletions.
31 changes: 31 additions & 0 deletions packages/contracts/contracts/L2/L1Block.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

/**
* @title L1Block
*/
contract L1Block {
address constant depositorAccount = 0xDeaDDEaDDeAdDeAdDEAdDEaddeAddEAdDEAd0001;

uint256 public number;
uint256 public timestamp;
uint256 public basefee;
bytes32 public hash;

function setL1BlockValues(
uint256 _number,
uint256 _timestamp,
uint256 _basefee,
bytes32 _hash
) external {
require(
msg.sender == depositorAccount,
"Only callable by L1 Attributes Depositor Account"
);

number = _number;
timestamp = _timestamp;
basefee = _basefee;
hash = _hash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ethers } from 'hardhat'
import { Contract, ContractFactory, Signer, BigNumber } from 'ethers'
import { applyL1ToL2Alias } from '@eth-optimism/core-utils'

import { DepositFeed__factory, DepositFeed } from '../typechain'
import { DepositFeed__factory, DepositFeed } from '../../typechain'

const ZERO_ADDRESS = '0x' + '00'.repeat(20)
const ZERO_BIGNUMBER = BigNumber.from(0)
Expand Down
60 changes: 60 additions & 0 deletions packages/contracts/test/L2/L1Block.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expect } from 'chai'
import { ethers } from 'hardhat'
import { Signer } from 'ethers'

import { L1Block__factory, L1Block } from '../../typechain'

const DEPOSITOR_ACCOUNT = '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001'
const NON_ZERO_HASH = '0x' + 'ab'.repeat(32)

describe('L1Block contract', () => {
let signer: Signer
let signerAddress: string
let l1Block: L1Block
let depositor: Signer
before(async () => {
;[signer] = await ethers.getSigners()
signerAddress = await signer.getAddress()
l1Block = await new L1Block__factory(signer).deploy()
await l1Block.deployed()

depositor = await ethers.getSigner(DEPOSITOR_ACCOUNT)

})

it('setL1BlockValues: Should revert if not called by L1 Attributes Depositor Account', async () => {

})

describe('Should return the correct block values for:', async () => {
before(async () => {
await ethers.provider.send('hardhat_impersonateAccount', [
DEPOSITOR_ACCOUNT
])
await ethers.provider.send('hardhat_setBalance', [
DEPOSITOR_ACCOUNT, '0xFFFFFFFFFFFF'
])
await l1Block.connect(depositor).setL1BlockValues(1, 2, 3, NON_ZERO_HASH)
await ethers.provider.send('hardhat_stopImpersonatingAccount', [
DEPOSITOR_ACCOUNT
])
l1Block.connect(signer)
})

it('number', async () => {
expect(await l1Block.number()).to.equal(1)
})

it('timestamp', async () => {
expect(await l1Block.timestamp()).to.equal(2)
})

it('basefee', async () => {
expect(await l1Block.basefee()).to.equal(3)
})

it('hash', async () => {
expect(await l1Block.hash()).to.equal(NON_ZERO_HASH)
})
})
})
28 changes: 11 additions & 17 deletions specs/deposits.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,16 @@ The contract has the following solidity interface, and can be interacted with ac

[ABI]: https://docs.soliditylang.org/en/v0.8.10/abi-spec.html

```solidity
interface L1BlockValues {
function setL1BlockValues(
uint256 number,
uint256 timestamp,
uint256 baseFee,
bytes32 hash
) external;
function l1Number() view;
function l1Timestamp() view;
function l1BaseFee() view;
function l1Hash() view;
}
```
#### L1 Attributes: Reference Implementation

A reference implementation of the L1 Attributes predeploy contract can be found in [L1Block.sol].

[L1Block.sol]: /packages/contracts/contracts/L1Block.sol

The bytecode to add to the genesis file will be located in the `deployedBytecode` of the
[JSON artifact file][l1-block-artifacts] corresponding to L1Block.sol.

[l1-block-artifacts]: /packages/contracts/artifacts/contracts/L2/L1Block.sol/L1Block.json

## L1 Transaction Deposits

Expand Down Expand Up @@ -203,7 +197,7 @@ has the same address as a contract on L2 but doesn't have the same code. We can
this for EOAs because they're guaranteed to have the same "code" (i.e. no code at all). This also
makes it possible for users to interact with contracts on L2 even when the Sequencer is down.

#### Reference Implementation
#### Deposit Feed: Reference Implementation

A reference implementation of the Deposit Feed contract can be found in [DepositFeed.sol].

Expand Down

0 comments on commit 9fa526b

Please sign in to comment.