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

Session key fixes and test #2138

Merged
merged 2 commits into from
Nov 12, 2024
Merged

Session key fixes and test #2138

merged 2 commits into from
Nov 12, 2024

Conversation

tudor-malene
Copy link
Collaborator

Why this change is needed

  • Added a test for session keys
  • Repurposed the "eth_sendTransaction" endpoint to sign with the active SK

Nonce: w.GetNonceAndIncrement(),
Gas: uint64(1_000_000),
GasPrice: gethcommon.Big1,
Data: gethcommon.FromHex(eventsContractBytecode),
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats this eventsContract? It's not in the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Same ... don't see the events contract in this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's a generic contract. It doesn't really matter for this PR. The idea here is to just send unsigned transactions, and check that they get signed

@@ -0,0 +1,10 @@
# Implement session keys - guide for app developers

If the user selects "no-click UX" (or something) when the game starts, do the following:
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a general statement applicable to an app dev out there ... also we have a section for app developers in the ten-documentation repo so we need to add a section there at some point.


If the user selects "no-click UX" (or something) when the game starts, do the following:

1) call eth_getStorageAt with the address 0x0000000000000000000000000000000000000003 (the other parameters don't matter). This will return the address of the session key.
Copy link
Contributor

Choose a reason for hiding this comment

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

So what I believe is being said there is that, if you call eth_getStorageAt through the gateway with a 'magic' slot number 0x0000000000000000000000000000000000000003 the gateway will return a session key address? Would you ever want to access this storage slot in a contract e.g. if the contract was transparent and you actually wanted the value stored at this address?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that's a magic address. Not a magic storage slot.
And there never will be a contract on that address

2) Create a transaction that transfers some eth to this address. (Maybe you ask the user to decide how many moves they want to prepay or something). The user has to sign this in their wallet. Then submit the tx.
3) Once the receipt is received you call eth_getStorageAt with 0x0000000000000000000000000000000000000004 . This means that you tell the gateway to activate the session key.
4) All the moves made by the user now can be sent with eth_sendRawTransaction or eth_sendTransaction unsigned. They will be signed by the gateway with the session key.
5) When the game is finished create a tx that moves the funds back from the SK to the main address. This will get singed with the SK by the gateeway
Copy link
Contributor

Choose a reason for hiding this comment

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

We will never be able to totally send the funds from the session key address back to the user address as we can't fully estimate the gas required in TEN, so there will be leakage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah. We'll live with that for now. It will be minimal though

3) Once the receipt is received you call eth_getStorageAt with 0x0000000000000000000000000000000000000004 . This means that you tell the gateway to activate the session key.
4) All the moves made by the user now can be sent with eth_sendRawTransaction or eth_sendTransaction unsigned. They will be signed by the gateway with the session key.
5) When the game is finished create a tx that moves the funds back from the SK to the main address. This will get singed with the SK by the gateeway
6) Call: eth_getStorageAt with 0x0000000000000000000000000000000000000005 - this deactivates the key.
Copy link
Contributor

Choose a reason for hiding this comment

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

... with likely albeit small leakage of funds


1) call eth_getStorageAt with the address 0x0000000000000000000000000000000000000003 (the other parameters don't matter). This will return the address of the session key.
2) Create a transaction that transfers some eth to this address. (Maybe you ask the user to decide how many moves they want to prepay or something). The user has to sign this in their wallet. Then submit the tx.
3) Once the receipt is received you call eth_getStorageAt with 0x0000000000000000000000000000000000000004 . This means that you tell the gateway to activate the session key.
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens on a gateway restart, is the session key and associated funds lost?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sk survives.

@tudor-malene tudor-malene merged commit 7f88ff5 into main Nov 12, 2024
2 checks passed
@tudor-malene tudor-malene deleted the tudor/fix_sk branch November 12, 2024 12:37
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.

3 participants