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

Add additional verification to EspressoTEEVerifier #28

Merged
merged 10 commits into from
Nov 28, 2024

Conversation

Sneh1999
Copy link
Collaborator

@Sneh1999 Sneh1999 commented Nov 25, 2024

Closes #312

I have listed down my findings related to automata here

This PR:

  • Adds additional verification checks to the EspressoTEEVerifier.sol
  • Cleans up and adds doc strings to deprecated functions
  • Adds some tests to test our verification logic

Important Files to Review

  • src/bridge/EspressoTEEVerifier.sol
  • src/bridge/SequencerInbox.sol

Additional Verifications Added

  • We check that the MR_ENCLAVE and MR_SIGNER match the expected values
  • We check that the hash of the function arguments sent by the batch poster is what was signed by the TEE
    (NOTE: we dont need to check the signature because automata already verifies that, we only check that the reportData matches the function arguments)

@param rawQuote The raw quote in bytes
@return header The parsed header
*/
function parseQuoteHeader(bytes calldata rawQuote) public pure returns (Header memory header) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didnt see any harm in making it public and I think it might turn out helpful for debugging in the future. Its a pure function so takes very less gas as well.

qeIdDaoUpsert(3, qeIdPath);
fmspcTcbDaoUpsert(tcbInfoPath);
function setUp() public {
vm.createSelectFork("https://rpc.ankr.com/eth_sepolia");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am forking sepolia in tests here instead of arb sepolia because automata hasnt deployed there contracts on arb sepolia yet. I will migrate these tests once they have done that


/**
constructor(bytes32 _mrEnclave, bytes32 _mrSigner, address _quoteVerifier) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I am accepting the V3QuoteVerifier contract here is because automata changed how they manage their contracts. Now each Verifier contract should be registered with the PCCSRouter

@Sneh1999 Sneh1999 marked this pull request as ready for review November 26, 2024 23:02
V3QuoteVerifier
} from "@automata-network/dcap-attestation/contracts/verifiers/V3QuoteVerifier.sol";
import {BytesUtils} from "@automata-network/dcap-attestation/contracts/utils/BytesUtils.sol";
import {Ownable} from "solady/auth/Ownable.sol";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason we're not using the openzeppelin Ownable here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automata uses this library for ownable. Apparently is more gas efficient

string memory inputFile = string.concat(vm.projectRoot(), quotePath);
bytes memory sampleQuote = vm.readFileBinary(inputFile);
espressoTEEVerifier = new EspressoTEEVerifier(
bytes32(0x51dfe95acffa8a4075b716257c836895af9202a5fd56c8c2208dacb79c659ff1),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define a variable like badMrEnclave here? And similarly for the other tests. Makes it a bit easier to read especially since the value is the same except for the last digit.

To be more certain that we are always reverting for the right reasons I think it would be a bit better to have custom Error types for each reason we fail verification and check in the tests if we are reverting for the right reasons. Suggestion for later cleanup work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will clean this up, might as well do it here!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sveitser
Copy link
Collaborator

What's the best way to run the tests locally? Both yarn build:all (hardhat compile) and forge build seem to take ages.

@sveitser
Copy link
Collaborator

sveitser commented Nov 27, 2024

I also get an error from forge build

[⠃] Compiling...2024-11-27T09:30:26.588485Z ERROR foundry_compilers_artifacts_solc::sources: error="/home/lulu/r/EspressoSystems/nitro-espresso-integration/contracts/node_modules/@openzeppelin/contracts/utils/Pausable.sol": No such file or directory (os error 2)
[⠒] Compiling...
[⠒] Compiling 275 files with Solc 0.8.25^C⏎     

That contract seems to be at @openzeppelin/contracts/security/Pausable.sol instead

@sveitser sveitser self-requested a review November 27, 2024 09:30
Copy link
Collaborator

@sveitser sveitser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. Some nitpicks and I haven't been able to run it locally because the compilation takes seemingly forever.

@Sneh1999
Copy link
Collaborator Author

What's the best way to run the tests locally? Both yarn build:all (hardhat compile) and forge build seem to take ages.

I did do forge build - yes it takes around 10-15 minutes

@@ -136,13 +146,6 @@ contract EspressoTEEVerifier is Ownable {
success = true;
}

/*
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont need this as we can call transferOwnership function present in the Ownable contract

@Sneh1999 Sneh1999 merged commit f8a152f into celestia-integration Nov 28, 2024
7 of 8 checks passed
@Sneh1999 Sneh1999 deleted the add-verification branch November 28, 2024 14:16
ImJeremyHe pushed a commit that referenced this pull request Dec 4, 2024
* Add additional verification to EspressoTEEVerifier

* fix tests

* fix tests

* cleanup

* revert broken tests

* fix ci

* fix ci

* address comments

* address comments

* add code docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants