ETHSign 🛠️ Attesting on Sign Protocol
ETHGlobal·Wed, Oct 9, 2024, 12:00 AM
Join Jack Xu on this workshop and learn how to interact with Sign Protocol on EVM through building "Actually Met IRL" in Solidity. As new users flock to web3, critical infrastructure advancements are needed to scale. Join us April 5th-26th for three weeks of hacking and summits around shaping the future of Ethereum. ----------------- Follow us: https://x.com/ETHGlobal?s=20 Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com
Transcript
[Music] hello everyone um thank you for taking an interest in our uh sinx hackathon uh at East Global uh I'm Jack I'm am the uh CTO of East sign today we're going to um basically do a walkth through of the sign protocols around contracts how to interact with them uh what are some of the Core Concepts like uh schemas and attestations within the system um and uh what it may be might be used for so basically uh we're going to um create a smart contract that interacts with the existing sign protocol on uh the base theia uh testnet um and the contract that we're going to write is uh something called uh actually met in real life okay so before that before we get started um for you to get started um you can come you can come to this uh website so eign github.com Forge harat template uh this is actually a uh a solidity template that I made um you do need to install Forge uh beforehand a hard hat you don't have to uh you need a node environment uh preferably node 20 which is the current LTS version okay so you can you can install Forge at uh I think is it g Foundry or something uh so just look up Foundry Forge yeah book. getet found. sh so you can install it by following these directions here okay and once you've done that uh and you're able to use this template to create your own uh repository uh which is what I've already done here um I made a repository called uh sign protocol evm demo zero okay I just made it um I haven't done anything to it yet okay so uh what we're going to do is we're actually going to open up vs code and we're going to uh start writing our stuff um but before we actually start writing so I should give you a little bit of an intro to uh what is sign protocol okay so sign protocol is um an omni chain attestation protocol okay um and what we're able to do is we're able to we're able to enable people to um to post or attest uh structure data uh on chain and that structure is predefined by the schema um so that what what that enables uh us to do is uh or not really us everyone to do is um you're able to define a standard for the type of data that you're going to upload and other people will be able to correctly de code your data um based on um the format presented in the schema uh we also have a sign scan okay okay that's terrible I should know better okay here we go uh scan we had to work on that SEO obviously um so we have the sign procal at deis Explorer so for example um uh let's say e sign which is our other documents sign product right if you look into um the schema name it's called an eign signing event so basically uh every time someone signs on makes a signature on each sign we're going to uh make an adest station here um that conforms to the data defined in this schema now you see you're seeing 23 days ago because we haven't set up the real time um ad station posting stuff yet this is like we uh we have to run the script currently periodically to onboard the data but uh in the near future we're going to actually make it real time okay so there are a few components uh to a schema right so you have the schema name okay um the ID is autogenerated okay and we have a description okay so and also the schema name um the name is only available for rwe Bas schemas so uh s protocol is present on quite a few chains um you can see it here uh we're present on all of these chains um base ethereum X1 which is okx is L2 opnb polygon scroll is data chain okay um but we're also present on R weave um and the cool thing about R weave is that which we won't show today but the cool thing about R weave is that um storing data up there is extremely cheap okay um and because of that we're able to you're able to store more data on our weef um at a lower price but today but the downside of that excuse me the downside of stowing things on rwe is that um if your entire if your at decisions are all posted on rwe then smart contracts actually I'm sorry in smart contracts um they're not actually able to interact um for example read uh the the uh the contents of the at station so today what what we're going to be demoing is actually um evm based attestations okay so we have a description okay uh created at that's just a time stamp um maximum valid time frame so what this does is uh in the schema you're able to set um the um basically the expiration the no not the expression um the duration of which uh the atation made remains valid meaning that for example if you set the maximum valid time frame to like 1 hour then that means the atation that you an atation that you make under this schema will expire after an hour of it uh from its creation date uh creation time stamp created by that's just uh an address okay uh whoever called the smart contract uh data location um so as I mentioned before you're able to store data on um on different on different platforms um and that data refers to schema details or if you go into an station here the decoded data or or actually raw data okay so if you want to store this Json on the evm Chain then it's actually going to be quite expensive but on our VI it's very cheap um so this is what the data location does okay uh transaction ID uh that's actually this is an rwe transaction ID if you click into it we can actually see uh the data that's being posted up here okay so this is an RW block Explorer um revocable ad to station now what this does is um um it basically governs whether an actication um is able to be revoked by by his creator meaning that so for example let's say um let's say we have a schema that represents some kind of club membership right and when you're join when you're joining the club um the the club uh administrator um they will uh make an attestation uh attesting to the fact that you've joined a club right uh but the thing about Club memberships is that you know they can always kick you out or if you like if you don't pay the fees or you know if you do something really heinous heinous um they can kick you out so in that case you know rocal aditions will actually be true or yes and if you do something really really outlandish or you don't pay your fees then uh the creator of um of the at can actually uh which is you know the club administrator uh they can actually um revoke your membership so revoke the anation um that that that that represented your your membership into the club um so schem of details this is the this is a this is a data field of the schema okay um so data field um by default um our sence scan uh we we expect either a Json input um or depending on the data location a CID that points to an R weave piece of data um or uh something on ipfs okay or something onchain if it's something onchain that just be displayed here uh raw uh without any you know uh redirections or fetching uh but if it's an RCI ID which which is the case here um then all of this would be um will be fet from R and displayed here as a Json okay um so that's so that's the schema part and if we look at the source code um this is a schema okay you can see there are quite a few things in here and this is all very uh i' like to think it's pretty well documented right so we've got um address registrant um which is the person that did the reg that registered the schema um bull uh revocable so if the schema is revocable data location this is a struct uh B basically gives you a few options there's onchain ipfs RB and custom okay a Max valid for that is um that's the maximum valid time frame that we talked about um now this is something interesting ISP hook so this is only available for evm contracts um for evm sign protocol contracts and also in the future you know uh Stark net and um salana um so what the hook does is it enables um as someone is creating an at station it allows a predefined hook to be called uh and this hook has to conform to our custom hook interface um it it basically allows you to it's it's just a call hook it's a call hook it's what it is okay uh time stamp uh this is when the schema was created and data so that's uh that's the data part that we showed here um which is this part schema details okay um so that's a walkthrough of the schema and uh the technical walkth through at least and actually you know what let's yeah let's just keep looking at this one um so this is an ATA station okay so because we looked at the schema um you've got the time stamp okay and um expiry so this is governed by the maximum valid time frame um if it's set to zero in the schema then that means um so you can actually set um you're able to set the expiration of the attestation separate from the maximum valid time fr frame in in the schema uh you just so for example if the maximum valid time frame in the schema is 1 hour uh then it just means that uh your your expiration date cannot be uh further than 1 hour from the creation dat of the association it could be like closer it could be like under 1 hour for sure it could be half an hour right and and the the tester is just uh whoever that made the atation and you can see this one points to a schema um a data location okay same thing which is where all these things are stored and also referenced attestation so we have this concept of um of linking of being able to link attestations together so one attestation can um reference another attestation so you can almost think of this as um um recording your state transitions uh explicitly instead of so so for example if you want to revoke someone someone's uh club membership the example that we used um so there are two way there really there are two ways of doing it one uh you can make the uh the schema in a schema you can say that okay the attestations are revocable so you know I can just you know revoke it later or a second option is that you can use linked attestations and uh you can just um as a club administrator if you're trying to roke someone's membership you can basically um make a new attestation saying that okay I'm revoking this person's membership and you're referencing the previous atation where you uh granted them the membership so it's just a way to kind of string different at attestations uh different related attestations together okay and and revoke there's a yes or no okay um and this one is also stored on uh this one has the data that's stored on our weave okay um okay so that's an overview of the structures actually you know what before that let's just look at the code as well for the attestation um so we've got uh schema ID linked attestation ID um ATT test time stamp revoke time stamp um a tester valid until uh revoked recipients data so you can also have um a list of uh an array of recipients and those will be indexed by our science scan um so for example like if I'm a clle administrator I'm I'm trying to uh Grant membership to like two people at once so I can have two recipients here okay uh so recipients and obviously you know you can do this inside of data no problem but recipients um this is explicitly indexed by our indexer whereas data it's just kind of shown um you you can't search you can't you cannot look up uh based on the contents in the data but you're able to look up uh recipients you can filter by recipients uh in our science scan there's also the concept of off of an offchain attestation meaning that um you you already have the data stored elsewhere and you just want to kind of Tim stamp your data okay so um so for this one um you only have the attester and the timestamp and this actually lives inside of the mapping and the key of the mapping um the the the key yes the key of the mapping will basically be uh whatever your data ID is okay so and oping anation record meaning that you know all you want to do is again Tim stamp on our platform and you're not interested in onboarding the data over here which we also support okay okay so let's actually get started uh building this uh met in actually met in real life um kind of um uh smart contract that makes use of sign protocol now uh why do I call it actually met in real life um because if you think about it um a lot of attestations nowadays are really half attestations right so for example if I so for example um so there's this uh so let's just talk about the met in real life schema which a lot of people you know they they like to they like to use um as an example um but so the problem is right um I can I can attest right now that I met uh I met Joe Biden in real life or I met a vitalic or I met Trump in real life right um however it's just what I claim right um how you there's no way for you to verify if I actually met them in real life right I can just claim um from my side whatever and you know it doesn't even have to be true right so so this is what this is why I I call like a lot of the attestations nowadays half attestations because it's just one party claiming to have done something but uh H have they really done it you you have no idea right because it's just that one party uh making a claim right now of course you can say that okay um in order to make it valid I need the other party to also attest uh but once you do that it kind of becomes um well it doesn't become annoying but um there could be a new schema used for that right um and uh for us what we're going to do is we're actually just going to do that we're going to create a new schema called Act met in real life and our smart contract will actually act as a gate um so that basically um this actually met in real life atation will only be met if if both parties um if both parties they uh they come to a Smart contract and say that okay I met the other person in real life okay and the second attestation uh sorry the The second contract interaction that basically affirms that uh they actually met in real life that will trigger um the actual attestation being posted okay um so so here we go um so we already cloned I already cloned um the the repository that I made earlier okay um I call it s protal evm demo zero and uh this is just uh you see this counter. so counter.
t. these are all just from uh Foundry uh and they're here by default okay um and um I also ran uh well you can't see it here uh I also ran pmmi which installs all the packages um by default I have quite a few packages um okay so what we want to do here is um we also want to integrate uh the package from sign protocol right um so to do that we actually we I did package everything into an npm package here which okay it's not loading but it's okay cuz I have to oh there we go yeah um so this one here okay so that's the name so what we're going to do is we're going to copy it over over here okay um and let's just say oh I should be it should be before that okay so now that we have this let's run let's install this again okay so now that we've installed this package what it does is basically it gives us access to um the contracts of sign protocol okay um so that you're actually able to interact with uh the existing onchain smart contracts okay so the first thing that we're going to do is let's just delete the test because um because well uh we're just doing a demo so we don't really need to test our code uh although obviously you know it's a good practice in general program coming um so after deleting that let's just rename this file to um actually met IRL um because well we're not going to use the default counter um so after that um let's just delete the template the default code that that it had and bump the solidity version change license some from unlicensed MIT because this code will be available later for everyone to uh to reference um so let's actually you know let's let's start our game plan here what are we going to what are we going to accomplish uh in this contract so the first thing that we're going to do is um we need to have um we need to have a way to link uh to link to the to link this smart contracts to the existing onchain s protocol instance um because we're going to be interacting with existing an existing uh s protocal deployment uh the second thing is that obviously which is the the core of this idea which is uh to force both parties to confirm that they've met each other in real life uh but formally can add to station um and uh the third thing which we actually didn't end up doing um is that uh originally I planned to have a way to register a new schema uh using code to demonstrate that but uh kind of ran out of time in recording afterwards um also the audio is different because uh halfway through recording um I actually lost audio and I didn't find out until I finished everything so uh this is like a voiceover that that I'm doing afterwards so um going to uh inherit from ownable because we do want to impose some access control um on some of the functions so for example uh only the owner should be able to set uh the sign protocol instance that uh this smart contract points to uh in order to do that obviously we have to uh import our uh sign protocol um our sign protocol interface um so I was uh forgetting the path there um and Ju Just to note uh right here I actually forgot to um fix the remapping which I did later um but in a in a hybrid hard hat and Foundry project uh every time you install a new package you kind of have to uh fix a remapping because Foundry uh by default uses get sub modules but um I'm making it use I'm forcing it to use mpm packages so we have to remap the paths so that it's able to find the package so uh we created a a variable it's called Uh sign protocal instance that holds uh basically a reference to the deploy sign protocal contract uh and also because in order to make an assocation uh we need to um attest it under some schema so um we're also uh setting uh the owner should be able to set the schema ID the schema that we're going to use right so uh that function also needs to be only owner and the schema ID is a un 64 okay okay so now we have to figure out a way to um to kind of um keep track of um the the the records right because uh party a is able to claim that party B uh met them in real life and and party B should be able to come later and then confirm that claim right so we need a data structure that supports that and uh we decid to use a mapping that maps from and address to another address uh called met ARL mapping and U exactly how we're going to use that uh we'll demonstrate it uh in in a second here so we're going to create a new function called claim met IRL so this is the initial claim that by party a that okay party a is basically saying that okay I I I met party B in real life I'm making this claim and this claim um when this function is called this claim is actually unverified so party B will have to come over and verify this claim here so what we're doing here is we're writing uh the second function confirm met IRL so this is the function that's called by party B uh to confirm a claim made by party a right um so uh so we we we're we're saying that okay um if we are uh we're basically looking up uh party A's claim and saying that um if party a is claiming that they've met us and we are actually confirming it if the add if the addresses are the same then uh then we're going to proceed with the with the uh with with the with the confirmation um otherwise uh if party a is claiming that they've met someone else and we're making that claim uh we're we're we're trying to confirm that obviously you can't confirm that party a met with someone else because the whole point is to have uh the first uh and second parties to confirm the facts themselves and here you can you can see that I was uh I was fixing the remappings that I kind of forgot to do earlier um in order for uh for FR to be able to find the files um yeah turns out I actually had to reload the workspace for it to work yep here we go okay so once we have uh confirmed that um our address matches with uh the claim that we're trying to confirm uh we will actually go ahead and create an attestation uh on sign protocol um so yeah so you see we're deleting the the we're skipping over the reg the register fun function demo because we kind of run out of time butth the function that we're going to look at is this ATT test function right so the main thing is to passing the attestation instruct um the indexing key is purely optional a delicate signature is something interesting it's kind of like an erc20 permit where um you're actually able to uh make an anation on someone else's behalf you can also create a schema like that as long as the the original party has um digitally signed it right and extra data is just something that pass along directly to the hooks um it's totally optional you can usually you can leave it blank unless um the schema maker the creator of the schema specified and they're looking for some spe some specific type of data so now um because I have to create that struct uh we're importing um an additional um atation struct so we're we're going to create that struct right here right now um and the data inside of the stru is actually um we also want want to talk about this so obviously schema ID because each attestation needs to um be made under a schema uh linked atation ID so each attestation so let me adjust the input game here so each attestation is actually um you're actually able to uh link it to your previously made attestation um and attest time stamp and revoke time stamp so these you can just pass in zero because uh the sign protocal contract will override it anyways it will uh make sure that the time stamps are correct um aester so this you have to uh input um the address of the attester in this case will actually be this actually met RL contract because this contract will be the caller now if the tester address is incorrect then sign protocol the SM contract will actually throw an error um valid until so that's the maximum valid time frame that we talked about um zero just means it's valid forever data location um it is a is an enum and uh it turns out I actually have to import that separately to um to to kind of make it work although really underneath a un8 um so zero just means uh we're going to have that information on chain as opposed to to on IPS ipfs R weave um and for uh revoked we're going to pass in false because obviously we're just making this at deis right now um and I believe if you pass in true it'll also revert um so for recipients uh so recipients is a bytes array uh the reason why um I made a bytes instead of a dress because I was trying to um I was thinking about you know future extensibility maybe uh you want to make an acction on evm that involves maybe like salana or uh some other addressed format then you'll actually be able to pass it in or encode the information in the bytes um but right here we're just working with evm we're working with um evm addresses so uh what I did was I just I just ABI encoded the the recipients address into uh into bytes and pass it in um and data we can just leave it blank because we're not really passing any anything extra there so now we're going to call the attest function um of the sign protocol smart contract now I made a mistake so yeah there we go so you should you shouldn't call the type you should call the actual object um so I'm only passing in the struct and for the indexing key you can we're not really doing anything with the front end just a demo uh delegate signature we're not really delegating anything so it's empty empty bytes and also uh extra data that's empty bytes and this a test function will return the UN 64 that that'll basically give you the acation ID and uh we'll just emit an event and then return that ID all right so let's actually go over take a look at some of the other overloaded attest uh attest functions here right so we also have another one that uh takes in resolver fees eth so um if the the schema specifies a hook and that hook expects payment uh when when making attestations um we actually accept uh we actually uh have the ability to forward uh payments made using the native coin native token or uh as you can see we can also support any erc20 tokens um and um and the receiver hook uh sorry the the schema hook will actually um have uh different functions uh that are called uh based on the type of fees that they expect uh and the same thing goes for revokes right so if you took take a look at the hook contracts you can see that uh we've got did receive attestation two of them uh the f is payable because we're expecting either no payment or a payment in Native tokens and the second one uh Scot more uh erc20 uh payment um payment uh parameters here right and we have that for both uh attesting and revoking okay all right so uh We've we're basically done I think with the smart contract so far so now uh let's work on actually deploying this thing right um so by default the the template that I made will give you an open Zeppelin uh deployment script but in this case we're not really deploying deploying anything upgradeable um so we're just going to modify it so that it will just deploy something directly um and online five actually um inside of deploy it should just be empty it shouldn't be in array but um and also we have to replace uh the actual contract name in online 4 um and we have to manually print out um the address because we're not using har hat deploy now the template does have har hat deploy uh in the package but uh you know uh for the purposes of this demo I just did it the simple way uh without writing a har hat deploy script um so after deploying the smart contract we want to verify it so that we can interact with it on the Block Explorer and uh so now we're on the Block explor um I was using a new computer so and also it turns out the default RPC on polygon scan is totally broken uh so I had to actually um go and um add Mumbai using a different RPC y so train.org always a very handy website for you to add uh add your um rpcs and new chains so picked one from Anor you know so these uh these noes from Anor are usually pretty pretty reliable um so we're just going to connect the wallets again and uh yeah so this is our this is the contract that we just deployed so now let's actually first let's set uh the sign protocol instance okay so now we've done that um let's then actually because we didn't uh use code to um to create a new schema we actually have have to create a new schema for this actually met IRL uh contract that we did so registrant is is just ourselves and then revocable false uh D data location zero that means on chain Max valid four zero means it's going to be uh it can be valid forever now hook uh I've had to um uh you know I I wish they're able to just convert it convert zero into a zero address for me but I to I had to do that uh time stamp you don't have to do it because sign protocal contract will fill that automatically um so now we're just waiting for the transaction to be confirmed uh for our schema to be live so our schema is now live um you can actually see in the logs emitted that uh we have a new schema with schema id7 so let's Now set that schema in our actually met IRL contract um so that any new um new attestations will be using of schema 7 so let's let me switch to my first account and claim to have met uh IRL with the second account or rather my second account uh claiming to have met with the first account um whichever way around yeah so my first account actually doesn't have any test thematic so just transferring some stuff over um right so yeah I had to reconnect yeah so I'm actually yeah so I'm using my uh my first account uh to to claim um or my my Dev account to claim to have met with my personal account and using my personal account to confirm that uh I've met with the dev account um and you can see that uh an attestation has been made uh through the event logs and we can actually now look up the attestation that we just made with id6 um so if you type in six um then we can get the information uh that we just uh that we that we uh that we wrote from the actually met IRL contract and yeah that wraps up basically the demo of of this uh of this kind of little uh prototype application that we did now um I uh I I have made this thing public so that you can uh look at it uh look at the source code and uh reference parts of it um also uh please come to our live Workshop session because um our in our live Workshop session we'll be talking about some of the other interesting um use cases that we made so this first one is an attestation gated Discord bot basically um it it it it's kind of like collab that land but you need to have um made to have made attestations in order to gain access and you know you can customize the rules and everything um and we also will also go over the kyc Gated access thing that we did uh for dat the chain and and uh yeah that's about it for this uh pre-recorded de uh demonstration uh Workshop uh I do apologize again for the for the audio mishaps uh the switching over halfway through the um through the video and uh I will see you on uh April 3rd I believe that's uh when our Workshop live Workshop is happening see you then thank [Music] you
Automatic transcript — names and jargon may be misspelled.