Skip to content

Commit bbe1093

Browse files
authored
Allow smart contract wallets to obtain Proof of Humanity trust bonus (#10555)
* Added eip-1271 support (isValidSignature) to PoH trust bonus verification. This allows smart contract wallets to properly sign the tx * Removing parts unrelated to my changes. Not sure how these got in * Restructuring the logic for better readability * Removing json.loads() when loading the contract abi per review from Tim. This stays consistent with the surrounding code * - Created new file for eip 1271 abi - Moved is_valid_eip_1271_signature() out of poh_utils.py and into grants/utils.py * Putting newline back in so changes aren't made during the PR
1 parent bdb1e09 commit bbe1093

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

app/assets/v2/js/pages/profile-trust.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ Vue.component('poh-verify-modal', {
833833
</div>
834834
<div v-if="step === 'validation-complete'">
835835
<div>
836-
Your Proof of Humanity verification was successful. Thank you for helping make Gitcoin mroe sybil resistant!
836+
Your Proof of Humanity verification was successful. Thank you for helping make Gitcoin more sybil resistant!
837837
</div>
838838
<b-button @click="dismissVerification" variant="primary" class="btn btn-primary mt-5 px-5 float-right">Done</b-button>
839839
</div>

app/dashboard/views.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
from eth_account.messages import defunct_hash_message
9292
from eth_utils import is_address, is_same_address
9393
from git.utils import get_auth_url, get_issue_details, get_url_dict, get_user, is_github_token_valid, search_users
94-
from grants.utils import get_clr_rounds_metadata
94+
from grants.utils import get_clr_rounds_metadata, is_valid_eip_1271_signature
9595
from kudos.models import Token
9696
from kudos.utils import humanize_name
9797
# from mailchimp3 import MailChimp
@@ -7220,21 +7220,26 @@ def verify_user_poh(request, handle):
72207220
'msg': 'Empty signature or Ethereum address',
72217221
})
72227222

7223+
web3 = get_web3('mainnet')
72237224
message_hash = defunct_hash_message(text="verify_poh_registration")
72247225
signer = w3.eth.account.recoverHash(message_hash, signature=signature)
72257226
if eth_address != signer:
7226-
return JsonResponse({
7227-
'ok': False,
7228-
'msg': 'Invalid signature',
7229-
})
7227+
# recoverHash() will fail if the address is a smart contract wallet. Check for EIP-1271 compliance
7228+
if is_valid_eip_1271_signature(web3, web3.toChecksumAddress(eth_address), message_hash, signature):
7229+
# We got a valid EIP-1271 signature from eth_address, so we can trust it.
7230+
signer = eth_address
7231+
else:
7232+
return JsonResponse({
7233+
'ok': False,
7234+
'msg': 'Invalid signature',
7235+
})
72307236

72317237
if Profile.objects.filter(poh_handle=signer).exists():
72327238
return JsonResponse({
72337239
'ok': False,
72347240
'msg': 'Ethereum address is already registered.',
72357241
})
72367242

7237-
web3 = get_web3('mainnet')
72387243
if not is_registered_on_poh(web3, signer):
72397244
return JsonResponse({
72407245
'ok': False,

app/grants/abi/__init__.py

Whitespace-only changes.

app/grants/abi/eip_1271_abi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EIP_1271_ABI = [{"constant":True,"inputs":[{"name":"_messageHash","type":"bytes32"},{"name":"_signature","type":"bytes"}],"name":"isValidSignature","outputs":[{"name":"magicValue","type":"bytes4"}],"payable":False,"stateMutability":"view","type":"function"}]

app/grants/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,12 @@ def bsci_script(csv: str) -> tuple:
465465

466466
def isNaN(string):
467467
return string != string
468+
469+
def is_valid_eip_1271_signature(web3, address, hash, signature) -> bool:
470+
from grants.abi.eip_1271_abi import EIP_1271_ABI
471+
try:
472+
eip_1271_contract = web3.eth.contract(address=address, abi=EIP_1271_ABI)
473+
retval = eip_1271_contract.functions.isValidSignature(hash, signature).call()
474+
return web3.toInt(retval) == 0x1626ba7e
475+
except Exception as e:
476+
return False

0 commit comments

Comments
 (0)