Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol): fix getLastSyncedBlock by writing the block's verifiedTransitionId #17624

Merged
merged 16 commits into from
Jun 20, 2024
Merged
1 change: 1 addition & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extend-ignore-identifiers-re = [
"bafybeiegdqpwx3he5dvoxqklspdjekjepjcobfaakyficksratn73qbbyy",
"TGE",
"tge",
"baed"
]

[files]
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/ITaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ interface ITaikoL1 {

/// @notice Gets the configuration of the TaikoL1 contract.
/// @return Config struct containing configuration parameters.
function getConfig() external view returns (TaikoData.Config memory);
function getConfig() external pure returns (TaikoData.Config memory);
}
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
}

/// @inheritdoc ITaikoL1
function getConfig() public view virtual override returns (TaikoData.Config memory) {
function getConfig() public pure virtual override returns (TaikoData.Config memory) {
// All hard-coded configurations:
// - treasury: the actual TaikoL2 address.
// - anchorGasLimit: 250_000 (based on internal devnet, its ~220_000
Expand Down
7 changes: 4 additions & 3 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ library LibProposing {

_tko.transferFrom(msg.sender, address(this), _config.livenessBond);

// Refund Ether
if (address(this).balance != 0) {
msg.sender.sendEtherAndVerify(address(this).balance);
// Bribe the block builder. Unlock 1559-tips, this tip is only made
// if this transaction succeeds.
if (msg.value != 0 && block.coinbase != address(0)) {
address(block.coinbase).sendEtherAndVerify(msg.value);
}

deposits_ = new TaikoData.EthDeposit[](0);
Expand Down
2 changes: 0 additions & 2 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ library LibProving {
uint256 reward; // reward to the new (current) prover

if (_ts.contester != address(0)) {
// assert(_blk.livenessBond == 0);

if (_local.sameTransition) {
// The contested transition is proven to be valid, contester loses the game
reward = _rewardAfterFriction(_ts.contestBond);
Expand Down
25 changes: 20 additions & 5 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ library LibVerifying {
uint32 lastVerifiedTransitionId;
uint16 tier;
bytes32 blockHash;
bytes32 stateRoot;
bytes32 syncStateRoot;
uint64 syncBlockId;
uint32 syncTransitionId;
address prover;
ITierRouter tierRouter;
}
Expand Down Expand Up @@ -140,8 +141,12 @@ library LibVerifying {
});

if (LibUtils.shouldSyncStateRoot(_config.stateRootSyncInternal, local.blockId)) {
local.stateRoot = ts.stateRoot;
local.syncBlockId = local.blockId;
bytes32 stateRoot = ts.stateRoot;
if (stateRoot != 0) {
local.syncStateRoot = stateRoot;
local.syncBlockId = local.blockId;
local.syncTransitionId = local.tid;
}
}

++local.blockId;
Expand All @@ -163,13 +168,23 @@ library LibVerifying {
}
if (!_tko.batchTransfer(provers, bonds)) revert L1_BATCH_TRANSFER_FAILED();

if (local.stateRoot != 0) {
if (local.syncStateRoot != 0) {
_state.slotA.lastSyncedBlockId = local.syncBlockId;
_state.slotA.lastSynecdAt = uint64(block.timestamp);

// We write the synced block's verifiedTransitionId to storage
if (local.syncBlockId != lastVerifiedBlockId) {
local.slot = local.syncBlockId % _config.blockRingBufferSize;
_state.blocks[local.slot].verifiedTransitionId = local.syncTransitionId;
}

// Ask signal service to write cross chain signal
ISignalService(_resolver.resolve(LibStrings.B_SIGNAL_SERVICE, false))
.syncChainData(
_config.chainId, LibStrings.H_STATE_ROOT, local.syncBlockId, local.stateRoot
_config.chainId,
LibStrings.H_STATE_ROOT,
local.syncBlockId,
local.syncStateRoot
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,9 @@ contract Bridge is EssentialContract, IBridge {
}

/// @dev Suggested by OpenZeppelin and copied from
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/83c7e45092dac350b070c421cd2bf7105616cf1a/contracts/metatx/ERC2771Forwarder.sol#L327C1-L370C6
/// https://github.com/OpenZeppelin/openzeppelin-contracts/
/// blob/83c7e45092dac350b070c421cd2bf7105616cf1a/contracts/
/// metatx/ERC2771Forwarder.sol#L327C1-L370C6
///
/// @dev Checks if the requested gas was correctly forwarded to the callee.
/// As a consequence of https://eips.ethereum.org/EIPS/eip-150[EIP-150]:
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/deployments/mainnet-contract-logs-L1.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
- owner: `admin.taiko.eth`
- quota:
- Quota Period: 24 hours
- ETH: `64516129032258064516` 1000 ETH
- ETH: 1000 ETH
- WETH(`0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`): 1000 ETH
- TAIKO(`0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800`): 2,000,000
- USDT(`0xdAC17F958D2ee523a2206206994597C13D831ec7`): 4,000,000
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L1/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.24;
import "./TaikoL1TestBase.sol";

contract TaikoL1_NoCooldown is TaikoL1 {
function getConfig() public view override returns (TaikoData.Config memory config) {
function getConfig() public pure override returns (TaikoData.Config memory config) {
config = TaikoL1.getConfig();
// over-write the following
config.maxBlocksToVerify = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.24;
import "./TaikoL1TestBase.sol";

contract TaikoL1Tiers is TaikoL1 {
function getConfig() public view override returns (TaikoData.Config memory config) {
function getConfig() public pure override returns (TaikoData.Config memory config) {
config = TaikoL1.getConfig();

config.maxBlocksToVerify = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L1/TaikoL1TestGroupBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.24;
import "./TaikoL1TestBase.sol";

contract TaikoL1New is TaikoL1 {
function getConfig() public view override returns (TaikoData.Config memory config) {
function getConfig() public pure override returns (TaikoData.Config memory config) {
config = TaikoL1.getConfig();
config.maxBlocksToVerify = 0;
config.blockMaxProposals = 10;
Expand Down