Calindra / nonodo

Development Node for Cartesi Rolups
Apache License 2.0
22 stars 14 forks source link

Espresso message sender #57

Closed fabiooshiro closed 2 weeks ago

fabiooshiro commented 5 months ago

How to handle the message sender from espresso transaction?

fabiooshiro commented 5 months ago

https://eips.ethereum.org/EIPS/eip-712

ZzzzHui commented 4 months ago

I think the message should at least include nonce too, otherwise the same input may be added into the repo more than once. We could refer to how normal ethereum tx is structured and signed.

fabiooshiro commented 4 months ago

references https://eips.ethereum.org/EIPS/eip-155 https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2718.md

The nonce must be stored as a field in the account data: https://ethereum.org/en/developers/docs/accounts/#an-account-examined

The next input/transaction must adhere to this constraint:

account.nonce == tx.nonce and tx.msg_sender == account.owner 
DiegoSena commented 4 months ago
ZzzzHui commented 4 months ago

Here is an example of how to sign data with viem, similar to what Gui posted in Discord channel, but in more details: https://viem.sh/docs/actions/wallet/signTypedData

Specifically, for the data.ts file, I think we can make it as:

// All properties on a domain are optional
export const domain = {
  name: 'Espresso Message',
  version: '1',
  chainId: 1, // for example, ethereum mainnet
  verifyingContract: {namespace},
  // probably don't need `salt`
} as const

// The named list of all type definitions
export const types = {
  EspressoMessage: [
    { name: 'msgSender', type: address},
    { name: 'nonce', type: 'uint256'},
    { name: 'payload', type: 'string'},
  ],
} as const

EDIT: as pointed out by Gui. We don't need the msgSender

fabiooshiro commented 4 months ago

We discussed with @tuler.eth, @Gabriel Coutinho de Paula, @pedroargento, @Milton and concluded that we need a nonce within the "account state"

ZzzzHui commented 4 months ago

Yes. Similar as account states on evm. We could also make nonce sequentially incremental like ethereum does too. The other option is to make nonce random. But I prefer the former.