sips icon indicating copy to clipboard operation
sips copied to clipboard

SIP-018 Signed Structured Data

Open MarvinJanssen opened this issue 3 years ago • 19 comments

The Signed Structured Data specification proposed in this SIP describes a standard way to deterministically encode and sign Structured Data. Structured Data is data that can be represented in human-readable format and used in applications and smart contracts. The aim of the standard is to produce signatures that are straightforward and inexpensive to verify by smart contracts.

Reference implementation:

  • https://github.com/MarvinJanssen/stx-signed-structured-data

Requires:

  • to-consensus-buff / CV serialisation in Clarity as described in https://github.com/blockstack/stacks-blockchain/issues/2693. I am currently using a custom REPL / Clarinet that includes this function. I will make an effort to publish the branch as soon as possible.

See also:

  • https://github.com/hirosystems/stacks-wallet-web/issues/1051
  • https://github.com/blockstack/stacks-blockchain/issues/2693
  • https://github.com/blockstack/stacks-blockchain/issues/2982

MarvinJanssen avatar Dec 28 '21 19:12 MarvinJanssen

I took another pass at this, in light of the recent OpenSea phishing attack. While I stand by my belief that discussion of to-consensus-buff should be part of the Stacks 2.1 SIP, I think the rest of this is good. Most of my comments are just asking for minor clarifications.

jcnelson avatar Feb 24 '22 05:02 jcnelson

Just as additional context, Verifiable Credentials are a second type of structured data that wallets should support

friedger avatar Feb 26 '22 09:02 friedger

Marvin - a question on making the domain info stronger by eg including domain names and user agent info?

cf. EIP 712 says this..

The way to solve this is by introducing a domain separator, a 256-bit number. This is a value unique to each domain that is ‘mixed in’ the signature. It makes signatures from different domains incompatible. The domain separator is designed to include bits of DApp unique information such as the name of the DApp, the intended validator contract address, the expected DApp domain name, etc. The user and user-agent can use this information to mitigate phishing attacks, where a malicious DApp tries to trick the user into signing a message for another DApp.

radicleart avatar May 18 '22 12:05 radicleart

Hi all -- just wanted to let folks know that I've implemented support for interacting with wallets that support this standard within micro-stacks:

Relevant versions: micro-stacks: >= 0.5.0 @micro-stacks/react: >= 0.2.1

Some docs: https://docs.micro-stacks.dev/modules/core/connect/message-signing https://docs.micro-stacks.dev/modules/integrations/react/message-signing

Note: I have also implemented support for recoverable signatures in both RSV mode (like this sip expects) and VRS mode (like legacy stacks functions used)

aulneau avatar May 20 '22 13:05 aulneau

Did another pass. Let's go ahead and advance this to Accepted :tada:

Before we can advance to Recommended, I have two outstanding comments that need to be addressed. Also, @kantai (who is now on the technical CAB) needs to make a pass as well.

jcnelson avatar May 27 '22 02:05 jcnelson

I added test vectors at the end of the SIP per @janniks in 395ea83 and moved it to Accepted status. Still an open question regarding the prefix. (See comment above.)

MarvinJanssen avatar May 27 '22 04:05 MarvinJanssen

@radicleart I'm wary adding a domain name to the domain object. I can foresee future applications that might not use a domain name or do not want to be strongly coupled to one. For example, an open DeFi protocol built on top of SIP018 might be used across different applications. The protocol then simply defines a unique name or other identifier in the domain object. That is not to say a future standard based on SIP018 cannot introduce a domain name in the domain object for specific purposes (like app sign in).

MarvinJanssen avatar May 27 '22 04:05 MarvinJanssen

I propose adding signature timestamp and signature expiration timestamp fields as part of domain. this may help mitigate potential misuse of signed messages e.g. prevent replay of meta transactions by compromised dapps ideally signature timestamp to be autogenerated while signing messages

jiga avatar May 27 '22 08:05 jiga

@jiga I don't think those fields should be part of SIP018 as I don't think they are always desirable. Furthermore, those fields should probably go in the payload and not the domain. (An order tuple may have an expiry field, for example.)

Meta transactions are a valid use case and I would suggest a future meta transaction SIP to be formulated on top of SIP018.

MarvinJanssen avatar May 28 '22 05:05 MarvinJanssen

SIP document updated with the new "SIP018" prefix in 318bad3!

To everyone that was/is implementing SIP018: this is a BREAKING CHANGE.

The prefix has been changed from a single-byte 0xC0 to six bytes: [0x53, 0x49, 0x50, 0x30, 0x31, 0x38]. (Which spells "SIP018" in ASCII.)

If you are curious why, see this discussion: https://github.com/stacksgov/sips/pull/57#discussion_r776508478

The reference implementation has also been updated to reflect the change:

  • https://github.com/MarvinJanssen/stx-signed-structured-data

MarvinJanssen avatar May 30 '22 02:05 MarvinJanssen

[email protected] has been updated to support the latest implementation of this SIP, matching the test vectors supplied in https://github.com/stacksgov/sips/commit/318bad31f09fb60b02181f1d1c81b26ba8254408

aulneau avatar May 30 '22 19:05 aulneau

This looks great to me, just had some superficial comments, and then we can move this to recommended!

kantai avatar Jun 01 '22 18:06 kantai

Implemented suggestions and moved to Recommended.

MarvinJanssen avatar Jun 03 '22 14:06 MarvinJanssen

Cool! Do the authors feel that this is ready for activation?

jcnelson avatar Jun 04 '22 20:06 jcnelson

Yep. But will give @janniks time to respond to the last open conversation.

MarvinJanssen avatar Jun 05 '22 08:06 MarvinJanssen

Wanna ping me when it's ready? @janniks @MarvinJanssen

jcnelson avatar Jun 07 '22 01:06 jcnelson

Ready to go @jcnelson

MarvinJanssen avatar Jun 07 '22 01:06 MarvinJanssen

Cool, it's now listed as "activating" in the README. Can you set the status to Activation-in-Progress? Thanks!

jcnelson avatar Jun 08 '22 19:06 jcnelson

Done!

MarvinJanssen avatar Jun 09 '22 12:06 MarvinJanssen

Looking at the activation criteria:

  1. to-consensus-buff or equivalent functionality is added to Stacks 2.1.
  2. At least one popular wallet application implements the standard before or within one year of the launch of Stacks 2.1.

Do you think both have been met @jcnelson? Hiro Wallet as well as the Stacks Ledger applet added support for SIP018 messages and to-consensus-buff has been added to Stacks 2.1. Can we thus consider this SIP activated or do we wait until the launch of Stacks 2.1?

MarvinJanssen avatar Jan 26 '23 22:01 MarvinJanssen

Just an update on this -- we will merge this when 2.1 activates on mainnet.

jcnelson avatar Feb 16 '23 23:02 jcnelson