Skip to content

Commit

Permalink
fix(protocol): revert auto snapshot PR (#16801)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Apr 23, 2024
1 parent 35966b0 commit ef00cae
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 148 deletions.
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/TaikoData.sol
Expand Up @@ -149,7 +149,7 @@ library TaikoData {
bool provingPaused;
uint8 __reservedB1;
uint16 __reservedB2;
uint32 lastSnapshotIdx;
uint32 __reservedB3;
uint64 lastUnpausedAt;
}

Expand All @@ -164,6 +164,7 @@ 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
Expand Down
6 changes: 0 additions & 6 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Expand Up @@ -45,12 +45,6 @@ abstract contract TaikoEvents {
/// @param slotB The SlotB data structure.
event StateVariablesUpdated(TaikoData.SlotB slotB);

/// @notice Emitted when the Taiko token snapshot is taken.
/// @param tkoAddress The Taiko token address.
/// @param snapshotIdx The snapshot index.
/// @param snapshotId The snapshot id.
event TaikoTokenSnapshot(address tkoAddress, uint256 snapshotIdx, uint256 snapshotId);

/// @dev Emitted when a block transition is proved or re-proved.
/// @param blockId The ID of the proven block.
/// @param tran The verified transition.
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/TaikoL1.sol
Expand Up @@ -59,6 +59,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
// reset some previously used slots for future reuse
state.slotB.__reservedB1 = 0;
state.slotB.__reservedB2 = 0;
state.slotB.__reservedB3 = 0;
state.__reserve1 = 0;
}

Expand Down
9 changes: 0 additions & 9 deletions packages/protocol/contracts/L1/TaikoToken.sol
Expand Up @@ -52,11 +52,6 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
return _burn(_from, _amount);
}

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

/// @notice Transfers tokens to a specified address.
/// @param _to The address to transfer tokens to.
/// @param _amount The amount of tokens to transfer.
Expand Down Expand Up @@ -84,10 +79,6 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
return super.transferFrom(_from, _to, _amount);
}

function currentSnapshotId() public view returns (uint256) {
return _getCurrentSnapshotId();
}

