Skip to content

Commit

Permalink
Merge branch 'main' into release-please--branches--main--components--…
Browse files Browse the repository at this point in the history
…relayer
  • Loading branch information
dionysuzx authored Feb 16, 2024
2 parents 09a86cf + 6803a91 commit 9696523
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 83 deletions.
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/cyberhorsey/webutils v0.0.0-20230314183728-56890c6ddbe7
github.com/davecgh/go-spew v1.1.1
github.com/ethereum/go-ethereum v1.13.1
github.com/go-git/go-git/v5 v5.7.0
github.com/go-git/go-git/v5 v5.11.0
github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a
github.com/google/uuid v1.3.1
github.com/joho/godotenv v1.4.0
Expand Down Expand Up @@ -39,16 +39,16 @@ require (
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -68,6 +68,7 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
Expand All @@ -80,7 +81,7 @@ require (
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
Expand All @@ -97,7 +98,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
Expand Down Expand Up @@ -137,12 +138,12 @@ require (
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
Expand All @@ -154,7 +155,7 @@ require (
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
Expand Down
55 changes: 30 additions & 25 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ contract TaikoL1 is
(meta, depositsProcessed) =
LibProposing.proposeBlock(state, config, AddressResolver(this), params, txList);

_verifyBlocks(config, config.maxBlocksToVerifyPerProposal);
if (!state.slotB.provingPaused) {
_verifyBlocks(config, config.maxBlocksToVerifyPerProposal);
}
}

/// @inheritdoc ITaikoL1
Expand Down
3 changes: 0 additions & 3 deletions packages/protocol/contracts/L1/hooks/AssignmentHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ contract AssignmentHook is EssentialContract, IHook {

// The proposer irrevocably pays a fee to the assigned prover, either in
// Ether or ERC20 tokens.
uint256 totalFeeETH = input.tip;
if (assignment.feeToken == address(0)) {
totalFeeETH += proverFee;

// Paying Ether
blk.assignedProver.sendEther(proverFee, MAX_GAS_PAYING_PROVER);
} else {
Expand Down
42 changes: 28 additions & 14 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ contract Bridge is EssentialContract, IBridge {
// This is the keccak256 hash of "bridge.ctx_slot"
bytes32 private constant _CTX_SLOT =
0xe4ece82196de19aabe639620d7f716c433d1348f96ce727c9989a982dbadc2b9;
// Place holder value when not using transient storage
uint256 internal constant PLACEHOLDER = type(uint256).max;

uint128 public nextMessageId; // slot 1
mapping(bytes32 msgHash => bool recalled) private __isMessageRecalled; // slot 2, deprecated
Expand Down Expand Up @@ -443,7 +445,7 @@ contract Bridge is EssentialContract, IBridge {
/// @inheritdoc IBridge
function context() public view returns (Context memory ctx) {
ctx = _loadContext();
if (ctx.msgHash == 0) {
if (ctx.msgHash == 0 || ctx.msgHash == bytes32(PLACEHOLDER)) {
revert B_INVALID_CONTEXT();
}
}
Expand Down Expand Up @@ -543,29 +545,41 @@ contract Bridge is EssentialContract, IBridge {

/// @notice Resets the call context
function _resetContext() private {
_storeContext(bytes32(0), address(0), uint64(0));
if (block.chainid == 1) {
_storeContext(bytes32(0), address(0), uint64(0));
} else {
_storeContext(bytes32(PLACEHOLDER), address(uint160(PLACEHOLDER)), uint64(PLACEHOLDER));
}
}

/// @notice Stores the call context
function _storeContext(bytes32 msgHash, address from, uint64 srcChainId) private {
assembly {
tstore(_CTX_SLOT, msgHash)
tstore(add(_CTX_SLOT, 1), from)
tstore(add(_CTX_SLOT, 2), srcChainId)
if (block.chainid == 1) {
assembly {
tstore(_CTX_SLOT, msgHash)
tstore(add(_CTX_SLOT, 1), from)
tstore(add(_CTX_SLOT, 2), srcChainId)
}
} else {
_ctx = Context({ msgHash: msgHash, from: from, srcChainId: srcChainId });
}
}

/// @notice Loads the call context
function _loadContext() private view returns (Context memory) {
bytes32 msgHash;
address from;
uint64 srcChainId;
assembly {
msgHash := tload(_CTX_SLOT)
from := tload(add(_CTX_SLOT, 1))
srcChainId := tload(add(_CTX_SLOT, 2))
if (block.chainid == 1) {
bytes32 msgHash;
address from;
uint64 srcChainId;
assembly {
msgHash := tload(_CTX_SLOT)
from := tload(add(_CTX_SLOT, 1))
srcChainId := tload(add(_CTX_SLOT, 2))
}
return Context({ msgHash: msgHash, from: from, srcChainId: srcChainId });
} else {
return _ctx;
}
return Context({ msgHash: msgHash, from: from, srcChainId: srcChainId });
}

/// @notice Checks if the signal was received.
Expand Down
30 changes: 19 additions & 11 deletions packages/protocol/contracts/common/OwnerUUPSUpgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract contract OwnerUUPSUpgradable is UUPSUpgradeable, OwnableUpgradeable {
bytes32 private constant _REENTRY_SLOT =
0xa5054f728453d3dbe953bdc43e4d0cb97e662ea32d7958190f3dc2da31d9721a;

uint8 private _reentryDeprecated; // slot 1
uint8 private _reentry; // slot 1
uint8 private _paused;
uint256[49] private __gap;

Expand Down Expand Up @@ -88,21 +88,29 @@ abstract contract OwnerUUPSUpgradable is UUPSUpgradeable, OwnableUpgradeable {
_paused = _FALSE;
}

function _inNonReentrant() internal view returns (bool) {
return _loadReentryLock() == _TRUE;
}

// Stores the reentry lock
function _storeReentryLock(uint8 reentry) private {
assembly {
tstore(_REENTRY_SLOT, reentry)
function _storeReentryLock(uint8 reentry) internal virtual {
if (block.chainid == 1) {
assembly {
tstore(_REENTRY_SLOT, reentry)
}
} else {
_reentry = reentry;
}
}

// Loads the reentry lock
function _loadReentryLock() private view returns (uint8 reentry) {
assembly {
reentry := tload(_REENTRY_SLOT)
function _loadReentryLock() internal view virtual returns (uint8 reentry) {
if (block.chainid == 1) {
assembly {
reentry := tload(_REENTRY_SLOT)
}
} else {
reentry = _reentry;
}
}

function _inNonReentrant() internal view returns (bool) {
return _loadReentryLock() == _TRUE;
}
}
17 changes: 15 additions & 2 deletions packages/protocol/contracts/signal/SignalService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,49 @@ contract SignalService is EssentialContract, ISignalService {
bytes[] storageProof;
}

uint256[50] private __gap;
mapping(address => bool) public isRelayerAuthorized;
uint256[49] private __gap;

event SnippetRelayed(
uint64 indexed chainid, bytes32 indexed kind, bytes32 data, bytes32 signal
);

event RelayerAuthorized(address indexed addr, bool authrized);

error SS_EMPTY_PROOF();
error SS_INVALID_APP();
error SS_INVALID_LAST_HOP_CHAINID();
error SS_INVALID_MID_HOP_CHAINID();
error SS_INVALID_PARAMS();
error SS_INVALID_SIGNAL();
error SS_LOCAL_CHAIN_DATA_NOT_FOUND();
error SS_UNAUTHORIZED();
error SS_UNSUPPORTED();

/// @dev Initializer to be called after being deployed behind a proxy.
function init(address _addressManager) external initializer {
__Essential_init(_addressManager);
}

/// @dev Authorize or deautohrize an address for calling relayChainData
/// @dev Note that addr is supposed to be TaikoL1 and TaikoL1 contracts deployed locally.
function authorizeRelayer(address addr, bool toAuthorize) external onlyOwner {
if (isRelayerAuthorized[addr] == toAuthorize) revert SS_INVALID_PARAMS();
isRelayerAuthorized[addr] = toAuthorize;

emit RelayerAuthorized(addr, toAuthorize);
}

/// @inheritdoc ISignalService
function relayChainData(
uint64 chainId,
bytes32 kind,
bytes32 data
)
external
onlyFromNamed("taiko")
returns (bytes32 slot)
{
if (!isRelayerAuthorized[msg.sender]) revert SS_UNAUTHORIZED();
return _relayChainData(chainId, kind, data);
}

Expand Down
5 changes: 4 additions & 1 deletion packages/protocol/script/DeployOnL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ contract DeployOnL1 is DeployCapability {
addressNotNull(taikoL1Addr, "taikoL1Addr");
TaikoL1 taikoL1 = TaikoL1(payable(taikoL1Addr));

if (vm.envAddress("SHARED_ADDRESS_MANAGER") == address(0)) {
SignalService(signalServiceAddr).authorizeRelayer(taikoL1Addr, true);
}

uint64 l2ChainId = taikoL1.getConfig().chainId;
require(l2ChainId != block.chainid, "same chainid");

Expand All @@ -116,7 +120,6 @@ contract DeployOnL1 is DeployCapability {
copyRegister(rollupAddressManager, sharedAddressManager, "taiko_token");
copyRegister(rollupAddressManager, sharedAddressManager, "signal_service");
copyRegister(rollupAddressManager, sharedAddressManager, "bridge");
copyRegister(sharedAddressManager, rollupAddressManager, "taiko");

address proposer = vm.envAddress("PROPOSER");
if (proposer != address(0)) {
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/test/L1/TaikoL1TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ abstract contract TaikoL1TestBase is TaikoTest {
data: abi.encodeCall(SignalService.init, address(addressManager))
})
);
ss.authorizeRelayer(address(L1), true);

pv = PseZkVerifier(
deployProxy({
Expand Down
18 changes: 11 additions & 7 deletions packages/protocol/test/L2/TaikoL2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ contract TestTaikoL2 is TaikoTest {
data: abi.encodeCall(AddressManager.init, ())
});

deployProxy({
name: "signal_service",
impl: address(new SignalService()),
data: abi.encodeCall(SignalService.init, (addressManager)),
registerTo: addressManager,
owner: address(0)
});
SignalService ss = SignalService(
deployProxy({
name: "signal_service",
impl: address(new SignalService()),
data: abi.encodeCall(SignalService.init, (addressManager)),
registerTo: addressManager,
owner: address(0)
})
);

uint64 gasExcess = 0;
uint8 quotient = 8;
Expand All @@ -55,6 +57,8 @@ contract TestTaikoL2 is TaikoTest {

L2.setConfigAndExcess(TaikoL2.Config(gasTarget, quotient), gasExcess);

ss.authorizeRelayer(address(L2), true);

gasExcess = 195_420_300_100;

vm.roll(block.number + 1);
Expand Down
18 changes: 11 additions & 7 deletions packages/protocol/test/L2/TaikoL2NoFeeCheck.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ contract TestTaikoL2NoFeeCheck is TaikoTest {
data: abi.encodeCall(AddressManager.init, ())
});

deployProxy({
name: "signal_service",
impl: address(new SignalService()),
data: abi.encodeCall(SignalService.init, (addressManager)),
registerTo: addressManager,
owner: address(0)
});
SignalService ss = SignalService(
deployProxy({
name: "signal_service",
impl: address(new SignalService()),
data: abi.encodeCall(SignalService.init, (addressManager)),
registerTo: addressManager,
owner: address(0)
})
);

uint64 gasExcess = 0;
uint8 quotient = 8;
Expand All @@ -55,6 +57,8 @@ contract TestTaikoL2NoFeeCheck is TaikoTest {

L2.setConfigAndExcess(TaikoL2.Config(gasTarget, quotient), gasExcess);

ss.authorizeRelayer(address(L2), true);

vm.roll(block.number + 1);
vm.warp(block.timestamp + 30);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/protocol/test/signal/SignalService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract TestSignalService is TaikoTest {
);

taiko = randAddress();
addressManager.setAddress(uint64(block.chainid), "taiko", taiko);
signalService.authorizeRelayer(taiko, true);
vm.stopPrank();
}

Expand Down Expand Up @@ -298,6 +298,13 @@ contract TestSignalService is TaikoTest {
signal: randBytes32(),
proof: abi.encode(proofs)
});

vm.prank(Alice);
signalService.authorizeRelayer(taiko, false);

vm.expectRevert(SignalService.SS_UNAUTHORIZED.selector);
vm.prank(taiko);
signalService.relayChainData(srcChainId, LibSignals.SIGNAL_ROOT, proofs[0].rootHash);
}

function test_SignalService_proveSignalReceived_one_hop_state_root() public {
Expand Down
Loading

0 comments on commit 9696523

Please sign in to comment.