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

feat(protocol): trigger simultaneous recurring TKO snapshots #16715

Merged
merged 53 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
abef644
Update TaikoL2.sol
dantaik Apr 11, 2024
19ceeb4
more
dantaik Apr 11, 2024
665fb16
fix
dantaik Apr 11, 2024
de3c699
Update TaikoL2.sol
dantaik Apr 11, 2024
2b7e8e5
Update TaikoL2.sol
dantaik Apr 11, 2024
e266e22
Update TaikoL2.sol
dantaik Apr 11, 2024
4b1faf2
rename
dantaik Apr 11, 2024
2f810e1
Update ISnapshot.sol
dantaik Apr 11, 2024
f72055b
more
dantaik Apr 12, 2024
858e0d1
Merge branch 'main' into synced_snapshot
dantaik Apr 12, 2024
50daa69
comment
dantaik Apr 12, 2024
0512cb3
more
dantaik Apr 12, 2024
5372314
Revert "more"
dantaik Apr 12, 2024
fa95bda
Update TaikoL2.sol
dantaik Apr 12, 2024
fa9bbaa
rename
dantaik Apr 12, 2024
62f5a26
more
dantaik Apr 12, 2024
b1772e9
Update TaikoToken.sol
dantaik Apr 12, 2024
6d899ba
Update LibStrings.sol
dantaik Apr 12, 2024
d97267d
Update TaikoL2.sol
dantaik Apr 12, 2024
8a0d80b
rename
dantaik Apr 12, 2024
cfa6dfe
Update BridgedERC20.sol
dantaik Apr 12, 2024
340e46a
Revert "rename"
dantaik Apr 12, 2024
a5aa52d
Revert "more"
dantaik Apr 12, 2024
766c9e9
more
dantaik Apr 12, 2024
0985d86
more
dantaik Apr 12, 2024
62bbe06
Update LibAutoSnapshot.sol
dantaik Apr 12, 2024
633f913
Update LibAutoSnapshot.sol
dantaik Apr 12, 2024
c464700
Merge branch 'main' into synced_snapshot
dantaik Apr 12, 2024
cf6c4bb
more
dantaik Apr 13, 2024
7f9ad39
Update LibAutoSnapshot.sol
dantaik Apr 13, 2024
9227586
fix
dantaik Apr 13, 2024
f8addd8
Update LibProposing.sol
dantaik Apr 13, 2024
2a5e748
Update TaikoL2.sol
dantaik Apr 13, 2024
5cf171f
Update TaikoL2.sol
dantaik Apr 13, 2024
b1894a6
more
dantaik Apr 14, 2024
f142029
rename
dantaik Apr 14, 2024
dee1e83
Update LibProposing.sol
dantaik Apr 14, 2024
8b22b19
Update TaikoL2.sol
dantaik Apr 14, 2024
7d36945
Merge branch 'main' into synced_snapshot
dantaik Apr 16, 2024
867d156
revert
dantaik Apr 16, 2024
1a065a5
Merge branch 'main' into synced_snapshot
dantaik Apr 16, 2024
7db0b3a
Update LibSnapshot.sol
dantaik Apr 16, 2024
679a73c
more
dantaik Apr 16, 2024
6f10750
Update pnpm-lock.yaml
dantaik Apr 16, 2024
79b7320
x
dantaik Apr 16, 2024
e0e04d9
Merge branch 'main' into synced_snapshot
davidtaikocha Apr 17, 2024
2f59200
Update LibSnapshot.sol
dantaik Apr 17, 2024
a578292
Update LibSnapshot.sol
dantaik Apr 17, 2024
7687c3b
Update BridgedERC20.sol
dantaik Apr 18, 2024
0fa8805
Merge branch 'main' into synced_snapshot
dantaik Apr 18, 2024
cb41cbc
Update BridgedERC20.sol
dantaik Apr 18, 2024
739d28d
Update BridgedERC20.sol
dantaik Apr 18, 2024
343035e
Merge branch 'main' into synced_snapshot
dantaik Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ library TaikoData {
uint64 lastUnpausedAt;
}

struct SlotC {
uint64 lastSnapshot;
uint64 __reservedC1;
uint64 __reservedC2;
uint64 __reservedC3;
}

