Commit e52ce890 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

feat: no proxy (#47)

* rebased to master

* Fixed resolve in ctc

* contracts: remove require statement

* Fix broken tests

* Fix broken FraudContributor
Co-authored-by: default avatarKelvin Fichter <kelvinfichter@gmail.com>
Co-authored-by: default avatarKarl Floersch <karl@karlfloersch.com>
parent 47bf1dfd
......@@ -22,7 +22,7 @@ const config: BuidlerConfig = {
timeout: 50000,
},
solc: {
version: '0.7.0',
version: '0.7.4',
optimizer: { enabled: true, runs: 200 },
},
typechain: {
......
......@@ -19,14 +19,6 @@ import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol
* @title OVM_L1CrossDomainMessenger
*/
contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCrossDomainMessenger, Lib_AddressResolver {
/*******************************************
* Contract Variables: Contract References *
*******************************************/
iOVM_CanonicalTransactionChain internal ovmCanonicalTransactionChain;
iOVM_StateCommitmentChain internal ovmStateCommitmentChain;
/***************
* Constructor *
......@@ -37,12 +29,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
*/
constructor(
address _libAddressManager
)
Lib_AddressResolver(_libAddressManager)
{
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"));
ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
}
) Lib_AddressResolver(_libAddressManager) {}
/********************
......@@ -174,6 +161,8 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
bool
)
{
iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
return (
ovmStateCommitmentChain.insideFraudProofWindow(_proof.stateRootBatchHeader) == false
&& ovmStateCommitmentChain.verifyStateCommitment(
......@@ -250,7 +239,7 @@ contract OVM_L1CrossDomainMessenger is iOVM_L1CrossDomainMessenger, OVM_BaseCros
override
internal
{
ovmCanonicalTransactionChain.enqueue(
iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain")).enqueue(
resolve("OVM_L2CrossDomainMessenger"),
_gasLimit,
_message
......
......@@ -19,14 +19,6 @@ import { OVM_BaseCrossDomainMessenger } from "./OVM_BaseCrossDomainMessenger.sol
*/
contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, OVM_BaseCrossDomainMessenger, Lib_AddressResolver {
/*******************************************
* Contract Variables: Contract References *
*******************************************/
iOVM_L1MessageSender internal ovmL1MessageSender;
iOVM_L2ToL1MessagePasser internal ovmL2ToL1MessagePasser;
/***************
* Constructor *
***************/
......@@ -36,12 +28,7 @@ contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, OVM_BaseCros
*/
constructor(
address _libAddressManager
)
Lib_AddressResolver(_libAddressManager)
{
ovmL1MessageSender = iOVM_L1MessageSender(resolve("OVM_L1MessageSender"));
ovmL2ToL1MessagePasser = iOVM_L2ToL1MessagePasser(resolve("OVM_L2ToL1MessagePasser"));
}
) Lib_AddressResolver(_libAddressManager) {}
/********************
......@@ -115,7 +102,7 @@ contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, OVM_BaseCros
)
{
return (
ovmL1MessageSender.getL1MessageSender() == resolve("OVM_L1CrossDomainMessenger")
iOVM_L1MessageSender(resolve("OVM_L1MessageSender")).getL1MessageSender() == resolve("OVM_L1CrossDomainMessenger")
);
}
......@@ -131,6 +118,6 @@ contract OVM_L2CrossDomainMessenger is iOVM_L2CrossDomainMessenger, OVM_BaseCros
override
internal
{
ovmL2ToL1MessagePasser.passMessageToL1(_message);
iOVM_L2ToL1MessagePasser(resolve("OVM_L2ToL1MessagePasser")).passMessageToL1(_message);
}
}
......@@ -51,11 +51,9 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
/*************
* Variables *
*************/
uint256 internal forceInclusionPeriodSeconds;
uint256 internal lastOVMTimestamp;
address internal sequencer;
address internal decompressionPrecompileAddress;
Lib_RingBuffer.RingBuffer internal batches;
Lib_RingBuffer.RingBuffer internal queue;
......@@ -63,17 +61,28 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
/***************
* Constructor *
***************/
constructor(
address _libAddressManager,
uint256 _forceInclusionPeriodSeconds
)
Lib_AddressResolver(_libAddressManager)
{
sequencer = resolve("OVM_Sequencer");
decompressionPrecompileAddress = resolve("OVM_DecompressionPrecompileAddress");
forceInclusionPeriodSeconds = _forceInclusionPeriodSeconds;
}
/********************
* Public Functions *
********************/
/**
* @inheritdoc iOVM_CanonicalTransactionChain
*/
function init()
override
public
{
batches.init(
16,
Lib_OVMCodec.RING_BUFFER_CTC_BATCHES,
......@@ -87,11 +96,6 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
);
}
/********************
* Public Functions *
********************/
/**
* @inheritdoc iOVM_CanonicalTransactionChain
*/
......@@ -272,7 +276,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
uint40 nextQueueIndex = getNextQueueIndex();
for (uint256 i = 0; i < _numQueuedTransactions; i++) {
if (msg.sender != sequencer) {
if (msg.sender != resolve("OVM_Sequencer")) {
Lib_OVMCodec.QueueElement memory el = getQueueElement(nextQueueIndex);
require(
el.timestamp + forceInclusionPeriodSeconds < block.timestamp,
......@@ -318,7 +322,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
);
require(
msg.sender == sequencer,
msg.sender == resolve("OVM_Sequencer"),
"Function can only be called by the Sequencer."
);
......@@ -603,7 +607,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
mstore(add(chainElementStart, 33), ctxBlockNumber)
calldatacopy(add(chainElementStart, BYTES_TILL_TX_DATA), add(_nextTransactionPtr, 3), _txDataLength)
leafHash := keccak256(chainElementStart, add(BYTES_TILL_TX_DATA, _txDataLength))
}
......@@ -779,7 +783,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
require(
_transaction.blockNumber == _txChainElement.blockNumber
&& _transaction.timestamp == _txChainElement.timestamp
&& _transaction.entrypoint == decompressionPrecompileAddress
&& _transaction.entrypoint == resolve("OVM_DecompressionPrecompileAddress")
&& _transaction.gasLimit == gasLimit
&& _transaction.l1TxOrigin == address(0)
&& _transaction.l1QueueOrigin == Lib_OVMCodec.QueueOrigin.SEQUENCER_QUEUE
......
......@@ -36,9 +36,6 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
uint256 internal lastDeletableIndex;
uint256 internal lastDeletableTimestamp;
Lib_RingBuffer.RingBuffer internal batches;
iOVM_CanonicalTransactionChain internal ovmCanonicalTransactionChain;
iOVM_FraudVerifier internal ovmFraudVerifier;
iOVM_BondManager internal ovmBondManager;
/***************
......@@ -50,13 +47,20 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
*/
constructor(
address _libAddressManager
)
Lib_AddressResolver(_libAddressManager)
{
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"));
ovmFraudVerifier = iOVM_FraudVerifier(resolve("OVM_FraudVerifier"));
ovmBondManager = iOVM_BondManager(resolve("OVM_BondManager"));
) Lib_AddressResolver(_libAddressManager) {}
/********************
* Public Functions *
********************/
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
function init()
override
public
{
batches.init(
16,
Lib_OVMCodec.RING_BUFFER_SCC_BATCHES,
......@@ -64,11 +68,6 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
);
}
/********************
* Public Functions *
********************/
/**
* @inheritdoc iOVM_StateCommitmentChain
*/
......@@ -132,7 +131,7 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
// Proposers must have previously staked at the BondManager
require(
ovmBondManager.isCollateralized(msg.sender),
iOVM_BondManager(resolve("OVM_BondManager")).isCollateralized(msg.sender),
"Proposer does not have enough collateral posted"
);
......@@ -142,7 +141,7 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
);
require(
getTotalElements() + _batch.length <= ovmCanonicalTransactionChain.getTotalElements(),
getTotalElements() + _batch.length <= iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain")).getTotalElements(),
"Number of state roots cannot exceed the number of canonical transactions."
);
......@@ -164,7 +163,7 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
public
{
require(
msg.sender == address(ovmFraudVerifier),
msg.sender == resolve("OVM_FraudVerifier"),
"State batches can only be deleted by the OVM_FraudVerifier."
);
......@@ -269,7 +268,7 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
);
require(
ovmCanonicalTransactionChain.verifyTransaction(
iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain")).verifyTransaction(
_transaction,
_txChainElement,
_txBatchHeader,
......@@ -297,7 +296,7 @@ contract OVM_StateCommitmentChain is iOVM_StateCommitmentChain, iRingBufferOverw
)
{
if (_id == Lib_OVMCodec.RING_BUFFER_CTC_QUEUE) {
return ovmCanonicalTransactionChain.getQueueElement(_index / 2).timestamp < lastDeletableTimestamp;
return iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain")).getQueueElement(_index / 2).timestamp < lastDeletableTimestamp;
} else {
return _index < lastDeletableIndex;
}
......
......@@ -64,7 +64,6 @@ contract OVM_BondManager is iOVM_BondManager, Lib_AddressResolver {
{
owner = msg.sender;
token = _token;
ovmFraudVerifier = resolve("OVM_FraudVerifier");
}
......@@ -75,7 +74,7 @@ contract OVM_BondManager is iOVM_BondManager, Lib_AddressResolver {
/// Adds `who` to the list of witnessProviders for the provided `preStateRoot`.
function recordGasSpent(bytes32 _preStateRoot, address who, uint256 gasSpent) override public {
// The sender must be the transitioner that corresponds to the claimed pre-state root
address transitioner = address(iOVM_FraudVerifier(ovmFraudVerifier).getStateTransitioner(_preStateRoot));
address transitioner = address(iOVM_FraudVerifier(resolve("OVM_FraudVerifier")).getStateTransitioner(_preStateRoot));
require(transitioner == msg.sender, Errors.ONLY_TRANSITIONER);
witnessProviders[_preStateRoot].total += gasSpent;
......@@ -85,7 +84,7 @@ contract OVM_BondManager is iOVM_BondManager, Lib_AddressResolver {
/// Slashes + distributes rewards or frees up the sequencer's bond, only called by
/// `FraudVerifier.finalizeFraudVerification`
function finalize(bytes32 _preStateRoot, uint256 batchIndex, address publisher, uint256 timestamp) override public {
require(msg.sender == ovmFraudVerifier, Errors.ONLY_FRAUD_VERIFIER);
require(msg.sender == resolve("OVM_FraudVerifier"), Errors.ONLY_FRAUD_VERIFIER);
require(witnessProviders[_preStateRoot].canClaim == false, Errors.ALREADY_FINALIZED);
// allow users to claim from that state root's
......
......@@ -2,18 +2,17 @@
pragma solidity ^0.7.0;
import { iOVM_BondManager } from "../../iOVM/verification/iOVM_BondManager.sol";
import { Lib_AddressResolver } from "../../libraries/resolver/Lib_AddressResolver.sol";
/// Minimal contract to be inherited by contracts consumed by users that provide
/// data for fraud proofs
contract OVM_FraudContributor {
iOVM_BondManager internal ovmBondManager;
abstract contract OVM_FraudContributor is Lib_AddressResolver {
/// Decorate your functions with this modifier to store how much total gas was
/// consumed by the sender, to reward users fairly
modifier contributesToFraudProof(bytes32 preStateRoot) {
uint startGas = gasleft();
_;
uint gasSpent = startGas - gasleft();
ovmBondManager.recordGasSpent(preStateRoot, msg.sender, gasSpent);
iOVM_BondManager(resolve('OVM_BondManager')).recordGasSpent(preStateRoot, msg.sender, gasSpent);
}
}
......@@ -19,16 +19,8 @@ import { iOVM_CanonicalTransactionChain } from "../../iOVM/chain/iOVM_CanonicalT
/* Contract Imports */
import { OVM_FraudContributor } from "./OVM_FraudContributor.sol";
contract OVM_FraudVerifier is OVM_FraudContributor, iOVM_FraudVerifier, Lib_AddressResolver {
contract OVM_FraudVerifier is Lib_AddressResolver, OVM_FraudContributor, iOVM_FraudVerifier {
/*******************************************
* Contract Variables: Contract References *
*******************************************/
iOVM_StateCommitmentChain internal ovmStateCommitmentChain;
iOVM_CanonicalTransactionChain internal ovmCanonicalTransactionChain;
/*******************************************
* Contract Variables: Internal Accounting *
*******************************************/
......@@ -47,11 +39,7 @@ contract OVM_FraudVerifier is OVM_FraudContributor, iOVM_FraudVerifier, Lib_Addr
address _libAddressManager
)
Lib_AddressResolver(_libAddressManager)
{
ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"));
ovmBondManager = iOVM_BondManager(resolve("OVM_BondManager"));
}
{}
/***************************************
......@@ -107,6 +95,9 @@ contract OVM_FraudVerifier is OVM_FraudContributor, iOVM_FraudVerifier, Lib_Addr
if (_hasStateTransitioner(_preStateRoot)) {
return;
}
iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
iOVM_CanonicalTransactionChain ovmCanonicalTransactionChain = iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"));
require(
ovmStateCommitmentChain.verifyStateCommitment(
......@@ -159,6 +150,8 @@ contract OVM_FraudVerifier is OVM_FraudContributor, iOVM_FraudVerifier, Lib_Addr
contributesToFraudProof(_preStateRoot)
{
iOVM_StateTransitioner transitioner = transitioners[_preStateRoot];
iOVM_StateCommitmentChain ovmStateCommitmentChain = iOVM_StateCommitmentChain(resolve("OVM_StateCommitmentChain"));
iOVM_BondManager ovmBondManager = iOVM_BondManager(resolve("OVM_BondManager"));
require(
transitioner.isComplete() == true,
......
......@@ -21,7 +21,7 @@ import { OVM_FraudContributor } from "./OVM_FraudContributor.sol";
/**
* @title OVM_StateTransitioner
*/
contract OVM_StateTransitioner is OVM_FraudContributor, iOVM_StateTransitioner, Lib_AddressResolver {
contract OVM_StateTransitioner is Lib_AddressResolver, OVM_FraudContributor, iOVM_StateTransitioner {
/*******************
* Data Structures *
......@@ -38,7 +38,6 @@ contract OVM_StateTransitioner is OVM_FraudContributor, iOVM_StateTransitioner,
* Contract Variables: Contract References *
*******************************************/
iOVM_ExecutionManager internal ovmExecutionManager;
iOVM_StateManager internal ovmStateManager;
......@@ -76,9 +75,7 @@ contract OVM_StateTransitioner is OVM_FraudContributor, iOVM_StateTransitioner,
postStateRoot = _preStateRoot;
transactionHash = _transactionHash;
ovmExecutionManager = iOVM_ExecutionManager(resolve("OVM_ExecutionManager"));
ovmStateManager = iOVM_StateManagerFactory(resolve("OVM_StateManagerFactory")).create(address(this));
ovmBondManager = iOVM_BondManager(resolve("OVM_BondManager"));
}
......@@ -100,7 +97,7 @@ contract OVM_StateTransitioner is OVM_FraudContributor, iOVM_StateTransitioner,
_;
}
/**********************************
* Public Functions: State Access *
**********************************/
......@@ -317,10 +314,12 @@ contract OVM_StateTransitioner is OVM_FraudContributor, iOVM_StateTransitioner,
"Invalid transaction provided."
);
iOVM_ExecutionManager ovmExecutionManager = iOVM_ExecutionManager(resolve("OVM_ExecutionManager"));
// We call `setExecutionManager` right before `run` (and not earlier) just in case the
// OVM_ExecutionManager address was updated between the time when this contract was created
// and when `applyTransaction` was called.
ovmStateManager.setExecutionManager(resolve("OVM_ExecutionManager"));
ovmStateManager.setExecutionManager(address(ovmExecutionManager));
// `run` always succeeds *unless* the user hasn't provided enough gas to `applyTransaction`
// or an INVALID_STATE_ACCESS flag was triggered. Either way, we won't get beyond this line
......
......@@ -52,6 +52,11 @@ interface iOVM_CanonicalTransactionChain {
* Public Functions *
********************/
/**
* Initializes this contract.
*/
function init() external;
/**
* Retrieves the total number of elements submitted.
* @return _totalElements Total submitted elements.
......
......@@ -14,6 +14,11 @@ interface iOVM_StateCommitmentChain {
* Public Functions *
********************/
/**
* Initializes this contract.
*/
function init() external;
/**
* Retrieves the total number of elements submitted.
* @return _totalElements Total submitted elements.
......
......@@ -13,7 +13,7 @@
"all": "yarn clean && yarn build && yarn test && yarn lint:fix && yarn lint",
"build": "yarn run build:contracts && yarn run build:typescript && yarn run build:copy && yarn run build:dump && yarn run build:typechain",
"build:typescript": "tsc -p tsconfig.prod.json",
"build:contracts": "buidler compile",
"build:contracts": "buidler compile --show-stack-traces",
"build:dump": "ts-node \"bin/take-dump.ts\"",
"build:copy": "copyfiles -u 2 \"contracts/optimistic-ethereum/**/*.sol\" \"build/contracts\"",
"build:typechain": "buidler typechain",
......
......@@ -55,18 +55,23 @@ export const makeContractDeployConfig = async (
AddressManager.address,
config.transactionChainConfig.forceInclusionPeriodSeconds,
],
afterDeploy: async (): Promise<void> => {
afterDeploy: async (contracts): Promise<void> => {
const sequencer = config.transactionChainConfig.sequencer
const sequencerAddress =
typeof sequencer === 'string'
? sequencer
: await sequencer.getAddress()
await AddressManager.setAddress('OVM_Sequencer', sequencerAddress)
await AddressManager.setAddress('Sequencer', sequencerAddress)
await contracts.OVM_CanonicalTransactionChain.init()
},
},
OVM_StateCommitmentChain: {
factory: getContractFactory('OVM_StateCommitmentChain'),
params: [AddressManager.address],
afterDeploy: async (contracts): Promise<void> => {
await contracts.OVM_StateCommitmentChain.init()
},
},
OVM_DeployerWhitelist: {
factory: getContractFactory('OVM_DeployerWhitelist'),
......
......@@ -16,10 +16,6 @@ export interface DeployResult {
export const deploy = async (
config: RollupDeployConfig
): Promise<DeployResult> => {
const Factory__SimpleProxy: ContractFactory = getContractFactory(
'Helper_SimpleProxy',
config.deploymentSigner
)
const AddressManager: Contract = await getContractFactory(
'Lib_AddressManager',
config.deploymentSigner
......@@ -42,16 +38,11 @@ export const deploy = async (
continue
}
const SimpleProxy = await Factory__SimpleProxy.deploy()
await AddressManager.setAddress(name, SimpleProxy.address)
contracts[`Proxy__${name}`] = SimpleProxy
try {
contracts[name] = await contractDeployParameters.factory
.connect(config.deploymentSigner)
.deploy(...(contractDeployParameters.params || []))
await SimpleProxy.setTarget(contracts[name].address)
await AddressManager.setAddress(name, contracts[name].address)
} catch (err) {
failedDeployments.push(name)
}
......
......@@ -206,6 +206,7 @@ describe('OVM_CanonicalTransactionChain', () => {
AddressManager.address,
FORCE_INCLUSION_PERIOD_SECONDS
)
await OVM_CanonicalTransactionChain.init()
})
describe('enqueue', () => {
......
......@@ -73,6 +73,7 @@ describe('OVM_StateCommitmentChain', () => {
OVM_StateCommitmentChain = await Factory__OVM_StateCommitmentChain.deploy(
AddressManager.address
)
await OVM_StateCommitmentChain.init()
})
describe('appendStateBatch', () => {
......
......@@ -53,6 +53,7 @@ describe('OVM_FraudVerifier', () => {
Mock__OVM_StateTransitionerFactory = smockit(
await ethers.getContractFactory('OVM_StateTransitionerFactory')
)
Mock__OVM_BondManager = smockit(
await ethers.getContractFactory('OVM_BondManager')
)
......
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