-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Ortega
committed
Oct 10, 2023
1 parent
f794d11
commit e534234
Showing
58 changed files
with
13,725 additions
and
7,885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.6.4.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ | |
], | ||
"devDependencies": { | ||
"prettier": "^3" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
50 changes: 50 additions & 0 deletions
50
onchain/rollups/contracts/consensus/authority/AuthorityFactory.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; | ||
|
||
import {IAuthorityFactory} from "./IAuthorityFactory.sol"; | ||
import {Authority} from "./Authority.sol"; | ||
|
||
/// @title Authority Factory | ||
/// @notice Allows anyone to reliably deploy a new `Authority` contract. | ||
contract AuthorityFactory is IAuthorityFactory { | ||
function newAuthority( | ||
address _authorityOwner | ||
) external override returns (Authority) { | ||
Authority authority = new Authority(_authorityOwner); | ||
|
||
emit AuthorityCreated(_authorityOwner, authority); | ||
|
||
return authority; | ||
} | ||
|
||
function newAuthority( | ||
address _authorityOwner, | ||
bytes32 _salt | ||
) external override returns (Authority) { | ||
Authority authority = new Authority{salt: _salt}(_authorityOwner); | ||
|
||
emit AuthorityCreated(_authorityOwner, authority); | ||
|
||
return authority; | ||
} | ||
|
||
function calculateAuthorityAddress( | ||
address _authorityOwner, | ||
bytes32 _salt | ||
) external view override returns (address) { | ||
return | ||
Create2.computeAddress( | ||
_salt, | ||
keccak256( | ||
abi.encodePacked( | ||
type(Authority).creationCode, | ||
abi.encode(_authorityOwner) | ||
) | ||
) | ||
); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
onchain/rollups/contracts/consensus/authority/AuthorityHistoryPairFactory.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
import {IAuthorityHistoryPairFactory} from "./IAuthorityHistoryPairFactory.sol"; | ||
import {Authority} from "./Authority.sol"; | ||
import {IAuthorityFactory} from "./IAuthorityFactory.sol"; | ||
import {History} from "../../history/History.sol"; | ||
import {IHistoryFactory} from "../../history/IHistoryFactory.sol"; | ||
|
||
/// @title Authority-History Pair Factory | ||
/// @notice Allows anyone to reliably deploy a new Authority-History pair. | ||
contract AuthorityHistoryPairFactory is IAuthorityHistoryPairFactory { | ||
IAuthorityFactory immutable authorityFactory; | ||
IHistoryFactory immutable historyFactory; | ||
|
||
/// @notice Constructs the factory. | ||
/// @param _authorityFactory The `Authority` factory | ||
/// @param _historyFactory The `History` factory | ||
constructor( | ||
IAuthorityFactory _authorityFactory, | ||
IHistoryFactory _historyFactory | ||
) { | ||
authorityFactory = _authorityFactory; | ||
historyFactory = _historyFactory; | ||
|
||
emit AuthorityHistoryPairFactoryCreated( | ||
_authorityFactory, | ||
_historyFactory | ||
); | ||
} | ||
|
||
function getAuthorityFactory() | ||
external | ||
view | ||
override | ||
returns (IAuthorityFactory) | ||
{ | ||
return authorityFactory; | ||
} | ||
|
||
function getHistoryFactory() | ||
external | ||
view | ||
override | ||
returns (IHistoryFactory) | ||
{ | ||
return historyFactory; | ||
} | ||
|
||
function newAuthorityHistoryPair( | ||
address _authorityOwner | ||
) external override returns (Authority authority_, History history_) { | ||
authority_ = authorityFactory.newAuthority(address(this)); | ||
history_ = historyFactory.newHistory(address(authority_)); | ||
|
||
authority_.setHistory(history_); | ||
authority_.transferOwnership(_authorityOwner); | ||
} | ||
|
||
function newAuthorityHistoryPair( | ||
address _authorityOwner, | ||
bytes32 _salt | ||
) external override returns (Authority authority_, History history_) { | ||
authority_ = authorityFactory.newAuthority( | ||
address(this), | ||
calculateCompoundSalt(_authorityOwner, _salt) | ||
); | ||
history_ = historyFactory.newHistory(address(authority_), _salt); | ||
|
||
authority_.setHistory(history_); | ||
authority_.transferOwnership(_authorityOwner); | ||
} | ||
|
||
function calculateAuthorityHistoryAddressPair( | ||
address _authorityOwner, | ||
bytes32 _salt | ||
) | ||
external | ||
view | ||
override | ||
returns (address authorityAddress_, address historyAddress_) | ||
{ | ||
authorityAddress_ = authorityFactory.calculateAuthorityAddress( | ||
address(this), | ||
calculateCompoundSalt(_authorityOwner, _salt) | ||
); | ||
|
||
historyAddress_ = historyFactory.calculateHistoryAddress( | ||
authorityAddress_, | ||
_salt | ||
); | ||
} | ||
|
||
/// @notice Calculate the compound salt. | ||
/// @param _authorityOwner authority owner | ||
/// @param _salt salt | ||
/// @return compound salt | ||
/// @dev The purpose of calculating a compound salt is to | ||
/// prevent attackers front-running the creation of an Authority | ||
/// occupying the to-be-deployed address, but with a different owner. | ||
function calculateCompoundSalt( | ||
address _authorityOwner, | ||
bytes32 _salt | ||
) internal pure returns (bytes32) { | ||
return keccak256(abi.encodePacked(_authorityOwner, _salt)); | ||
} | ||
} |
Oops, something went wrong.