/// @dev Struct holding the state variables for the {TaikoL1} contract.
struct State {
// Ring buffer for proposed blocks and a some recent verified blocks.
Expand All @@ -164,10 +171,10 @@ library TaikoData {
uint64 blockId_mod_blockRingBufferSize
=> mapping(uint32 transitionId => TransitionState ts)
) transitions;
// Ring buffer for Ether deposits
bytes32 __reserve1;
SlotA slotA; // slot 5
SlotB slotB; // slot 6
uint256[44] __gap;
SlotC slotC; // slot 7
uint256[43] __gap;
}
}
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
}

/// @notice Creates a new token snapshot.
function snapshot() public onlyFromOwnerOrNamed(LibStrings.B_SNAPSHOOTER) returns (uint256) {
function snapshot() public onlyFromOwnerOrNamed(LibStrings.B_TAIKO) returns (uint256) {
return _snapshot();
}

Expand Down
8 changes: 8 additions & 0 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.24;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../common/IAddressResolver.sol";
import "../../common/ISnapshot.sol";
import "../../common/LibStrings.sol";
import "../../libs/LibAddress.sol";
import "../../libs/LibNetwork.sol";
Expand Down Expand Up @@ -228,6 +229,13 @@ library LibProposing {
meta: meta_,
depositsProcessed: deposits_
});

// Take a snapshot every week
uint256 v = block.number / 50_400;
if (v > _state.slotC.lastSnapshot) {
_state.slotC.lastSnapshot = uint64(v);
ISnapshot(_resolver.resolve(LibStrings.B_TAIKO_TOKEN, false)).snapshot();
}
}

function _isProposerPermitted(
Expand Down
14 changes: 14 additions & 0 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "../common/EssentialContract.sol";
import "../common/ISnapshot.sol";
import "../common/LibStrings.sol";
import "../libs/LibAddress.sol";
import "../signal/ISignalService.sol";
Expand Down Expand Up @@ -49,6 +50,9 @@ contract TaikoL2 is EssentialContract {
/// @notice The L1's chain ID.
uint64 public l1ChainId;

/// @notice The last snapshot marker
uint64 public lastSnapshot;

uint256[46] private __gap;

/// @notice Emitted when the latest L1 block details are anchored to L2.
Expand Down Expand Up @@ -169,6 +173,16 @@ contract TaikoL2 is EssentialContract {
gasExcess = _gasExcess;

emit Anchored(_parentHash, _gasExcess);

// Take a snapshot every week
address taikoToken = resolve(LibStrings.B_TAIKO_TOKEN, true);
if (taikoToken != address(0)) {
uint256 v = _l1BlockId / 50_400;
if (v > lastSnapshot) {
lastSnapshot = uint64(v);
ISnapshot(taikoToken).snapshot();
}
}
}

/// @notice Withdraw token or Ether from this address
Expand Down
8 changes: 8 additions & 0 deletions packages/protocol/contracts/common/ISnapshot.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/// @title ISnapshot
/// @custom:security-contact [email protected]
interface ISnapshot {
function snapshot() external returns (uint256);
}
9 changes: 6 additions & 3 deletions packages/protocol/contracts/tokenvault/BridgedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ contract BridgedERC20 is
error BTOKEN_CANNOT_RECEIVE();
error BTOKEN_UNAUTHORIZED();

modifier onlyOwnerOrSnapshooter() {
if (msg.sender != owner() && msg.sender != snapshooter) {
modifier onlyOwnerOrTaikoOrSnapshooter() {
if (
msg.sender != owner() && msg.sender != snapshooter
&& msg.sender != resolve(LibStrings.B_TAIKO, false)
) {
revert BTOKEN_UNAUTHORIZED();
}
_;
Expand Down Expand Up @@ -81,7 +84,7 @@ contract BridgedERC20 is
}

/// @notice Creates a new token snapshot.
function snapshot() external onlyOwnerOrSnapshooter returns (uint256) {
function snapshot() external onlyOwnerOrTaikoOrSnapshooter returns (uint256) {
return _snapshot();
}

Expand Down
Loading