Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
21 changes: 10 additions & 11 deletions espresso/environment/enclave_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const (
ENCLAVE_INTERMEDIATE_IMAGE_TAG = "op-batcher-enclave:tests"
ENCLAVE_IMAGE_TAG = "op-batcher-enclaver:tests"
ESPRESSO_ENABLE_ENCLAVE_TESTS = "ESPRESSO_RUN_ENCLAVE_TESTS"

// TeeTypeNitro corresponds to IEspressoTEEVerifier.TeeType.NITRO enum value
TeeTypeNitro uint8 = 1
// ServiceTypeBatchPoster corresponds to ServiceType.BatchPoster enum value
ServiceTypeBatchPoster uint8 = 0
)

// Skips the calling test if `ESPRESSO_ENABLE_ENCLAVE_TESTS` is not set.
Expand Down Expand Up @@ -274,21 +279,15 @@ func RegisterEnclaveHash(ctx context.Context, sys *e2esys.System, pcr0Bytes []by
return fmt.Errorf("failed to create verifier: %w", err)
}

nitroVerifierAddress, err := verifier.EspressoNitroTEEVerifier(&bind.CallOpts{})
if err != nil {
return fmt.Errorf("failed to get nitro verifier address: %w", err)
}

nitroVerifier, err := bindings.NewEspressoNitroTEEVerifier(nitroVerifierAddress, l1Client)
if err != nil {
return fmt.Errorf("failed to create nitro verifier: %w", err)
}

opts, err := bind.NewKeyedTransactorWithChainID(sys.Cfg.Secrets.Deployer, sys.Cfg.L1ChainIDBig())
if err != nil {
return fmt.Errorf("failed to create transactor: %w", err)
}
registrationTx, err := nitroVerifier.SetEnclaveHash(opts, crypto.Keccak256Hash(pcr0Bytes), true)

// SetEnclaveHash must be called through EspressoTEEVerifier wrapper because
// NitroTEEVerifier.setEnclaveHash has onlyTEEVerifier modifier, restricting calls
// to only the TEEVerifier contract. The wrapper has onlyGuardianOrOwner permissions.
registrationTx, err := verifier.SetEnclaveHash(opts, crypto.Keccak256Hash(pcr0Bytes), true, TeeTypeNitro, ServiceTypeBatchPoster)
if err != nil {
return fmt.Errorf("failed to create registration transaction: %w", err)
}
Expand Down
675 changes: 597 additions & 78 deletions op-batcher/bindings/batch_authenticator.go

Large diffs are not rendered by default.

296 changes: 4 additions & 292 deletions op-batcher/bindings/batch_inbox.go

Large diffs are not rendered by default.

1,714 changes: 1,572 additions & 142 deletions op-batcher/bindings/espresso_tee_verifier.go

Large diffs are not rendered by default.

23 changes: 16 additions & 7 deletions op-deployer/pkg/deployer/opcm/espresso.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,33 @@ import (
)

type DeployAWSNitroVerifierInput struct {
EnclaveHash [32]byte
NitroEnclaveVerifier common.Address
TeeVerifierAddress common.Address
ProxyAdminOwner common.Address
}

type DeployAWSNitroVerifierOutput struct {
NitroTEEVerifierAddress common.Address
NitroTEEVerifierProxy common.Address
NitroTEEVerifierImpl common.Address
ProxyAdmin common.Address
}

type DeployEspressoInput struct {
Salt common.Hash
NitroTEEVerifier common.Address
NonTeeBatcher common.Address
TeeBatcher common.Address
Salt common.Hash
NitroTEEVerifier common.Address
SgxTEEVerifier common.Address
NonTeeBatcher common.Address
TeeBatcher common.Address
ProxyAdminOwner common.Address
UseMockTEEVerifier bool
}

type DeployEspressoOutput struct {
BatchAuthenticatorAddress common.Address
BatchInboxAddress common.Address
BatchAuthenticatorAddress common.Address
TeeVerifierProxy common.Address
TeeVerifierImpl common.Address
TeeVerifierProxyAdmin common.Address
}

