Skip to content

Commit f5587dc

Browse files
Move the switching logic between batchers inside the Batch Authenticator contract.
1 parent cad7ab5 commit f5587dc

File tree

13 files changed

+396
-194
lines changed

13 files changed

+396
-194
lines changed

espresso/scripts/prepare-allocs.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ op-deployer init --l1-chain-id "${L1_CHAIN_ID}" \
7474

7575
dasel put -f "${DEPLOYER_DIR}/intent.toml" -s .chains.[0].espressoEnabled -t bool -v true
7676

77+
# Configure Espresso batchers for devnet. We reuse the operator address for both
78+
# the non-TEE and TEE batchers to ensure they are non-zero and consistent.
7779
dasel put -f "${DEPLOYER_DIR}/intent.toml" -s .chains.[0].nonTeeBatcher -v "${OPERATOR_ADDRESS}"
80+
dasel put -f "${DEPLOYER_DIR}/intent.toml" -s .chains.[0].teeBatcher -v "${OPERATOR_ADDRESS}"
7881
dasel put -f "${DEPLOYER_DIR}/intent.toml" -s .l1ContractsLocator -v "${ARTIFACTS_DIR}"
7982
dasel put -f "${DEPLOYER_DIR}/intent.toml" -s .l2ContractsLocator -v "${ARTIFACTS_DIR}"
8083
dasel put -f "${DEPLOYER_DIR}/intent.toml" -s .opcmAddress -v `jq -r .opcmAddress < ${DEPLOYER_DIR}/bootstrap_implementations.json`

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ golint:
3030
compile-contracts:
3131
(cd packages/contracts-bedrock && just build-dev)
3232

33+
run-l1-espresso-contracts-tests: compile-contracts
34+
(cd packages/contracts-bedrock && forge test --match-path "/**/test/L1/Batch*.t.sol")
35+
3336
compile-contracts-fast:
3437
(cd packages/contracts-bedrock && forge build --offline --skip "/**/test/**")
3538

op-batcher/bindings/batch_authenticator.go

Lines changed: 99 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

op-batcher/bindings/batch_inbox.go

Lines changed: 4 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

op-deployer/pkg/deployer/opcm/espresso.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type DeployEspressoInput struct {
1919
Salt common.Hash
2020
NitroTEEVerifier common.Address
2121
NonTeeBatcher common.Address
22+
TeeBatcher common.Address
2223
}
2324