function _beforeTokenTransfer(
address _from,
address _to,
Expand Down
17 changes: 1 addition & 16 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Expand Up @@ -4,7 +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/LibSnapshot.sol";
import "../../common/LibStrings.sol";
import "../../libs/LibAddress.sol";
import "../../libs/LibNetwork.sol";
import "../hooks/IHook.sol";
Expand Down Expand Up @@ -185,8 +185,6 @@ library LibProposing {

{
IERC20 tko = IERC20(_resolver.resolve(LibStrings.B_TAIKO_TOKEN, false));
_takeTaikoTokenSnapshot(_state, address(tko), b);

uint256 tkoBalance = tko.balanceOf(address(this));

// Run all hooks.
Expand Down Expand Up @@ -232,19 +230,6 @@ library LibProposing {
});
}

function _takeTaikoTokenSnapshot(
TaikoData.State storage _state,
address _taikoToken,
TaikoData.SlotB memory _slotB
)
private
{
uint32 idx = LibSnapshot.autoSnapshot(_taikoToken, block.number, _slotB.lastSnapshotIdx);
if (idx != 0) {
_state.slotB.lastSnapshotIdx = idx;
}
}

function _isProposerPermitted(
TaikoData.SlotB memory _slotB,
IAddressResolver _resolver
Expand Down
18 changes: 1 addition & 17 deletions packages/protocol/contracts/L2/TaikoL2.sol
Expand Up @@ -5,7 +5,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "../common/EssentialContract.sol";
import "../common/LibSnapshot.sol";
import "../common/LibStrings.sol";
import "../libs/LibAddress.sol";
import "../signal/ISignalService.sol";
import "./Lib1559Math.sol";
Expand Down Expand Up @@ -47,24 +47,15 @@ contract TaikoL2 is EssentialContract {
uint64 private __currentBlockTimestamp;

/// @notice The L1's chain ID.
/// @dev Slot 4.
uint64 public l1ChainId;

uint32 public lastSnapshotIdx;

uint256[46] private __gap;

/// @notice Emitted when the latest L1 block details are anchored to L2.
/// @param parentHash The hash of the parent block.
/// @param gasExcess The gas excess value used to calculate the base fee.
event Anchored(bytes32 parentHash, uint64 gasExcess);

/// @notice Emitted when the Taiko token snapshot is taken.
/// @param tkoAddress The Taiko token address.
/// @param snapshotIdx The snapshot index.
/// @param snapshotId The snapshot id.
event TaikoTokenSnapshot(address tkoAddress, uint256 snapshotIdx, uint256 snapshotId);

error L2_BASEFEE_MISMATCH();
error L2_INVALID_L1_CHAIN_ID();
error L2_INVALID_L2_CHAIN_ID();
Expand Down Expand Up @@ -114,7 +105,6 @@ contract TaikoL2 is EssentialContract {

/// @notice Anchors the latest L1 block details to L2 for cross-layer
/// message verification.
/// @dev The gas limit for this transaction is set to 250K in geth and raiko.
/// @dev This function can be called freely as the golden touch private key is publicly known,
/// but the Taiko node guarantees the first transaction of each block is always this anchor
/// transaction, and any subsequent calls will revert with L2_PUBLIC_INPUT_HASH_MISMATCH.
Expand Down Expand Up @@ -178,12 +168,6 @@ contract TaikoL2 is EssentialContract {
__currentBlockTimestamp = uint64(block.timestamp);
gasExcess = _gasExcess;

address tko = resolve(LibStrings.B_TAIKO_TOKEN, true);
if (tko != address(0)) {
uint32 idx = LibSnapshot.autoSnapshot(tko, _l1BlockId, lastSnapshotIdx);
if (idx != 0) lastSnapshotIdx = idx;
}

emit Anchored(_parentHash, _gasExcess);
}

Expand Down
47 changes: 0 additions & 47 deletions packages/protocol/contracts/common/LibSnapshot.sol

This file was deleted.

39 changes: 0 additions & 39 deletions packages/protocol/contracts/tokenvault/BridgedERC20.sol
Expand Up @@ -31,12 +31,6 @@ contract BridgedERC20 is
uint256[47] private __gap;

error BTOKEN_CANNOT_RECEIVE();
error BTOKEN_UNAUTHORIZED();

modifier onlyAuthorizedForSnapshot() {
if (!isAuthorizedForSnapshot(msg.sender)) revert BTOKEN_UNAUTHORIZED();
_;
}

/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
Expand Down Expand Up @@ -72,17 +66,6 @@ contract BridgedERC20 is
__srcDecimals = _decimals;
}

/// @notice Set the snapshoter address.
/// @param _snapshooter snapshooter address.
function setSnapshooter(address _snapshooter) external onlyOwner {
snapshooter = _snapshooter;
}

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

/// @notice Gets the name of the token.
/// @return The name.
function name()
Expand Down Expand Up @@ -116,28 +99,6 @@ contract BridgedERC20 is
return __srcDecimals;
}

/// @notice Gets the current snapshot ID.
/// @return The current snapshot ID.
function currentSnapshotId() public view returns (uint256) {
return _getCurrentSnapshotId();
}

/// @notice Checks if an address can take a snapshot.
/// @param addr The address.
/// @return true if the address can perform a snapshot, false otherwise.
function isAuthorizedForSnapshot(address addr) public view returns (bool) {
if (addr == address(0)) return false;

if (
addr == resolve(LibStrings.B_TAIKO, true)
&& address(this) == resolve(LibStrings.B_TAIKO_TOKEN, true)
) return true;

if (addr == snapshooter) return true;

return false;
}

/// @notice Gets the canonical token's address and chain ID.
/// @return The canonical token's address.
/// @return The canonical token's chain ID.
Expand Down
13 changes: 0 additions & 13 deletions packages/protocol/test/L1/TaikoL1.t.sol
Expand Up @@ -186,19 +186,6 @@ contract TaikoL1Test is TaikoL1TestBase {
assertEq(balanceBeforeBurn - 1 ether, balanceAfterBurn);
}

function test_snapshot() external {
vm.prank(address(L1));
tko.snapshot();

uint256 totalSupplyAtSnapshot = tko.totalSupplyAt(1);

vm.prank(tko.owner(), tko.owner());
tko.burn(address(this), 1 ether);

// At snapshot date vs. now, the total supply differs
assertEq(totalSupplyAtSnapshot, tko.totalSupply() + 1 ether);
}

function test_getTierIds() external {
uint16[] memory tiers = cp.getTierIds();
assertEq(tiers[0], LibTiers.TIER_OPTIMISTIC);
Expand Down

0 comments on commit ef00cae

Please sign in to comment.