Skip to content

Commit

Permalink
feat(protocol): do not allow using owner() as named address in Addres…
Browse files Browse the repository at this point in the history
…sManager (#13771)
  • Loading branch information
dantaik authored May 17, 2023
1 parent 92a4d56 commit 12c810f
Show file tree
Hide file tree
Showing 15 changed files with 3,647 additions and 3,997 deletions.
12 changes: 8 additions & 4 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ contract TaikoL1 is EssentialContract, ICrossChainSync, TaikoEvents, TaikoErrors
* @param newProofTimeTarget New proof time target.
* @param newProofTimeIssued New proof time issued. If set to type(uint64).max, let it be unchanged.
*/
function setProofParams(uint64 newProofTimeTarget, uint64 newProofTimeIssued) external onlyOwner {
if (newProofTimeTarget == 0 || newProofTimeIssued == 0)
function setProofParams(uint64 newProofTimeTarget, uint64 newProofTimeIssued)
external
onlyOwner
{
if (newProofTimeTarget == 0 || newProofTimeIssued == 0) {
revert L1_INVALID_PARAM();
}

state.proofTimeTarget = newProofTimeTarget;
// Special case in a way - that we leave the proofTimeIssued unchanged
Expand Down Expand Up @@ -173,8 +177,8 @@ contract TaikoL1 is EssentialContract, ICrossChainSync, TaikoEvents, TaikoErrors
return state.blockFee;
}

function getProofReward(uint64 provenAt, uint64 proposedAt) public view returns (uint64) {
return LibTokenomics.getProofReward({state: state, proofTime: provenAt - proposedAt});
function getProofReward(uint64 proofTime) public view returns (uint64) {
return LibTokenomics.getProofReward(state, proofTime);
}

function getBlock(uint256 blockId)
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ library LibVerifying {
// EIP-4844 blob deleted after 30 days
|| config.txListCacheExpiry > 30 * 24 hours || config.ethDepositGas == 0
|| config.ethDepositMaxFee == 0 || config.ethDepositMaxFee >= type(uint96).max
|| config.adjustmentQuotient == 0 || initProofTimeTarget == 0 || initProofTimeIssued == 0
|| config.adjustmentQuotient == 0 || initProofTimeTarget == 0
|| initProofTimeIssued == 0
) revert L1_INVALID_CONFIG();

uint64 timeNow = uint64(block.timestamp);
Expand Down
7 changes: 7 additions & 0 deletions packages/protocol/contracts/common/AddressManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ contract AddressManager is OwnableUpgradeable, IAddressManager {
uint256 indexed _domain, bytes32 indexed _name, address _newAddress, address _oldAddress
);

error EOAOwnerAddressNotAllowed();

/// @dev Initializer to be called after being deployed behind a proxy.
function init() external initializer {
OwnableUpgradeable.__Ownable_init();
Expand All @@ -48,6 +50,11 @@ contract AddressManager is OwnableUpgradeable, IAddressManager {
virtual
onlyOwner
{
// This is to prevent using the owner as named address
if (newAddress.code.length == 0 && newAddress == msg.sender) {
revert EOAOwnerAddressNotAllowed();
}

address oldAddress = addresses[domain][name];
addresses[domain][name] = newAddress;
emit AddressSet(domain, name, newAddress, oldAddress);
Expand Down
10 changes: 8 additions & 2 deletions packages/protocol/script/DeployOnL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ contract DeployOnL1 is Script {
// Calculating it for our needs based on testnet/mainnet. We need it in
// order to make the fees on the same level - in ideal circumstences.
// See Brecht's comment https://github.com/taikoxyz/taiko-mono/pull/13564
if(INITIAL_PROOF_TIME_TARGET == 0) {
if (INITIAL_PROOF_TIME_TARGET == 0) {
revert PROOF_TIME_TARGET_NOT_SET();
}

Expand All @@ -130,7 +130,13 @@ contract DeployOnL1 is Script {
address(taikoL1),
bytes.concat(
taikoL1.init.selector,
abi.encode(addressManagerProxy, genesisHash, feeBase, initProofTimeIssued, initProofTimeIssued)
abi.encode(
addressManagerProxy,
genesisHash,
feeBase,
initProofTimeIssued,
initProofTimeIssued
)
)
);
setAddress("taiko", taikoL1Proxy);
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol/script/DetermineNewProofTimeIssued.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ uint16 constant DESIRED_PROOF_TIME_TARGET = 500;
uint8 constant ADJUSTMENT_QUOTIENT = 16;

contract DetermineProofTimeIssued is Script {

function run() public {
uint16 proofTimeTarget = DESIRED_PROOF_TIME_TARGET; // Approx. value which close to what is in the simulation
uint64 feeBase = 1e8; // 1 TKO
Expand All @@ -19,4 +18,4 @@ contract DetermineProofTimeIssued is Script {
console2.log("The proof time target is:", proofTimeTarget);
console2.log("The associated proof time issued is:", initProofTimeIssued);
}
}
}
8 changes: 5 additions & 3 deletions packages/protocol/test/TaikoL1LibTokenomicsMainnet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ contract TaikoL1LibTokenomicsMainnet is TaikoL1TestBase {

uint64 provenAt = uint64(block.timestamp);
console2.log(
"Proof reward is:", L1.getProofReward(provenAt, proposedAt[blockId - proofTime])
"Proof reward is:",
L1.getProofReward(provenAt - proposedAt[blockId - proofTime])
);
verifyBlock(Carol, 1);
}
Expand Down Expand Up @@ -182,7 +183,7 @@ contract TaikoL1LibTokenomicsMainnet is TaikoL1TestBase {
uint64 provenAt = uint64(block.timestamp);
console2.log(
"Proof reward is:",
L1.getProofReward(provenAt, proposedAt[blockId - proofTime])
L1.getProofReward(provenAt - proposedAt[blockId - proofTime])
);
}

Expand Down Expand Up @@ -249,7 +250,8 @@ contract TaikoL1LibTokenomicsMainnet is TaikoL1TestBase {

uint64 provenAt = uint64(block.timestamp);
console2.log(
"Proof reward is:", L1.getProofReward(provenAt, proposedAt[blockId - proofTime])
"Proof reward is:",
L1.getProofReward(provenAt - proposedAt[blockId - proofTime])
);
verifyBlock(Carol, 1);
}
Expand Down
40 changes: 19 additions & 21 deletions packages/protocol/test/TaikoL1LibTokenomicsTestnet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
signalRoot
);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));

verifyBlock(Carol, 1);
// This is where new fee evaluated
Expand Down Expand Up @@ -115,7 +115,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {

proveBlock(Bob, Bob, meta, parentHash, 1000000, 1000000, blockHash, signalRoot);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));
verifyBlock(Carol, 1);
// This is where new fee evaluated
printVariables("after verify");
Expand Down Expand Up @@ -179,7 +179,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
signalRoot
);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAtArr[blockId]));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAtArr[blockId]));