2425
type DeployEspressoOutput struct {

op-deployer/pkg/deployer/pipeline/espresso.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func DeployEspresso(env *Env, intent *state.Intent, st *state.State, chainID com
5151
Salt: st.Create2Salt,
5252
NitroTEEVerifier: nvo.NitroTEEVerifierAddress,
5353
NonTeeBatcher: chainIntent.NonTeeBatcher,
54+
TeeBatcher: chainIntent.TeeBatcher,
5455
}, batchAuthenticatorOwnwerAddress)
5556
if err != nil {
5657
return fmt.Errorf("failed to deploy espresso contracts: %w", err)

packages/contracts-bedrock/interfaces/L1/IBatchAuthenticator.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ interface IBatchAuthenticator {
2323

2424
function owner() external view returns (address);
2525

26-
function preApprovedBatcher() external view returns (address);
26+
function teeBatcher() external view returns (address);
27+
28+
function nonTeeBatcher() external view returns (address);
2729

2830
function registerSigner(
2931
bytes memory attestationTbs,
@@ -36,9 +38,14 @@ interface IBatchAuthenticator {
3638

3739
function validBatchInfo(bytes32) external view returns (bool);
3840

41+
function activeIsTee() external view returns (bool);
42+
43+
function switchBatcher() external;
44+
3945
function __constructor__(
4046
address _espressoTEEVerifier,
41-
address _preApprovedBatcher,
47+
address _teeBatcher,
48+
address _nonTeeBatcher,
4249
address _owner
4350
) external;
4451
}

packages/contracts-bedrock/interfaces/L1/IBatchInbox.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ interface IBatchInbox {
66

77
function version() external view returns (string memory);
88

9-
function __constructor__(address _nonTeeBatcher, address _batchAuthenticator, address _owner) external;
9+
function __constructor__(address _batchAuthenticator, address _owner) external;
1010
}

packages/contracts-bedrock/scripts/deploy/DeployEspresso.s.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ contract DeployEspressoInput is BaseDeployIO {
1616
bytes32 internal _salt;
1717
address internal _nitroTEEVerifier;
1818
address internal _nonTeeBatcher;
19+
address internal _teeBatcher;
1920

2021
function set(bytes4 _sel, bytes32 _val) public {
2122
if (_sel == this.salt.selector) _salt = _val;
@@ -27,6 +28,8 @@ contract DeployEspressoInput is BaseDeployIO {
2728
_nitroTEEVerifier = _val;
2829
} else if (_sel == this.nonTeeBatcher.selector) {
2930
_nonTeeBatcher = _val;
31+
} else if (_sel == this.teeBatcher.selector) {
32+
_teeBatcher = _val;
3033
} else {
3134
revert("DeployEspressoInput: unknown selector");
3235
}
@@ -44,6 +47,10 @@ contract DeployEspressoInput is BaseDeployIO {
4447
function nonTeeBatcher() public view returns (address) {
4548
return _nonTeeBatcher;
4649
}
50+
51+
function teeBatcher() public view returns (address) {
52+
return _teeBatcher;
53+
}
4754
}
4855

4956
contract DeployEspressoOutput is BaseDeployIO {
@@ -97,7 +104,8 @@ contract DeployEspresso is Script {
97104
_salt: salt,
98105
_args: DeployUtils.encodeConstructor(
99106
abi.encodeCall(
100-
IBatchAuthenticator.__constructor__, (address(teeVerifier), input.nonTeeBatcher(), owner)
107+
IBatchAuthenticator.__constructor__,
108+
(address(teeVerifier), input.teeBatcher(), input.nonTeeBatcher(), owner)
101109
)
102110
)
103111
})
@@ -135,7 +143,7 @@ contract DeployEspresso is Script {
135143
_name: "BatchInbox",
136144
_salt: salt,
137145
_args: DeployUtils.encodeConstructor(
138-
abi.encodeCall(IBatchInbox.__constructor__, (input.nonTeeBatcher(), address(batchAuthenticator), owner))
146+
abi.encodeCall(IBatchInbox.__constructor__, (address(batchAuthenticator), owner))
139147
)
140148
})
141149
);

packages/contracts-bedrock/src/L1/BatchAuthenticator.sol

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pragma solidity ^0.8.0;
44
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
55
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
66
import { ISemver } from "interfaces/universal/ISemver.sol";
7-
import { EspressoTEEVerifier } from "@espresso-tee-contracts/EspressoTEEVerifier.sol";
87
import { IEspressoTEEVerifier } from "@espresso-tee-contracts/interface/IEspressoTEEVerifier.sol";
98

109
interface INitroValidator {
@@ -22,22 +21,48 @@ contract BatchAuthenticator is ISemver, Ownable {
2221
/// @notice Mapping of batches verified by this contract
2322
mapping(bytes32 => bool) public validBatchInfo;
2423

25-
address public immutable preApprovedBatcher;
24+
/// @notice Address of the TEE batcher whose signatures may authenticate batches.
25+
address public immutable teeBatcher;
2626

27-
EspressoTEEVerifier public immutable espressoTEEVerifier;
27+
/// @notice Address of the non-TEE (fallback) batcher that can post when TEE is inactive.
28+
address public immutable nonTeeBatcher;
29+
30+
IEspressoTEEVerifier public immutable espressoTEEVerifier;
2831
INitroValidator public immutable nitroValidator;
2932

30-
constructor(EspressoTEEVerifier _espressoTEEVerifier, address _preApprovedBatcher, address _owner) Ownable() {
33+
/// @notice Flag indicating which batcher is currently active.
34+
/// @dev When true the TEE batcher is active; when false the non-TEE batcher is active.
35+
bool public activeIsTee;
36+
37+
constructor(
38+
IEspressoTEEVerifier _espressoTEEVerifier,
39+
address _teeBatcher,
40+
address _nonTeeBatcher,
41+
address _owner
42+
)
43+
Ownable()
44+
{
45+
require(_teeBatcher != address(0), "BatchAuthenticator: zero tee batcher");
46+
require(_nonTeeBatcher != address(0), "BatchAuthenticator: zero non-tee batcher");
47+
3148
espressoTEEVerifier = _espressoTEEVerifier;
32-
preApprovedBatcher = _preApprovedBatcher;
49+
teeBatcher = _teeBatcher;
50+
nonTeeBatcher = _nonTeeBatcher;
3351
nitroValidator = INitroValidator(address(espressoTEEVerifier.espressoNitroTEEVerifier()));
52+
// By default, start with the TEE batcher active.
53+
activeIsTee = true;
3454
_transferOwnership(_owner);
3555
}
3656

3757
function decodeAttestationTbs(bytes memory attestation) external view returns (bytes memory, bytes memory) {
3858
return nitroValidator.decodeAttestationTbs(attestation);
3959
}
4060

61+
/// @notice Toggles the active batcher between the TEE and non-TEE batcher.
62+
function switchBatcher() external onlyOwner {
63+
activeIsTee = !activeIsTee;
64+
}
65+
4166
function authenticateBatchInfo(bytes32 commitment, bytes calldata _signature) external {
4267
// https://github.com/ethereum/go-ethereum/issues/19751#issuecomment-504900739
4368
bytes memory signature = _signature;
@@ -52,7 +77,7 @@ contract BatchAuthenticator is ISemver, Ownable {
5277
revert("Invalid signature");
5378
}
5479

55-
if (!espressoTEEVerifier.espressoNitroTEEVerifier().registeredSigners(signer) && signer != preApprovedBatcher) {
80+
if (!espressoTEEVerifier.espressoNitroTEEVerifier().registeredSigners(signer) && signer != teeBatcher) {
5681
revert("Invalid signer");
5782
}
5883

0 commit comments

Comments
 (0)