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

chore(protocol): improve contracts and docs for auditing #14565

Merged
merged 191 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 189 commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
d96e4bd
feat(protocol): alpha-4 with staking-based tokenomics (#13981)
dantaik Jun 28, 2023
c7fee73
refactor(protocol): add very minor update (#14066)
dantaik Jun 28, 2023
4cb7367
refactor(protocol): optimize ProverPool (#14069)
dantaik Jun 30, 2023
dc2e975
Merge branch 'main' into alpha-4
dantaik Jun 30, 2023
46c0e66
fix(protocol): Fix alpha-4 ability to build protocol and run tests (#…
cyberhorsey Jun 30, 2023
dee55c9
feat(eventindexer): Alpha 4 event indexing (#14078)
cyberhorsey Jul 1, 2023
5c40c12
feat(relayer): Alpha 4 event sub (#14081)
cyberhorsey Jul 1, 2023
81176e3
Merge branch 'main' into alpha-4
davidtaikocha Jul 1, 2023
8e398f4
chore(protocol): delete ProverPool2 and deprecated documents (#14082)
dantaik Jul 1, 2023
478ba5e
feat(protocol): allow premint of TKO to multiple addresses/amounts in…
cyberhorsey Jul 2, 2023
8ba71a6
chore(protocol): use block.prevrandao to avoid warning (#14088)
dantaik Jul 3, 2023
6805a11
Merge branch 'main' into alpha-4
dantaik Jul 3, 2023
e8ffbb8
Update TokenVault.sol
dong77 Jul 3, 2023
2fa83d2
fix typo
dantaik Jul 3, 2023
a539646
feat(protocol): restrict prover staking changes to once per hour (#14…
dantaik Jul 4, 2023
5bf313e
feat(protocol): disable oracle proofs to be over written by regular p…
dantaik Jul 4, 2023
38d537b
feat(protocol): unify taiko tokens acros L1, L2s, and L3s (#14083)
dantaik Jul 4, 2023
4e8e78a
Merge branch 'main' into alpha-4
cyberhorsey Jul 4, 2023
7f41353
feat(protocol): A4 bindings (#14101)
cyberhorsey Jul 4, 2023
4ef8d0c
fix(eventindexer): add address to Slashed event in db, + add logs (#1…
cyberhorsey Jul 4, 2023
05da0e7
fix(protocol): limit reward per gas in weight calculation (#14098)
dantaik Jul 5, 2023
c341f0a
add provers route
cyberhorsey Jul 5, 2023
44d119e
Merge branch 'main' into alpha-4
cyberhorsey Jul 5, 2023
a24f9a6
abigen
cyberhorsey Jul 5, 2023
76d9375
Merge branch 'alpha-4' of github.com:taikoxyz/taiko-mono into alpha-4
cyberhorsey Jul 5, 2023
5cd6c82
chore(protocol) use uint32 for gas limit, gas used, gas price (#14112)
dantaik Jul 6, 2023
fd07f3f
feat(protocol): add prover into block events (#14123)
dantaik Jul 7, 2023
c4c671e
feat(protocol): also add rewardPerGas into BlockProposedEvent (#14124)
dantaik Jul 8, 2023
053e198
Resolve merge from main with eventindexer changes
cyberhorsey Jul 10, 2023
c4ab00d
Merge branch 'alpha-4' of github.com:taikoxyz/taiko-mono into alpha-4
cyberhorsey Jul 10, 2023
32b043f
empty struct line
cyberhorsey Jul 10, 2023
aa3d6ec
move proverpool
cyberhorsey Jul 10, 2023
62a913c
lint
cyberhorsey Jul 10, 2023
9c0fd32
proverpool address comp
cyberhorsey Jul 10, 2023
f8415a2
chore(protocol): update BridgedERC20.sol by remove "dao" from auth li…
dantaik Jul 10, 2023
abc4157
Merge branch 'main' into alpha-4
cyberhorsey Jul 10, 2023
fc8fbbe
bindings for taikol1
cyberhorsey Jul 11, 2023
eb0d9e3
Merge branch 'main' into alpha-4
cyberhorsey Jul 11, 2023
d27a746
bindings
cyberhorsey Jul 11, 2023
a3e6f03
Merge branch 'alpha-4' of github.com:taikoxyz/taiko-mono into alpha-4
cyberhorsey Jul 11, 2023
35053d2
id => blockid
cyberhorsey Jul 11, 2023
77649c5
chore(protocol): improve ProverPool docs coverage (#14163)
dionysuzx Jul 14, 2023
b782050
feat(protocol): update Alpha-4 network configs (#14169)
davidtaikocha Jul 14, 2023
84f963a
feat(protocol): apply slight reward penalty based on timing (#14164)
dantaik Jul 15, 2023
ce1b87e
feat(bridge-ui): Optional faucet (#14178)
cyberhorsey Jul 16, 2023
29ccc17
comment to force push
cyberhorsey Jul 16, 2023
5ccdbb0
Merge branch 'alpha-4' of github.com:taikoxyz/taiko-mono into alpha-4
cyberhorsey Jul 16, 2023
d0319d1
envvars fix for faucet
cyberhorsey Jul 16, 2023
a58db26
fix(protocol): Fix prover duplicate (#14184)
cyberhorsey Jul 17, 2023
586cb78
fix(bridge-ui): add chain icons (#14189)
jscriptcoder Jul 18, 2023
2305fc7
feat(protocol): Pos dashboard + eventindexer indexing all proverpool …
cyberhorsey Jul 18, 2023
e2600d2
feat(pos-dashboard): Dashboard improvements (#14215)
cyberhorsey Jul 20, 2023
fb40a00
.
cyberhorsey Jul 20, 2023
adaa62e
.
cyberhorsey Jul 20, 2023
49df1a6
rm
cyberhorsey Jul 20, 2023
d54e566
feat(protocol): bring back whitelisted proposer (#14212)
dantaik Jul 20, 2023
7279086
feat(protocol): NFT (ERC721/ERC1155) bridge (#14118)
adaki2004 Jul 23, 2023
838b5e4
Merge branch 'main' into alpha-4
dong77 Jul 23, 2023
cb53b1e
pull main
dong77 Jul 23, 2023
8b746a0
Update LibVaultUtils.sol
dong77 Jul 23, 2023
6363f6e
chore(protocol): do not check sender in bridge's receive function [te…
dantaik Jul 24, 2023
e10bee7
feat(eventindexer): speed up sync (#14258)
cyberhorsey Jul 23, 2023
aa5d03d
chore(website): remove ttko discord and combine node runner manual (#…
dionysuzx Jul 24, 2023
a4aeeee
feat(bridge-ui-v2): bridging ETH and ERC20 (#14225)
jscriptcoder Jul 24, 2023
e269dbf
Merge branch 'main' into alpha-4
dantaik Jul 24, 2023
fdd74ac
fix(repo): update pnpm lock file (#14270)
dionysuzx Jul 24, 2023
9affe9c
feat(eventindexer): Galxe liquidity adding (#14268)
cyberhorsey Jul 25, 2023
8cd932c
fix(protocol): fix issue in slash amount calc (#14272)
dantaik Jul 25, 2023
01a0ad0
feat(protocol): Fix generate genesis tests (#14275)
adaki2004 Jul 25, 2023
29006ea
feat(pos-dashboard): Prover pool update (#14278)
cyberhorsey Jul 25, 2023
013912f
refactor(protocol): add proofWindowMultiplier (#14269)
dantaik Jul 25, 2023
b83a418
feat(pos-dashboard): bump lockfile (#14297)
cyberhorsey Jul 27, 2023
e795a09
merge main
dong77 Jul 27, 2023
fc22d37
Update lefthook.yml
dong77 Jul 27, 2023
3edbe55
Rearrange releaseTokens and merge into 1 txn
adaki2004 Jul 28, 2023
5743097
Remove releasedMsg and unnecessary comments
adaki2004 Jul 28, 2023
570ae10
Merge branch 'main' into alpha-4
cyberhorsey Jul 28, 2023
4b23d14
feat(protocol): decouple proof(s) verification from core protocol (#1…
adaki2004 Jul 29, 2023
7beb4fe
Merge branch 'alpha-4' into one_txn_token_and_eth_release
adaki2004 Jul 31, 2023
bd14dec
Move mock-proof workardound (for tests) into separate files
adaki2004 Jul 31, 2023
cd6b960
Add missing test deps
adaki2004 Jul 31, 2023
b339374
Remove enum/int recall message status
adaki2004 Jul 31, 2023
b4ade2e
remove comment section
adaki2004 Jul 31, 2023
3bd031e
fix(bridge-ui): alpha 4 fix bridge UI - TS errors (#14322)
jscriptcoder Jul 31, 2023
b9f3bda
feat(protocol): update `DeployOnL1` script for `ProofVerifier` (#14325)
davidtaikocha Jul 31, 2023
45549b8
Merge branch 'main' into alpha-4
davidtaikocha Jul 31, 2023
303d88d
Revert "remove comment section"
adaki2004 Aug 1, 2023
b70e686
Revert "Remove enum/int recall message status"
adaki2004 Aug 1, 2023
bf3bf66
Vault route logic
adaki2004 Aug 1, 2023
9661ddc
Merge branch 'main' into alpha-4
dantaik Aug 2, 2023
4d88957
Merge branch 'alpha-4' into one_txn_token_and_eth_release
dantaik Aug 2, 2023
333e39c
Discussed improvements
adaki2004 Aug 2, 2023
2e1ee3c
Fix failing test
adaki2004 Aug 2, 2023
c6cbc98
Remove unnecessary reentrancy
adaki2004 Aug 2, 2023
4a78b6b
feat(bridge-ui-v2): Fixed input validations and catching additional e…
KorbinianK Aug 2, 2023
ad7e9a0
Reduce code size part 1.
adaki2004 Aug 2, 2023
ec4c7a1
Merge branch 'alpha-4' into one_txn_token_and_eth_release
dantaik Aug 2, 2023
9f80603
Code size optimizations
adaki2004 Aug 2, 2023
8799400
Findings
adaki2004 Aug 2, 2023
7b239b6
remove unused mock
adaki2004 Aug 2, 2023
e82deba
feat(protocol): add `blockId` to `Slashed` event (#14357)
davidtaikocha Aug 3, 2023
1f2d4bc
Merge branch 'main' into alpha-4
davidtaikocha Aug 3, 2023
42bbc5f
feat(protocol): Fix failing unit test (#14358)
adaki2004 Aug 3, 2023
bb461e7
Add mock LibBridgeRecall (to mock proof)
adaki2004 Aug 3, 2023
340d245
lint + optimizer setting
adaki2004 Aug 3, 2023
78a2a2e
linitng warnings
adaki2004 Aug 3, 2023
b67ae99
lint warning
adaki2004 Aug 3, 2023
4bd85a3
add back github workflow
adaki2004 Aug 3, 2023
8377a80
Add auto-generated contract documentation
adaki2004 Aug 3, 2023
b21be79
Merge branch 'alpha-4' into one_txn_token_and_eth_release
dantaik Aug 3, 2023
4a8591d
improvements
adaki2004 Aug 3, 2023
7f3e524
Removed supportsInterface where not necessary
adaki2004 Aug 4, 2023
22ddab9
Discussed changes
adaki2004 Aug 4, 2023
3d46d9a
Merge branch 'main' into one_txn_token_and_eth_release
adaki2004 Aug 4, 2023
d0db12a
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 9, 2023
f70d767
feat(protocol): optimize bridge with removal of depositValue (#14383)
dantaik Aug 9, 2023
4660ec9
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 9, 2023
e23c86e
improve comments
dantaik Aug 9, 2023
1f41d77
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 9, 2023
378feec
fix(protocol): fix vault sending ether and improve comments (#14427)
dantaik Aug 11, 2023
e7afabb
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 11, 2023
143e585
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 11, 2023
6eb7f98
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 11, 2023
0381d7a
Modified bridge readme
adaki2004 Aug 11, 2023
3dea1c1
Merge branch 'main' into one_txn_token_and_eth_release
cyberhorsey Aug 11, 2023
8250784
feat(relayer): Bridge relayer updates (#14461)
cyberhorsey Aug 12, 2023
0e6fe65
improve comments
dantaik Aug 9, 2023
f7cc97e
fix(bridge-ui): return true if the token address is found on dest cha…
cyberhorsey Aug 12, 2023
5e9faa7
docs(protocol): cleanup protocol docs (#14462)
dionysuzx Aug 12, 2023
7e21e28
resolve conflicts
dantaik Aug 12, 2023
6c54371
fmt
dantaik Aug 12, 2023
23bf430
improve comments
dantaik Aug 12, 2023
39f29c2
Update EtherVault.sol
dantaik Aug 12, 2023
0691ba8
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 12, 2023
d801475
update comments (#14469)
dantaik Aug 13, 2023
7e7b951
Update ERC721Vault.sol
dantaik Aug 14, 2023
78f2cdb
fix(protocol): fix vault bugs in sending Ether (#14471)
dantaik Aug 14, 2023
f28b222
feat(protocol): Add tests to send ether with other token types (#14486)
adaki2004 Aug 14, 2023
b2ff009
Merge branch 'main' into one_txn_token_and_eth_release
cyberhorsey Aug 14, 2023
3301f1b
feat(protocol): change protocol data layout to enable coverage report…
adaki2004 Aug 16, 2023
3d12e57
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 17, 2023
43b582c
Merge branch 'main' into one_txn_token_and_eth_release
dionysuzx Aug 17, 2023
ab00d40
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 19, 2023
8d9bf6d
feat(protocol): prototype prover abstraction (#14510)
dantaik Aug 19, 2023
c55b887
Update generate_genesis.test.sh
dantaik Aug 20, 2023
a160237
Merge branch 'main' into one_txn_token_and_eth_release
dantaik Aug 20, 2023
e02f2b5
feat(protocol): block reward to incentivize proposers (#14544)
dantaik Aug 21, 2023
efa8319
Merge branch 'one_txn_token_and_eth_release' into prover_abstraction_…
dantaik Aug 21, 2023
8cf6106
Update TaikoL1Base.sol
dantaik Aug 21, 2023
497fdee
update
dantaik Aug 21, 2023
ff1dda0
Fix deploy scritp
cyberhorsey Aug 21, 2023
cfcd767
remove overflow check
cyberhorsey Aug 21, 2023
47e77ba
fix(protocol): fix workflow errors in #14541 (#14550)
davidtaikocha Aug 22, 2023
68278c8
feat(protocol): remove config.blockMaxTransactions (#14547)
dantaik Aug 22, 2023
9290aaf
chore(protocol): change the way instance is calculated (#14554)
dantaik Aug 22, 2023
2deb2b7
Update packages/protocol/contracts/L1/libs/LibProposing.sol
dantaik Aug 22, 2023
dc3d6d7
Update packages/protocol/contracts/L1/libs/LibProposing.sol
dantaik Aug 22, 2023
e4cea04
Update LibProving.sol
dantaik Aug 22, 2023
6cd7f5f
Update LibProposing.sol
dantaik Aug 22, 2023
20367a6
add TODOs for David and Yue
dantaik Aug 22, 2023
5f8d3ea
fix feedback
dantaik Aug 23, 2023
4dca9c9
fix feedback
dantaik Aug 23, 2023
e3df377
LibUtils.ORACLE_PROVER
dantaik Aug 23, 2023
18f20e2
add ID to onBlockAssigned
dantaik Aug 23, 2023
c43aba2
Update TaikoL1Oracle.t.sol
dantaik Aug 23, 2023
2db59cf
Add explanation to unchecked logic
adaki2004 Aug 23, 2023
d385380
Likn to Lib1559Math high level description
adaki2004 Aug 23, 2023
daa9b30
enable IERC1271 to be a prover
dantaik Aug 23, 2023
49bec2b
access control docs
adaki2004 Aug 23, 2023
e26a24d
Merge branch 'prover_abstraction_and_protocol_simplification' into au…
adaki2004 Aug 23, 2023
c58d193
Added dependency and ownership update functions
adaki2004 Aug 24, 2023
4130bd0
Deployment info to markdown
adaki2004 Aug 24, 2023
1c807c8
allow earlier proofs from other regular provers
dantaik Aug 25, 2023
4b923c3
Merge branch 'prover_abstraction_and_protocol_simplification' into au…
adaki2004 Aug 25, 2023
f19916a
First incident reponse plan
adaki2004 Aug 25, 2023
3357dad
refactor(protocol): remove gasUsed and parentGasUsed (#14582)
dantaik Aug 25, 2023
73322ec
Merge branch 'prover_abstraction_and_protocol_simplification' into au…
adaki2004 Aug 25, 2023
97f080d
Merge branch 'main' into audit_preparation
adaki2004 Aug 28, 2023
3dd1233
Merge branch 'main' into audit_preparation
adaki2004 Aug 28, 2023
a028f92
Fix failing tests and remove simulation
adaki2004 Aug 28, 2023
5f89c49
Workaround approve() race condition and one docu link
adaki2004 Aug 29, 2023
5cbd1cf
Remove increase/decrease allowance since part of ERC20Upgradeable
adaki2004 Aug 29, 2023
3194950
Merge branch 'main' into audit_preparation
adaki2004 Aug 29, 2023
20e9ebc
Merge branch 'main' into audit_preparation
adaki2004 Aug 30, 2023
8b12899
Fix comment
adaki2004 Aug 30, 2023
3832fea
forge fmt formatting
adaki2004 Aug 30, 2023
e39ed1b
Fix typos
adaki2004 Aug 30, 2023
c5f78fc
Merge branch 'main' into audit_preparation
dantaik Aug 31, 2023
20143f0
Merge branch 'main' into audit_preparation
dantaik Aug 31, 2023
77e9639
Update packages/protocol/contracts/L1/libs/LibProving.sol
adaki2004 Aug 31, 2023
b8bbb1b
Merge branch 'main' into audit_preparation
dantaik Aug 31, 2023
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
6 changes: 3 additions & 3 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { PausableUpgradeable } from
import { Proxied } from "../common/Proxied.sol";

/// @title TaikoToken
/// @notice The TaikoToken (TKO) is used for proposing blocks and also for
/// staking in the Taiko protocol. It is an ERC20 token with 8 decimal places of
/// @notice The TaikoToken (TKO), in the protocol is used for prover collateral
/// in the form of bonds. It is an ERC20 token with 18 decimal places of
/// precision.
contract TaikoToken is
EssentialContract,
Expand Down Expand Up @@ -109,7 +109,7 @@ contract TaikoToken is
uint256 amount
)
public
onlyFromNamed("erc20_vault")
onlyFromNamed2("erc20_vault", "taiko")
dantaik marked this conversation as resolved.
Show resolved Hide resolved
{
_burn(from, amount);
}
Expand Down
20 changes: 20 additions & 0 deletions packages/protocol/contracts/L1/libs/LibDepositing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ library LibDepositing {
})
);

// Unchecked is safe:
// - uint64 can store up to ~1.8 * 1e19, which can represent 584K years
// if we are depositing at every second
unchecked {
state.slotA.numEthDeposits++;
}
Expand Down Expand Up @@ -106,6 +109,12 @@ library LibDepositing {
});
uint96 _fee =
deposits[i].amount > fee ? fee : deposits[i].amount;

// Unchecked is safe:
// - _fee cannot be bigger than deposits[i].amount
// - all values are in the same range (uint96) except loop
// counter, which obviously cannot be bigger than uint95
// otherwise the function would be gassing out.
unchecked {
deposits[i].amount -= _fee;
totalFee += _fee;
Expand All @@ -118,6 +127,10 @@ library LibDepositing {
state.ethDeposits[state.slotA.numEthDeposits
% config.ethDepositRingBufferSize] =
_encodeEthDeposit(feeRecipient, totalFee);

// Unchecked is safe:
// - uint64 can store up to ~1.8 * 1e19, which can represent 584K
// years if we are depositing at every second
unchecked {
state.slotA.numEthDeposits++;
}
Expand All @@ -138,6 +151,13 @@ library LibDepositing {
view
returns (bool)
{
// Unchecked is safe:
// - both numEthDeposits and state.slotA.nextEthDepositToProcess are
// indexes. One is tracking all deposits (numEthDeposits: unprocessed)
// and the next to be processed, so nextEthDepositToProcess cannot be
// bigger than numEthDeposits
// - ethDepositRingBufferSize cannot be 0 by default (validity checked
// in LibVerifying)
unchecked {
return amount >= config.ethDepositMinAmount
&& amount <= config.ethDepositMaxAmount
Expand Down
10 changes: 10 additions & 0 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ library LibProposing {

TaikoToken tt = TaikoToken(resolver.resolve("taiko_token", false));
if (state.taikoTokenBalances[assignment.prover] >= config.proofBond) {
// Safe, see the above constraint
unchecked {
state.taikoTokenBalances[assignment.prover] -= config.proofBond;
}
Expand Down Expand Up @@ -127,6 +128,11 @@ library LibProposing {
uint256 reward;
if (config.proposerRewardPerSecond > 0 && config.proposerRewardMax > 0)
{
// Unchecked is safe:
// - block.timestamp is always greater than block.proposedAt
// (proposed in the past)
// - 1x state.taikoTokenBalances[addr] uint256 could theoretically
// store the whole token supply
unchecked {
uint256 blockTime = block.timestamp
- state.blocks[(b.numBlocks - 1) % config.blockRingBufferSize]
Expand All @@ -152,6 +158,10 @@ library LibProposing {
}

// Init the metadata
// Unchecked is safe:
// - equation is done among same variable types
// - incrementation (state.slotB.numBlocks++) is fine for 584K years if
// we propose at every second
unchecked {
meta.id = b.numBlocks;
meta.timestamp = uint64(block.timestamp);
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ library LibProving {
if (tid == 0) {
tid = blk.nextTransitionId;

// Unchecked is safe:
// - Not realistic 65K different fork choice per block will be
// proven and none of them is valid
adaki2004 marked this conversation as resolved.
Show resolved Hide resolved
unchecked {
++blk.nextTransitionId;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibTaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ library LibTaikoToken {
{
uint256 balance = state.taikoTokenBalances[msg.sender];
if (balance < amount) revert L1_INSUFFICIENT_TOKEN();

// Unchecked is safe per above check
unchecked {
state.taikoTokenBalances[msg.sender] -= amount;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ library LibVerifying {
>= type(uint96).max / config.ethDepositMaxCountPerBlock
) revert L1_INVALID_CONFIG();

// Unchecked is safe:
// - assignment is within ranges
// - block.timestamp will still be within uint64 range for the next
// 500K+ years.
unchecked {
uint64 timeNow = uint64(block.timestamp);

Expand Down Expand Up @@ -114,6 +118,11 @@ library LibVerifying {
TaikoData.Transition memory tz;

uint64 processed;

// Unchecked is safe:
// - assignment is within ranges
// - blockId and processed values incremented will still be OK in the
// next 584K years if we verifying one block per every second
unchecked {
++blockId;

Expand Down
6 changes: 6 additions & 0 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ contract TaikoL2 is EssentialContract, TaikoL2Signer, ICrossChainSync {
returns (bytes32 prevPIH, bytes32 currPIH)
{
bytes32[256] memory inputs;

// Unchecked is safe because it cannot overflow.
unchecked {
// Put the previous 255 blockhashes (excluding the parent's) into a
// ring buffer.
Expand Down Expand Up @@ -307,6 +309,10 @@ contract TaikoL2 is EssentialContract, TaikoL2Signer, ICrossChainSync {
view
returns (uint256 _basefee, uint64 _gasExcess)
{
// Unchecked is safe because:
// - gasExcess is capped at uint64 max ever, so multiplying with a
// uint32 value is safe
// - 'excess' is bigger than 'issued'
unchecked {
uint256 issued = timeSinceParent * config.gasIssuedPerSecond;
uint256 excess = (uint256(gasExcess) + parentGasUsed).max(issued);
Expand Down
67 changes: 67 additions & 0 deletions packages/protocol/contracts/actors_privileges_deployments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Actors, Privileges, and Upgradeable Procedures Documentation

## Introduction

This document provides a comprehensive overview of the actors involved in the smart contract system and outlines their respective privileges and roles.
Different `roles` (we call them `domain`) are granted via `AddressManager` contract's `setAddress()` function. Idea is very similar Optimism's `AddressManager` except that we use the `chainId + domainName` as the key for a given address. We need so, because for bridging purposes, the destination chain's bridge address needs to be inculded signaling the messgae hash is tamper-proof.
Every contract which needs some role-based authentication, needs to inherit from `AddressResolver` contract, which will serve as a 'middleman/lookup' by querying the `AddressManager` per given address is allowed to act on behalf of that domain or not.

## 1. Domains (≈role per chainId)

In the context of the smart contract system, various actors play distinct roles. Each actor is associated with specific responsibilities and privileges within the system. When there is a modifier called `onlyFromNamed` or `onlyFromNamed2`, it means we are checking access through the before mentioned contracts (`AddressResolver` and `AddressManager`), and one function maximum allows up to 2 domains (right now, but it might change when e.g.`DAO` is set up) can be given access.

### 1.1 Taiko

- **Role**: This domain role is given to TaikoL1 smart contract.
- **Privileges**:
- Possibility to mint/burn the taiko token
- Possibility to mint/burn erc20 tokens (I think we should remove this privilege)

### 1.2 Bridge

- **Role**: This domain role is given to Bridge smart contracts (both chains).
- **Privileges**:
- The right to trigger transfering/minting the tokens (on destination chain) (be it ERC20, ERC721, ERC1155) from the vault contracts
- The right to trigger releasing the custodied assets on the source chain (if bridging is not successful)

### 1.3 ERCXXX_Vault

- **Role**: This role is givne to respective token vault contracts (ERC20, ERC721, ERC1155)
- **Privileges**:
- Part of token briding, the possibility to burn and mint the respective standard tokens (no autotelic minting/burning)

## 2. Different access modifiers

Beside the `onlyFromNamed` or `onlyFromNamed2` modifiers, we have others such as:

### 2.1 onlyOwner

- **Description**: Only owner can be granted access.
- **Associated contracts**: TaikoToken, AddressManager, EtherVault

### 2.2 onlyAuthorized

- **Description**: Only authorized (by owner) can be granted access - the address shall be a smart contract. (`Bridge` in our case)
- **Associated Actors**: EtherVault

## 3. Upgradeable Procedures

The smart contract system incorporates upgradeable procedures to ensure flexibility and security. These procedures adhere to the following principles:

### 3.1 Deployment Scripts

- Deployment scripts are visible in the `packages/protocol/scripts` folder, encompassing both deployment and upgrade scripts for easy reference and replication.

### 3.2 Transparent Upgradeability

- Upgradeability is based on the Transparent Upgradeability Proxy by OpenZeppelin, ensuring that contract upgrades are secure and transparent to all stakeholders.

### 3.3 Ownership Transition

- Currently, on testnets, some privileges (like `onlyOwner`) are assigned to externally owned accounts (EOAs) for easier testing. However, it is essential to note that `TimeLockController` contracts will be the owners at a later stage.

## Conclusion

Clear documentation of actors and their privileges, combined with robust upgradeable procedures, is essential for smart contract systems, especially for based rollups. This documentation ensures that all stakeholders understand their roles and responsibilities within the system and guarantees its adaptability and security over time.

Please ensure that this document is kept up to date as changes are made to the smart contract system and its actors or privileges.
5 changes: 5 additions & 0 deletions packages/protocol/contracts/libs/Lib1559Math.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { SafeCastUpgradeable } from
/// @title Lib1559Math
/// @dev This library provides utilities related to the L2 EIP-1559
/// implementation.
/// See formulas described in the whitepaper
/// https://taikoxyz.github.io/taiko-mono/taiko-whitepaper.pdf
/// From section: "9.6. Rate Limiting using EIP-1559."
/// Additional info about the arithmetic formula:
/// https://github.com/taikoxyz/taiko-mono/blob/main/packages/protocol/docs/L2EIP1559.md
library Lib1559Math {
using SafeCastUpgradeable for uint256;

Expand Down
57 changes: 57 additions & 0 deletions packages/protocol/incident_response_plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Incident Response Plan

This document outlines the incident response plan for our smart contract system, addressing both ChainOps and SmartContract-related incidents. It provides a list of potential incidents and instructions on how to handle them effectively.

## ChainOps-Related Incidents

### 1. Congested Network

**Description**: A congested network can lead to (slow transaction confirmations, higher gas fees, slashing provers) impacting the performance of the rollup.

**Response**:

1. Check Grafana Alerts: Monitor the Grafana dashboard at [Grafana Dashboard](https://grafana.test.taiko.xyz/) for alerts related to network congestion.
2. Engineer on Duty: The engineer on duty should be alerted automatically through the monitoring system.
3. Mitigation: If network congestion is detected, consider adjusting gas prices or scheduling transactions during off-peak times.

### 2. Chain Head Number Stop Increasing

**Description**: When the chain head stops, it indicates a potential issue with the operation of the network.

**Response**:

1. Grafana Alerts: Monitor Grafana for alerts regarding the chain head number.
2. Engineer on Duty: The engineer on duty should receive automatic alerts.
3. Investigation: Investigate the root cause by analyzing blockchain data and logs.
4. Collaboration: Collaborate with blockchain network administrators if necessary for a solution.

### 3. Latest Verified Block Number Stop Increasing

**Description**: A halt in the increase of the latest verified block number may indicate a problem with the operation of the network.

**Response**:

1. Grafana Alerts: Keep an eye on Grafana alerts regarding the latest verified block number.
2. Engineer on Duty: The engineer on duty should be automatically notified.
3. Troubleshooting: Investigate the node's syncing process and take corrective actions to ensure it resumes.

## SmartContract-Related Incidents

### 1. Unforeseeable Smart Contract Issue

**Description**: Unforeseeable issues with the smart contracts may arise, which were not identified during the audit.

**Response**:

1. Incident Report: Create a detailed incident report, including the symptoms, affected contracts, and any relevant transaction or event data.
2. Escalation: Notify the development and audit teams for immediate attention.
3. Isolation: If necessary, isolate the affected smart contracts or functions to prevent further damage.
4. Analysis: Collaborate with the audit team to analyze and diagnose the issue.
5. Resolution: Implement necessary fixes, upgrades, or rollbacks as per the audit team's recommendations.
6. Communication: Keep stakeholders informed throughout the incident resolution process.

## Conclusion

This incident response plan ensures that potential incidents, whether related to ChainOps or SmartContracts, are promptly detected and addressed. The plan relies on monitoring tools like Grafana and the availability of an engineer on duty. In the case of unforeseeable smart contract issues, a systematic incident resolution process is in place to minimize the impact on the system's functionality and security.

Regular testing and review of this plan are recommended to ensure its effectiveness in responding to incidents as the system evolves.
42 changes: 42 additions & 0 deletions packages/protocol/script/upgrade/SetAddressManager.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
// _____ _ _ _ _
// |_ _|_ _(_) |_____ | | __ _| |__ ___
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-<
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/

pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "forge-std/console2.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";
import "./UpgradeScript.s.sol";

interface IEssentialContract {
function setAddressManager(address newAddressManager) external;
}
/// @notice Each contract (which inherits EssentialContract) is having a
/// setAddressManager() setter. In such case AddressManager needs to get
/// changed, we need a quick way to update it.
///
/// Invokaction example:
/// forge script SetAddressManager --sig "run(address,address)" <address>
/// <address>

contract SetAddressManager is UpgradeScript {
function run(
address essentialContract,
address newAddressManager
)
external
setUp
{
IEssentialContract(essentialContract).setAddressManager(
newAddressManager
);
console2.log(
Brechtpd marked this conversation as resolved.
Show resolved Hide resolved
essentialContract,
" contract set a new AddressManagerAddress:",
address(newAddressManager)
);
}
}
45 changes: 45 additions & 0 deletions packages/protocol/script/upgrade/TransferOwnership.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
// _____ _ _ _ _
// |_ _|_ _(_) |_____ | | __ _| |__ ___
// | |/ _` | | / / _ \ | |__/ _` | '_ (_-<
// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/

pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "forge-std/console2.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";
import "./UpgradeScript.s.sol";

interface IOwnable {
function transferOwnership(address newOwner) external;
}
/// @notice As "single" owner is not desirable for protocols we need to
/// transfer ownership. BUT! Transferring ownership to a multisig also
/// does not help too much if the protocol wants to give some time for
/// the users to exit before an upgrade is effective. So implementing a
/// delay (L2Beat prefers 7 days) is essential.
/// So the usual approach is the following:
/// 1. Transfer ownership to TimeLockController contract which enforces the
/// delay
/// 2. The ownership of the TimeLockController contract shall be a multisig/DAO

/// Invokaction example:
/// forge script TransferOwnership --sig "run(address,address)" <address>
/// <address>
contract TransferOwnership is UpgradeScript {
function run(
address contractAddr,
address timeLockContract
)
external
setUp
{
IOwnable(contractAddr).transferOwnership(timeLockContract);
console2.log(
contractAddr,
" contract has a new owner:",
address(timeLockContract)
);
}
}
Loading