From e92b1da2ced73c2b28a825fce916acededab0a39 Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:49:00 +0800 Subject: [PATCH] fix(protocol): block reward must be minted (#14595) Co-authored-by: adaki2004 --- packages/protocol/contracts/L1/TaikoToken.sol | 2 +- packages/protocol/contracts/L1/libs/LibProposing.sol | 8 ++++---- .../protocol/contracts/common/AddressResolver.sol | 12 ++++++++++++ .../protocol/contracts/tokenvault/BridgedERC20.sol | 2 +- packages/protocol/test/L1/TaikoL1Oracle.t.sol | 4 +--- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoToken.sol b/packages/protocol/contracts/L1/TaikoToken.sol index f7a2ded007c..f1e75920611 100644 --- a/packages/protocol/contracts/L1/TaikoToken.sol +++ b/packages/protocol/contracts/L1/TaikoToken.sol @@ -96,7 +96,7 @@ contract TaikoToken is uint256 amount ) public - onlyFromNamed("erc20_vault") + onlyFromNamed2("erc20_vault", "taiko") { _mint(to, amount); } diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index e0569e03da1..6dcaf584b5a 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -81,14 +81,13 @@ library LibProposing { revert L1_TOO_MANY_BLOCKS(); } + TaikoToken tt = TaikoToken(resolver.resolve("taiko_token", false)); if (state.taikoTokenBalances[assignment.prover] >= config.proofBond) { unchecked { state.taikoTokenBalances[assignment.prover] -= config.proofBond; } } else { - TaikoToken(resolver.resolve("taiko_token", false)).transferFrom( - assignment.prover, address(this), config.proofBond - ); + tt.transferFrom(assignment.prover, address(this), config.proofBond); } // Pay prover after verifying assignment @@ -138,7 +137,8 @@ library LibProposing { config.proposerRewardMax ); - state.taikoTokenBalances[input.beneficiary] += reward; + // Reward must be minted + tt.mint(input.beneficiary, reward); } } } diff --git a/packages/protocol/contracts/common/AddressResolver.sol b/packages/protocol/contracts/common/AddressResolver.sol index be14cf33074..82befee3963 100644 --- a/packages/protocol/contracts/common/AddressResolver.sol +++ b/packages/protocol/contracts/common/AddressResolver.sol @@ -33,6 +33,18 @@ abstract contract AddressResolver { _; } + /// @dev Modifier that ensures the caller is the resolved address of two + /// given names. + /// @param name1 The first name to check against. + /// @param name2 The second name to check against. + modifier onlyFromNamed2(bytes32 name1, bytes32 name2) { + if ( + msg.sender != resolve(name1, true) + && msg.sender != resolve(name2, true) + ) revert RESOLVER_DENIED(); + _; + } + /// @notice Resolves a name to its address on the current chain. /// @param name Name whose address is to be resolved. /// @param allowZeroAddress If set to true, does not throw if the resolved diff --git a/packages/protocol/contracts/tokenvault/BridgedERC20.sol b/packages/protocol/contracts/tokenvault/BridgedERC20.sol index 5cacd7229bd..d3b7b709d06 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC20.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC20.sol @@ -83,7 +83,7 @@ contract BridgedERC20 is uint256 amount ) public - onlyFromNamed("erc20_vault") + onlyFromNamed2("erc20_vault", "taiko") { _mint(account, amount); emit Transfer(address(0), account, amount); diff --git a/packages/protocol/test/L1/TaikoL1Oracle.t.sol b/packages/protocol/test/L1/TaikoL1Oracle.t.sol index e9efa61897c..6ef3ae74c2b 100644 --- a/packages/protocol/test/L1/TaikoL1Oracle.t.sol +++ b/packages/protocol/test/L1/TaikoL1Oracle.t.sol @@ -67,9 +67,7 @@ contract TaikoL1OracleTest is TaikoL1TestBase { bytes32 parentHash = GENESIS_BLOCK_HASH; for ( - uint256 blockId = 1; - blockId < conf.blockMaxProposals * 10; - blockId++ + uint256 blockId = 1; blockId < conf.blockMaxProposals * 9; blockId++ ) { printVariables("before propose"); TaikoData.BlockMetadata memory meta =