verifyBlock(Carol, 1);

Expand All @@ -205,7 +205,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
bytes32 signalRoot = bytes32(1e9 + blockId);
proveBlock(Bob, Bob, meta, parentHash, 1000000, 1000000, blockHash, signalRoot);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));
verifyBlock(Carol, 1);

parentHash = blockHash;
Expand Down Expand Up @@ -260,7 +260,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
signalRoot
);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));

verifyBlock(Carol, 1);

Expand Down Expand Up @@ -328,7 +328,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
);

uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt[blockId]));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt[blockId]));

verifyBlock(Carol, 1);

Expand Down Expand Up @@ -396,7 +396,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
);

uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt[blockId]));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt[blockId]));

verifyBlock(Carol, 1);
mine(21 - blockId);
Expand Down Expand Up @@ -451,7 +451,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
signalRoot
);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));

verifyBlock(Carol, 1);

Expand Down Expand Up @@ -520,7 +520,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
);

uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt[blockId]));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt[blockId]));

verifyBlock(Carol, 1);
mine(5);
Expand Down Expand Up @@ -576,7 +576,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
signalRoot
);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));

verifyBlock(Carol, 1);

Expand Down Expand Up @@ -605,7 +605,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
bytes32 signalRoot = bytes32(1e9 + blockId);
proveBlock(Bob, Bob, meta, parentHash, 1000000, 1000000, blockHash, signalRoot);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));
verifyBlock(Carol, 1);

parentHash = blockHash;
Expand Down Expand Up @@ -665,7 +665,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
);

uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAtArr[blockId]));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAtArr[blockId]));

verifyBlock(Carol, 1);
mine(21 - blockId);
Expand Down Expand Up @@ -693,7 +693,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
bytes32 signalRoot = bytes32(1e9 + blockId);
proveBlock(Bob, Bob, meta, parentHash, 1000000, 1000000, blockHash, signalRoot);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));
verifyBlock(Carol, 1);

parentHash = blockHash;
Expand Down Expand Up @@ -746,7 +746,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
signalRoot
);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));

verifyBlock(Carol, 1);

