passportxyz / passport

Passport allows users to prove their identity through a secure, decentralized UI
Other
942 stars 451 forks source link

Audit of Smart Contract for On-chain Stamp Integration #1254

Open erichfi opened 1 year ago

erichfi commented 1 year ago

The primary goal of this SPIKE is to conduct a thorough audit of the smart contract responsible for bringing stamps on-chain. This is a crucial component of our system, and as such, requires a meticulous review to ensure its security, efficiency, and compatibility with the rest of our infrastructure.

Tasks:

Deliverables:

Once we've completed this SPIKE, we will be well-equipped to make informed decisions about any necessary changes or improvements to the smart contract, bolstering the security and efficiency of our on-chain stamp integration.

tim-schultz commented 1 year ago

Testing

Both Contracts

GitcoinAttester

GitcoinVerifier

General

lucianHymer commented 1 year ago

To save some gas, we could make the iterator in the for loop of _hashPassport unchecked. Nobody would ever have > 2^256 stamps so we shouldn't have to worry about overflow, and even if it did overflow they'd just fail validation b/c it wouldn't match.

I think we can also just do uint256 i instead of uint256 i = 0, in solidity it starts as 0.

lucianHymer commented 1 year ago

In _verify, we should do the revert statements as Tim mentioned. We can drop the if statement both in Attester waiting on the verify result, and the if statement around recipientNonces[]++. Also, no need for verify to return a value.

In hashPassport, passport should be passed as calldata

We should revert with custom errors instead of strings.

Also, my previous comment applies to the for loop in getMultiAttestRequest as well.

Here's a PR where I tried some of this stuff out (didn't add the custom errors to this): https://github.com/gitcoinco/eas-proxy/pull/13

nutrina commented 1 year ago

Have merged in https://github.com/gitcoinco/eas-proxy/pull/13 , this looks good.