type DeployEspressoScript struct {
Expand Down
23 changes: 9 additions & 14 deletions op-deployer/pkg/deployer/pipeline/espresso.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,11 @@ func DeployEspresso(env *Env, intent *state.Intent, st *state.State, chainID com
nitroEnclaveVerifierAddress = common.Address{}
}

// get enclave hash from environment variable, fallback to zeroed hash
var enclaveHash [32]byte
if envVar := os.Getenv("ENCLAVE_HASH"); envVar != "" {
copy(enclaveHash[:], common.FromHex(envVar))
lgr.Info("Using enclave hash from ENCLAVE_HASH env var", "hash", common.Bytes2Hex(enclaveHash[:]))
} else {
lgr.Info("ENCLAVE_HASH env var not set, using zeroed hash")
}

var nvo opcm.DeployAWSNitroVerifierOutput
nvo, err = opcm.DeployAWSNitroVerifier(env.L1ScriptHost, opcm.DeployAWSNitroVerifierInput{
EnclaveHash: enclaveHash,
NitroEnclaveVerifier: nitroEnclaveVerifierAddress,
TeeVerifierAddress: common.Address{}, // Will be set after TEEVerifier deployment if needed
ProxyAdminOwner: env.Deployer,
})
if err != nil {
return fmt.Errorf("failed to deploy nitro verifier contracts: %w", err)
Expand All @@ -69,10 +61,13 @@ func DeployEspresso(env *Env, intent *state.Intent, st *state.State, chainID com
}

eo, err = opcm.DeployEspresso(env.L1ScriptHost, opcm.DeployEspressoInput{
Salt: st.Create2Salt,
NitroTEEVerifier: nvo.NitroTEEVerifierAddress,
NonTeeBatcher: chainIntent.NonTeeBatcher,
TeeBatcher: chainIntent.TeeBatcher,
Salt: st.Create2Salt,
NitroTEEVerifier: nvo.NitroTEEVerifierProxy,
SgxTEEVerifier: common.Address{}, // SGX not currently supported
NonTeeBatcher: chainIntent.NonTeeBatcher,
TeeBatcher: chainIntent.TeeBatcher,
ProxyAdminOwner: batchAuthenticatorOwnwerAddress,
UseMockTEEVerifier: nitroEnclaveVerifierAddress == common.Address{},
}, batchAuthenticatorOwnwerAddress)
if err != nil {
return fmt.Errorf("failed to deploy espresso contracts: %w", err)
Expand Down
7 changes: 5 additions & 2 deletions packages/contracts-bedrock/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ ast = true
evm_version = 'cancun'

remappings = [
# Espresso-tee-contracts context-specific remappings (must come before general @openzeppelin remappings)
'lib/espresso-tee-contracts/:@openzeppelin/contracts/=lib/espresso-tee-contracts/lib/openzeppelin-contracts/contracts',
'lib/espresso-tee-contracts/:@openzeppelin/contracts-upgradeable/=lib/espresso-tee-contracts/lib/openzeppelin-contracts-upgradeable/contracts',
'lib/espresso-tee-contracts/:solady/=lib/solady/src',
# General remappings
'@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts',
'@espresso-tee-contracts/=lib/espresso-tee-contracts/src',
'@nitro-validator/=lib/espresso-tee-contracts/lib/nitro-validator/src',
'aws-nitro-enclave-attestation/=lib/espresso-tee-contracts/lib/aws-nitro-enclave-attestation/contracts/src',
'lib/espresso-tee-contracts/:@openzeppelin/contracts/=lib/espresso-tee-contracts/lib/openzeppelin-contracts/contracts',
'lib/espresso-tee-contracts/:solady/=lib/solady/src',
'@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts',
'@openzeppelin/contracts-v5/=lib/openzeppelin-contracts-v5/contracts',
'@rari-capital/solmate/=lib/solmate',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ interface IBatchAuthenticator {
/// @notice Emitted when the non-TEE batcher address is updated.
event NonTeeBatcherUpdated(address indexed oldNonTeeBatcher, address indexed newNonTeeBatcher);

/// @notice Emitted when the active batcher is switched.
event BatcherSwitched(bool indexed activeIsTee);

function authenticateBatchInfo(
bytes32 commitment,
bytes memory _signature
Expand Down Expand Up @@ -48,4 +51,6 @@ interface IBatchAuthenticator {
function setTeeBatcher(address _newTeeBatcher) external;

function setNonTeeBatcher(address _newNonTeeBatcher) external;

function validateBatch(address sender, bytes calldata data) external view;
}
4 changes: 1 addition & 3 deletions packages/contracts-bedrock/interfaces/L1/IBatchInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ pragma solidity ^0.8.0;
interface IBatchInbox {
fallback() external;

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

function __constructor__(address _batchAuthenticator, address _owner) external;
function __constructor__(address _batchAuthenticator) external;
}
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ build *ARGS: lint-fix-no-fail

# Builds the contracts (developer mode).
build-dev *ARGS: lint-fix-no-fail
just forge-build-dev {{ARGS}}
just forge-build-dev {{ARGS}} && just fix-proxy-artifact

# Builds the go-ffi tool for contract tests.
build-go-ffi:
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/lib/espresso-tee-contracts
Submodule espresso-tee-contracts updated 46 files
+37 −0 .github/workflows/slither.yml
+0 −1 .github/workflows/test.yml
+6 −1 .gitignore
+3 −0 .gitmodules
+311 −26 README.md
+0 −3 deployments/421614-certmanager.json
+0 −3 deployments/421614-nitro-verifier.json
+0 −3 deployments/421614-sgx-verifier.json
+0 −3 deployments/421614tee-verifier.json
+111 −0 flake.lock
+54 −0 flake.nix
+11 −2 foundry.lock
+1 −1 lib/openzeppelin-contracts
+1 −0 lib/safe-utils
+3 −1 remappings.txt
+244 −0 scripts/DeployAllTEEVerifiers.s.sol
+67 −0 scripts/DeployMockTEEVerifiers.s.sol
+45 −22 scripts/DeployNitroTEEVerifier.s.sol
+59 −13 scripts/DeploySGXTEEVerifier.s.sol
+55 −20 scripts/DeployTEEVerifier.s.sol
+175 −0 scripts/MultiSigTransfer.s.sol
+8 −0 slither.config.json
+78 −46 src/EspressoNitroTEEVerifier.sol
+1 −1 src/EspressoRollupSequencerManager.sol
+76 −36 src/EspressoSGXTEEVerifier.sol
+155 −70 src/EspressoTEEVerifier.sol
+162 −0 src/OwnableWithGuardiansUpgradeable.sol
+149 −0 src/TEEHelper.sol
+25 −12 src/interface/IEspressoNitroTEEVerifier.sol
+21 −25 src/interface/IEspressoSGXTEEVerifier.sol
+39 −13 src/interface/IEspressoTEEVerifier.sol
+78 −0 src/interface/ITEEHelper.sol
+49 −0 src/libraries/JournalValidation.sol
+62 −0 src/mocks/EspressoNitroTEEVerifierMock.sol
+54 −0 src/mocks/EspressoSGXTEEVerifierMock.sol
+90 −24 src/mocks/EspressoTEEVerifier.sol
+12 −0 src/types/Types.sol
+278 −73 test/EspressoNitroTEEVerifier.t.sol
+284 −50 test/EspressoSGXTEEVerifier.t.sol
+479 −63 test/EspressoTEEVerifier.t.sol
+212 −0 test/JournalValidation.t.sol
+180 −0 test/MultiSigTransfer.t.sol
+601 −0 test/OwnableWithGuardiansUpgradeable.t.sol
+165 −0 test/SignerValidation.t.sol
+61 −0 test/TEEHelper.t.sol
+250 −0 test/TEEHelper_DoSFix.t.sol
Loading
Loading