Expand Down Expand Up @@ -808,7 +808,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
uint64 provenAt = uint64(block.timestamp);
console2.log(
"Proof reward is:",
L1.getProofReward(provenAt, proposedAt[blockId - proofTime])
L1.getProofReward(provenAt - proposedAt[blockId - proofTime])
);
}

Expand Down Expand Up @@ -836,8 +836,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
}

/// @dev Test if testing proof time params works (changes) as expected
function test_changing_proof_time_parameters(
) external {
function test_changing_proof_time_parameters() external {
mine(1);

depositTaikoToken(Alice, 1e6 * 1e8, 100 ether);
Expand All @@ -854,15 +853,14 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {

//parentHash = prove_with_increasing_time(parentHash, 10);
for (uint256 blockId = 1; blockId < 20; blockId++) {

// See if proof reward decreases faster than usual
if(blockId == 8) {
if (blockId == 8) {
// 500 sec has the proofTimeIssued of 219263 (Calculated with 'forge script script/DetermineNewProofTimeIssued.s.sol')
L1.setProofParams(500, 219263);
}

// See if proof reward increases now
if(blockId == 15) {
if (blockId == 15) {
// 10 sec has the proofTimeIssued of 3759 (Calculated with 'forge script script/DetermineNewProofTimeIssued.s.sol')
L1.setProofParams(10, 3759);
}
Expand All @@ -886,7 +884,7 @@ contract TaikoL1LibTokenomicsTestnet is TaikoL1TestBase {
signalRoot
);
uint64 provenAt = uint64(block.timestamp);
console2.log("Proof reward is:", L1.getProofReward(provenAt, proposedAt));
console2.log("Proof reward is:", L1.getProofReward(provenAt - proposedAt));

verifyBlock(Carol, 1);

Expand Down
5 changes: 4 additions & 1 deletion packages/protocol/test/TaikoL1Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ contract TaikoL1OracleTest is TaikoL1TestBase {
assertEq(lastVerifiedBlockIdNow, lastVerifiedBlockId);
}

vm.warp(block.timestamp + L1.getStateVariables().proofTimeTarget + conf.systemProofCooldownPeriod);
vm.warp(
block.timestamp + L1.getStateVariables().proofTimeTarget
+ conf.systemProofCooldownPeriod
);
verifyBlock(Carol, 1);

lastVerifiedBlockIdNow = L1.getStateVariables().lastVerifiedBlockId;
Expand Down
12 changes: 9 additions & 3 deletions packages/protocol/test/TaikoL1TestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,20 @@ abstract contract TaikoL1TestBase is Test {
registerAddress("proto_broker", address(L1));

// Lastly, init L1
if( proofTimeTarget == 0 || initProofTimeIssued == 0) {
// This just means, these tests are not focusing on the tokenomics, which is fine!
if (proofTimeTarget == 0 || initProofTimeIssued == 0) {
// This just means, these tests are not focusing on the tokenomics, which is fine!
// So here, with 500second proof time the initial proof time issued value shall be that below.
// Calculated with 'forge script script/DetermineNewProofTimeIssued.s.sol'
proofTimeTarget = 500;
initProofTimeIssued = 219263;
}
L1.init(address(addressManager), GENESIS_BLOCK_HASH, feeBase, proofTimeTarget, initProofTimeIssued);
L1.init(
address(addressManager),
GENESIS_BLOCK_HASH,
feeBase,
proofTimeTarget,
initProofTimeIssued
);
printVariables("init ");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct Config {
uint64 maxEthDepositsPerBlock;
uint96 maxEthDepositAmount;
uint96 minEthDepositAmount;
uint64 proofTimeTarget;
uint8 adjustmentQuotient;
bool relaySignalRoot;
}
Expand All @@ -42,6 +41,7 @@ struct StateVariables {
uint64 genesisTimestamp;
uint64 numBlocks;
uint64 proofTimeIssued;
uint64 proofTimeTarget;
uint64 lastVerifiedBlockId;
uint64 accProposedAt;
uint64 nextEthDepositToProcess;
Expand Down Expand Up @@ -165,7 +165,7 @@ struct State {
uint64 blockFee;
uint64 proofTimeIssued;
uint64 lastVerifiedBlockId;
uint64 __reserved91;
uint64 proofTimeTarget;
uint256[42] __gap;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ event BlockVerified(uint256 id, bytes32 blockHash)
```solidity
event EthDeposited(struct TaikoData.EthDeposit deposit)
```

### ProofTimeTargetChanged

```solidity
event ProofTimeTargetChanged(uint64 proofTimeTarget)
```
Loading

0 comments on commit 12c810f

Please sign in to comment.