Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqvq committed Oct 31, 2024
1 parent de1eacd commit 74299af
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ module sui::attestation_tests {

#[test]
fun test_attestation_verify() {
let attestation = x"8444a1013822a0591120a9696d6f64756c655f69647827692d30326130666132393836396564363165642d656e633031393262663561663336613733613566646967657374665348413338346974696d657374616d701b00000192bff6ad796470637273b0005830000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015830000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000025830000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035830639a8b65f68b0223cbb14a0032487e5656d260434e3d1a10e7ec1407fb86143860717fc8afee90df7a1604111709af460458300c5c8067bd308b422bbe9654cbb0b3d13a49a5470d04865497582661f1910f7bd2cf840560d302391ca4c66f46c258520558300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000658300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000758300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000858300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000958300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006b636572746966696361746559027f3082027b30820201a00302010202100192bf5af36a73a500000000671a9d5b300a06082a8648ce3d04030330818e310b30090603550406130255533113301106035504080c0a57617368696e67746f6e3110300e06035504070c0753656174746c65310f300d060355040a0c06416d617a6f6e310c300a060355040b0c034157533139303706035504030c30692d30326130666132393836396564363165642e75732d656173742d312e6177732e6e6974726f2d656e636c61766573301e170d3234313032343139313734345a170d3234313032343232313734375a308193310b30090603550406130255533113301106035504080c0a57617368696e67746f6e3110300e06035504070c0753656174746c65310f300d060355040a0c06416d617a6f6e310c300a060355040b0c03415753313e303c06035504030c35692d30326130666132393836396564363165642d656e63303139326266356166333661373361352e75732d656173742d312e6177733076301006072a8648ce3d020106052b810400220362000419e33204ae5676d5706f428e99aeaf3c97a5c6d8bd6ff2c8f7c221d1d79303e3ed9408de07a33060060ae4f62631a10d2fb2c6f770c679ea895ba298128811f28e7a3a811d2edd9b2d891239b43effd1a475c8e377ef88d2e3d244086874a245a31d301b300c0603551d130101ff04023000300b0603551d0f0404030206c0300a06082a8648ce3d0403030368003065023100a97e905326fc6b9556254fbf1226d6719989c21b87ac735961a6a5e0a56fb667b232c9937423169b02ea8dbbf097aeb40230499f8e4c09856e2246a2adab33adfbe490968fb916b599a992e2e20594a0f7118e3d9e18c6e7a900fc4a113752fe310868636162756e646c65845902153082021130820196a003020102021100f93175681b90afe11d46ccb4e4e7f856300a06082a8648ce3d0403033049310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c03415753311b301906035504030c126177732e6e6974726f2d656e636c61766573301e170d3139313032383133323830355a170d3439313032383134323830355a3049310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c03415753311b301906035504030c126177732e6e6974726f2d656e636c617665733076301006072a8648ce3d020106052b8104002203620004fc0254eba608c1f36870e29ada90be46383292736e894bfff672d989444b5051e534a4b1f6dbe3c0bc581a32b7b176070ede12d69a3fea211b66e752cf7dd1dd095f6f1370f4170843d9dc100121e4cf63012809664487c9796284304dc53ff4a3423040300f0603551d130101ff040530030101ff301d0603551d0e041604149025b50dd90547e796c396fa729dcf99a9df4b96300e0603551d0f0101ff040403020186300a06082a8648ce3d0403030369003066023100a37f2f91a1c9bd5ee7b8627c1698d255038e1f0343f95b63a9628c3d39809545a11ebcbf2e3b55d8aeee71b4c3d6adf3023100a2f39b1605b27028a5dd4ba069b5016e65b4fbde8fe0061d6a53197f9cdaf5d943bc61fc2beb03cb6fee8d2302f3dff65902c2308202be30820244a00302010202101cd0c4a846859575fe3ecdb330e852a0300a06082a8648ce3d0403033049310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c03415753311b301906035504030c126177732e6e6974726f2d656e636c61766573301e170d3234313032343039333235355a170d3234313131333130333235355a3064310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c034157533136303406035504030c2d613132616566333232643530353436352e75732d656173742d312e6177732e6e6974726f2d656e636c617665733076301006072a8648ce3d020106052b8104002203620004d09c64a02b070e9ab2f4ed69d2c2592e52499fd32cc10de3d348b861a2463f095bd78072b248add25aebb092fcd483db4dac438410ce16fa7a4e3289f47a30b29dc15dc5767a5bd9fec5fe4db8876de017b0e3766b70fc7915c57f9a8b183bb0a381d53081d230120603551d130101ff040830060101ff020102301f0603551d230418301680149025b50dd90547e796c396fa729dcf99a9df4b96301d0603551d0e041604146ccdaf765a77d0d75639755b06f339a61aec9431300e0603551d0f0101ff040403020186306c0603551d1f046530633061a05fa05d865b687474703a2f2f6177732d6e6974726f2d656e636c617665732d63726c2e73332e616d617a6f6e6177732e636f6d2f63726c2f61623439363063632d376436332d343262642d396539662d3539333338636236376638342e63726c300a06082a8648ce3d04030303680030650230784f6435c8c2db44be0d5e3c2ef4b975c2de65f3d8b26193628d38173e7f902729e5908ad8c6cbbbee969c6bd712c3b4023100ac0a805da8838a344a053bb6aea203a7c44ab916080c8e6bd91c98cd057918fe368d53105b2b6d25acce71ac6b97895b59031a308203163082029ba003020102021100d3f7e82c3fc7dbbd7ac57ebb3e8a4fea300a06082a8648ce3d0403033064310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c034157533136303406035504030c2d613132616566333232643530353436352e75732d656173742d312e6177732e6e6974726f2d656e636c61766573301e170d3234313032343130313230335a170d3234313033303034313230335a308189313c303a06035504030c33356637313231383234373530333739362e7a6f6e616c2e75732d656173742d312e6177732e6e6974726f2d656e636c61766573310c300a060355040b0c03415753310f300d060355040a0c06416d617a6f6e310b3009060355040613025553310b300906035504080c0257413110300e06035504070c0753656174746c653076301006072a8648ce3d020106052b810400220362000424160078a3019a9cfc024525a4133aeb46c39a97bbc0811a7df74fb11a28418b74bcbeaf85ad52811c4844c7427bc0377872c2caa6f582fb20f84a5f84bbf0b4efde64646a9fbd97d60a31c8e94f398c22a33cddcb77c59c16f6bf302bdfb091a381ea3081e730120603551d130101ff040830060101ff020101301f0603551d230418301680146ccdaf765a77d0d75639755b06f339a61aec9431301d0603551d0e04160414c670ada693df3d381aebc1c7fe214f4e0ed95163300e0603551d0f0101ff0404030201863081800603551d1f047930773075a073a071866f687474703a2f2f63726c2d75732d656173742d312d6177732d6e6974726f2d656e636c617665732e73332e75732d656173742d312e616d617a6f6e6177732e636f6d2f63726c2f63303838663561312d653531322d346663342d626135622d6561373931316137376636652e63726c300a06082a8648ce3d0403030369003066023100c5b57f998e0225974e291a6ffee3d7c93122c778de01770cfdd92cae6648e58559c5a582d5a388737da2d77f69f7cf1002310085088eb257f6f5db83348820fc1f41597c53762f387abf49ff852b44dfa188883b20d66b7afa5a2a17fa7351d649153f5902c1308202bd30820244a00302010202144500f9709fede9b4b43789ef88bede7efb2b1e6d300a06082a8648ce3d040303308189313c303a06035504030c33356637313231383234373530333739362e7a6f6e616c2e75732d656173742d312e6177732e6e6974726f2d656e636c61766573310c300a060355040b0c03415753310f300d060355040a0c06416d617a6f6e310b3009060355040613025553310b300906035504080c0257413110300e06035504070c0753656174746c65301e170d3234313032343139303734345a170d3234313032353139303734345a30818e310b30090603550406130255533113301106035504080c0a57617368696e67746f6e3110300e06035504070c0753656174746c65310f300d060355040a0c06416d617a6f6e310c300a060355040b0c034157533139303706035504030c30692d30326130666132393836396564363165642e75732d656173742d312e6177732e6e6974726f2d656e636c617665733076301006072a8648ce3d020106052b81040022036200044dae149b171de0872413260f133ce391a397c254dbf0c7c25f0dc0a8a28fa6d2354c9acdc66c74e88389bfed97d33a77fcf77973a8f1381c5d65aa026eb571027844c486e91c18d7bba97907336a814b782f1bc56d722a9fbdd0616589cdb43aa366306430120603551d130101ff040830060101ff020100300e0603551d0f0101ff040403020204301d0603551d0e041604140e872a9e434237fa56cab905f466bbea99848abd301f0603551d23041830168014c670ada693df3d381aebc1c7fe214f4e0ed95163300a06082a8648ce3d040303036700306402304b324ab3d2f1edec5c6715f548f816a4229caa642d067188693413780fdda3194bc469c4f4e421038500b437dc0aeba30230672cca9937e8f711b170a8fc59790bc8e2de5e61cca7011b2d00fde88dd28d6521a4f10fe7b813eaccaf72e4dc6cadfa6a7075626c69635f6b6579f669757365725f646174615820af3ef9c81f191839c060785ce2db7ffb9aaaabb314ffc6a6db774fb9453ef3a2656e6f6e6365f65860fdfe27bd43732ba44c870a48502da367f528291a5058ba95461669468f9d48cf6f07590a5408d4908ab4a84c9b37209d0bd60c52523132da478b0e8a67768316310056ae2e8b39a600ee991bd37bc22ebf06f180e264c86c27471e22eb535652";
let enclave_pk = x"af3ef9c81f191839c060785ce2db7ffb9aaaabb314ffc6a6db774fb9453ef3a2";
let verify = attestation::attestation_verify(&enclave_pk, &attestation);
let attestation = x"8444a1013822a059111fa9696d6f64756c655f69647827692d30663733613462346362373463633966322d656e633031393265343138386665663738316466646967657374665348413338346974696d657374616d701b00000192e43cadbb6470637273b0005830000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015830000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000025830000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035830639a8b65f68b0223cbb14a0032487e5656d260434e3d1a10e7ec1407fb86143860717fc8afee90df7a1604111709af460458309ab5a1aba055ee41ee254b9b251a58259b29fa1096859762744e9ac73b5869b25e51223854d9f86adbb37fe69f3e5d1c0558300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000658300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000758300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000858300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000958300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f58300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006b636572746966696361746559027e3082027a30820201a00302010202100192e4188fef781d000000006723e692300a06082a8648ce3d04030330818e310b30090603550406130255533113301106035504080c0a57617368696e67746f6e3110300e06035504070c0753656174746c65310f300d060355040a0c06416d617a6f6e310c300a060355040b0c034157533139303706035504030c30692d30663733613462346362373463633966322e75732d656173742d312e6177732e6e6974726f2d656e636c61766573301e170d3234313033313230323033315a170d3234313033313233323033345a308193310b30090603550406130255533113301106035504080c0a57617368696e67746f6e3110300e06035504070c0753656174746c65310f300d060355040a0c06416d617a6f6e310c300a060355040b0c03415753313e303c06035504030c35692d30663733613462346362373463633966322d656e63303139326534313838666566373831642e75732d656173742d312e6177733076301006072a8648ce3d020106052b81040022036200049e2df2f8fe1ce8e1053b01397cb574a0558a46ef1526fd1b3784a16d01f2a07a802f5b7d99ba5fb293c5d43bd53579a1ca8791a9184f5e297ae7fd88a75bad074418a72153ce2a0a4673de6bfd8afac6fb650e36e121a37ef19453be770e6145a31d301b300c0603551d130101ff04023000300b0603551d0f0404030206c0300a06082a8648ce3d04030303670030640230097d15740cb4ae0d03c6ec77c0b153ac9257a292cf3316bfd7ba15bf41a91d09e661a476d9286d8cf4b64466a4cb9d1b02301179c3a2f9303bfa617b1e4c9a6fcdfe14cd126730d1d885834006b6e5c87454c3650d361b01e882a22fbf0cb1e2514168636162756e646c65845902153082021130820196a003020102021100f93175681b90afe11d46ccb4e4e7f856300a06082a8648ce3d0403033049310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c03415753311b301906035504030c126177732e6e6974726f2d656e636c61766573301e170d3139313032383133323830355a170d3439313032383134323830355a3049310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c03415753311b301906035504030c126177732e6e6974726f2d656e636c617665733076301006072a8648ce3d020106052b8104002203620004fc0254eba608c1f36870e29ada90be46383292736e894bfff672d989444b5051e534a4b1f6dbe3c0bc581a32b7b176070ede12d69a3fea211b66e752cf7dd1dd095f6f1370f4170843d9dc100121e4cf63012809664487c9796284304dc53ff4a3423040300f0603551d130101ff040530030101ff301d0603551d0e041604149025b50dd90547e796c396fa729dcf99a9df4b96300e0603551d0f0101ff040403020186300a06082a8648ce3d0403030369003066023100a37f2f91a1c9bd5ee7b8627c1698d255038e1f0343f95b63a9628c3d39809545a11ebcbf2e3b55d8aeee71b4c3d6adf3023100a2f39b1605b27028a5dd4ba069b5016e65b4fbde8fe0061d6a53197f9cdaf5d943bc61fc2beb03cb6fee8d2302f3dff65902c1308202bd30820244a00302010202105e38d80df50697821a75868f41e784b0300a06082a8648ce3d0403033049310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c03415753311b301906035504030c126177732e6e6974726f2d656e636c61766573301e170d3234313032393039303734355a170d3234313131383130303734355a3064310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c034157533136303406035504030c2d616662353333343262366335383838352e75732d656173742d312e6177732e6e6974726f2d656e636c617665733076301006072a8648ce3d020106052b8104002203620004c92eff4f5268be6b0b2d5e402610285410046d5ff1ccbbada2cafac96ca22525a89d710bc69c6dddf1c5dde1bb29293416611718f47631c5c61945d82ad49c41a553af78f409763490a3f888edf8188fee6d6691aeba6faf3a559d1086f7437fa381d53081d230120603551d130101ff040830060101ff020102301f0603551d230418301680149025b50dd90547e796c396fa729dcf99a9df4b96301d0603551d0e041604144cb4eb898e87a14e9b196cc57923aa7899c45454300e0603551d0f0101ff040403020186306c0603551d1f046530633061a05fa05d865b687474703a2f2f6177732d6e6974726f2d656e636c617665732d63726c2e73332e616d617a6f6e6177732e636f6d2f63726c2f61623439363063632d376436332d343262642d396539662d3539333338636236376638342e63726c300a06082a8648ce3d0403030367003064023064ff9e5be5f0028e5cd81103213d49839330fcf2110d9e53bb4149fd71e86576ac27c53e886a92081bef34a006b2bead02300a6a31d99fe753f0b582f1ee81975e7c81bfb7a31bac3f41f0456107cb0c4442bfb644f8c672b322fd415b5445021210590319308203153082029ba003020102021100852d3a881d6902449e319ba2b5e9d1bb300a06082a8648ce3d0403033064310b3009060355040613025553310f300d060355040a0c06416d617a6f6e310c300a060355040b0c034157533136303406035504030c2d616662353333343262366335383838352e75732d656173742d312e6177732e6e6974726f2d656e636c61766573301e170d3234313033313037353034325a170d3234313130363033353034325a308189313c303a06035504030c33356138626266633236663932356238622e7a6f6e616c2e75732d656173742d312e6177732e6e6974726f2d656e636c61766573310c300a060355040b0c03415753310f300d060355040a0c06416d617a6f6e310b3009060355040613025553310b300906035504080c0257413110300e06035504070c0753656174746c653076301006072a8648ce3d020106052b810400220362000447bc86fbe2f49eaf541fef52b3bee0eb6e12ec1bdb27ffa399cfd236fb4c170dee6381b1039711a90bd88e0954ef6a88846cb46cd0e2fe7a0d8621ce52c8e66b00090e5823e2c3416a695f03290628147fca8766f8e021d7898d413bdf9a97f4a381ea3081e730120603551d130101ff040830060101ff020101301f0603551d230418301680144cb4eb898e87a14e9b196cc57923aa7899c45454301d0603551d0e041604142fb78d05684f062a6edd77765ac8b555ab745687300e0603551d0f0101ff0404030201863081800603551d1f047930773075a073a071866f687474703a2f2f63726c2d75732d656173742d312d6177732d6e6974726f2d656e636c617665732e73332e75732d656173742d312e616d617a6f6e6177732e636f6d2f63726c2f66316139303335362d616130622d343934332d613866612d3933613737623036396361332e63726c300a06082a8648ce3d0403030368003065023100984a7c2bf94a8045eacbedbe559d82be2c9872a7f842cdb9581176049f59edd0df470ed5197603a27a7983d719b295bf023062ade2ddf0a6f3f27e57e8a9b6ef8049f8811d5254ed6b9063d12d5e6911ab819d41d834ffa8ec6602ebc64edd25bfa95902c3308202bf30820245a003020102021500d5866ef7a8cc2588b9858bbf7d3362486149ad95300a06082a8648ce3d040303308189313c303a06035504030c33356138626266633236663932356238622e7a6f6e616c2e75732d656173742d312e6177732e6e6974726f2d656e636c61766573310c300a060355040b0c03415753310f300d060355040a0c06416d617a6f6e310b3009060355040613025553310b300906035504080c0257413110300e06035504070c0753656174746c65301e170d3234313033313130313030385a170d3234313130313130313030385a30818e310b30090603550406130255533113301106035504080c0a57617368696e67746f6e3110300e06035504070c0753656174746c65310f300d060355040a0c06416d617a6f6e310c300a060355040b0c034157533139303706035504030c30692d30663733613462346362373463633966322e75732d656173742d312e6177732e6e6974726f2d656e636c617665733076301006072a8648ce3d020106052b81040022036200040fe46adf864a558a00a9ca4b64ece5ba124ed1d29656a1f16ca71d0dc8fca56b0fb15aafd309f6258374e8c7b4a5b0521c76d1812a7873474dae9322aef1cd782db19fc2ece4d36fa08acbe65e4bec2a3cfe70960d179778ea7e7711f827b36ea366306430120603551d130101ff040830060101ff020100300e0603551d0f0101ff040403020204301d0603551d0e041604143e40d423bf86e9565c378487843389bd2f471a56301f0603551d230418301680142fb78d05684f062a6edd77765ac8b555ab745687300a06082a8648ce3d040303036800306502310097c76197278a1681013ff415526e54a66209e4c35c32227f7a84bd0d05c181f4db627c96b3284e4f2ce476b4834c04a2023050eb1c7e8c16c2b533f5e714a7389276b70b18c678c2f51189ca841d8908bc8e192626b97d5f577ad850b2896554ff646a7075626c69635f6b6579f669757365725f6461746158205a264748a62368075d34b9494634a3e096e0e48f6647f965b81d2a653de684f2656e6f6e6365f6586033dc0b143ec65334d7322ddab064080de20b7cc7c548c2441804e2456389e80e041963b5ac7e62c00e7fa49ae64afbc4ddad25a7951e82f8a64e5706049d70bfaf7f6ab39e321a38373d0e9e983d0438d0b6769fb3cd8ff25b35556bc2aae529";
let enclave_pk = x"5a264748a62368075d34b9494634a3e096e0e48f6647f965b81d2a653de684f2";
let pcr = x"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
let verify = attestation::attestation_verify(&enclave_pk, &attestation, &pcr, &pcr, &pcr);
assert!(verify == true)
}
}
2 changes: 1 addition & 1 deletion crates/sui-types/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl AttestationDocument {
}

fn validate_pcrs(&self, expected_pcrs: &[&[u8]]) -> Result<(), NitroError> {
if expected_pcrs.len() != 3 || self.pcrs.len() != 3 {
if expected_pcrs.len() != 3 {
return Err(NitroError::InvalidPcrs);
}
let mut is_match = true;
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/src/unit_tests/attestation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use super::attestation_verify_inner;
use fastcrypto::encoding::Encoding;
use fastcrypto::encoding::{Base64, Hex};

#[test]
fn attestation_parse() {
let res = attestation_verify_inner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use smallvec::smallvec;
use std::collections::VecDeque;
use sui_types::attestation::attestation_verify_inner;
pub fn nitro_attestation_verify(
context: &mut NativeContext,
_context: &mut NativeContext,
ty_args: Vec<Type>,
mut args: VecDeque<Value>,
) -> PartialVMResult<NativeResult> {
Expand Down

0 comments on commit 74299af

Please sign in to comment.