forked from sammy007/go-equihash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
equi_test.go
62 lines (50 loc) · 12.7 KB
/
equi_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package equihash
import (
"encoding/hex"
"testing"
)
func TestEthashVerifyWithTargetInvalid(t *testing.T) {
h, _ := hex.DecodeString("0400000008e9694cc2120ec1b5733cc12687b609058eec4f7046a521ad1d1e3049b400003e7420ed6f40659de0305ef9b7ec037f4380ed9848bc1c015691c90aa16ff3930000000000000000000000000000000000000000000000000000000000000000c9310d5874e0001f")
n, _ := hex.DecodeString("000000000000000000000000000000010b000000000000000000000000000040")
h = append(h, n...)
sol, _ := hex.DecodeString("00b43863a213bfe79f00337f5a729f09710abcc07035ef8ac34372abddecf2f82715f7223f075af96f0604fc124d6151fc8fb516d24a137faec123a89aa9a433f8a25a6bcfc554c28be556f6c878f96539186fab191505f278df48bf1ad2240e5bb39f372a143de1dd1b672312e00d52a3dd83f471b0239a7e8b30d4b9153027df87c8cd0b64de76749539fea376b4f39d08cf3d5e821495e52fdfa6f8085e59fc670656121c9d7c01388c8b4b4585aa7b9ac3f7ae796f9eb1fadba1730a1860eed797feabb18832b5e8f003c0adaf0788d1016e7a8969144018ecc86140aa4553962aa739a4850b509b505e158c5f9e2d5376374652e9e6d81b19fa0351be229af136efbce681463cc53d7880c1eeca3411154474ff8a7b2bac034a2026646776a517bf63921c31fbbd6be7c3ff42aab28230bfe81d33800b892b262f3579b7a41925a59f5cc1d4f523577c19ff9f92023146fa26486595bd89a1ba459eb0b5cec0578c3a071dbec73eca054c723ab30ce8e69de32e779cd2f1030e39878ac6ea3cdca743b43aedefe1a9b4f2da861038e2759defef0b8cad11d4179f2f08881b53ccc203e558c0571e049d998a257b3279016aad0d7999b609f6331a0d0f88e286a70432ca7f50a5bb8fafbbe9230b4ccb1fa57361c163d6b9f84579d61f41585a022d07dc8e55a8de4d8f87641dae777819458a2bf1bb02c438480ff11621ca8442ec2946875cce247c8877051359e9c822670d37bb00fa806e60e8e890ce62540fda2d5b1c790ca1e005030ac6d8e63db577bb98be111ee146828f9c48ee6257d7627b93ea3dd11aac3412e63dfc7ca132a73c4f51e7650f3f8ecf57bfc18716990b492d50e0a3e5fbf6136e771b91f7283ec3326209265b9531d157f8a07a4117fc8fb29ba1363afc6f9f0608251ea595256727a5bbe28f42a42edfbfa9017680e32980d4ad381612612b2bc7ad91e82eca693ea4fc27049a99636b50a576f1e55c72202d582b150ef194c1419f53177ecf315ea6b0e2f1aa8cd8f59b165aa0d89561c537fb6141f5813b7a4968fe16afc703326113f68508d88ff8d0aee1e88a84c0ae56c72f27511290ced48e93e8c95419d14aed1a5b2e9b2c9c1070c593e5eb50bb9a80e14e9f9fe501f56b1b3140159e8213b75d48d14af472a604484cd8e7e7abb6820245ed3ab29f9947463a033c586194be45eadec8392c8614d83a1e9ca0fe5655fa14f7a9c1d1f8f2185a06193ff4a3c3e9a96b02310033ceaa25894e7c56a6147e691597098054e285d39656d3d459ec5d13243c062b6eb44e19a13bdfc0b3c96bd3d1aeb75bb6b080322aea23555993cb529243958bb1a0e5d5027e6c78155437242d1d13c1d6e442a0e3783147a08bbfc0c2529fb705ad27713df40486fd58f001977f25dfd3c202451c07010a3880bca63959ca61f10ed3871f1152166fce2b52135718a8ceb239a0664a31c62defaad70be4b920dce70549c10d9138fbbad7f291c5b73fa21c3889929b143bc1576b72f70667ac11052b686891085290d871db528b5cfdc10a6d563925227609f10d1768a0e02dc7471ad424f94f737d4e7eb0fb167f1434fc4ae2d49e152f06f0845b6db0a44f0d6f5e7410420e6bd1f430b1af956005bf72b51405a04d9a5d9906ceca52c22c855785c3c3ac4c3e9bf532d31bab321e1db66f6a9f7dc9c017f2b7d8dfeb933cf5bbae71311ae318f6d187ebc5c843be342b08a9a0ff7c4b9c4b0f4fa74b13296afe84b6481440d58332e07b3d051ed55219d28e77af6612134da4431b797c63ef55bc53831e2f421db620fee51ba0967e4ed7009ef90af2204259bbfbb54537fd35c2132fa8e7f9c84bf9938d248862c6ca1cca9f48b0b33aa1589185c4eabc1c32")
if !Verify(h, sol) {
t.Errorf("Must be correct solution")
}
h[0] = byte(1)
if Verify(h, sol) {
t.Errorf("Must be incorrect solution")
}
h[0] = byte(4)
sol[0] = byte(1)
if Verify(h, sol) {
t.Errorf("Must be incorrect solution")
}
}
func TestEthashVerifyWithDuplicates(t *testing.T) {
h, _ := hex.DecodeString("040000000fa70ccb2e9ba029f85cbe32581ce55acf1fe9c58462e4ed1ef7e7440100000023dedf461c6f02a0f68855763231ee8c9b5285df91540e6b72c092b76a0eb33e0000000000000000000000000000000000000000000000000000000000000000e3882358a298021d")
n, _ := hex.DecodeString("65080b63ea72fd94c258ca8c08315de88ed97c61000000000000000000000000")
h = append(h, n...)
sol, _ := hex.DecodeString("00c94770c254c45779d1c04ca145f6883466d1d61c06f0536319c3e8e629b0f37a7d9efab9bf5c8f77e212f0a7219f20d40308fec5aee035b382a40c3d71795ef535032c218855e20f0db47dfc850b9bf95ee6a209f8b9ebc558dffb7d32e27aee711fc1e218df8d5c304fa9c9c2290859c273c38c19392cc94a4555aa3c0a34dc408e5c1c7ce63442d57a176e451f4d4c499a46210c3700179bb8de65a5bb0ef53f7da98a52331f07df0769f9e0aec5d394b20c06faaa7e3c6fd875a90a774ed77232d4779dfb5291fe6a8e051ed60fa4e30e1bfd4ed9596bdbaa4356933fddcea5f92c5d92f32754056a588bed4abf84a53cb55499fdb7a15879da09e9318d7943c69fcd0c84189543bf8294ff766bb519153b25dc96580ab6e74245b265d4792c40b6dc9e0a43ca8d46cb331b1248c0a9e45f85e967e6bb01630ab2c31fab0550bca13f91b89b13dc513ae7161fc5049af0fa754ca8c2b5c80b2782f25b0fc7eb1e46aa063f33ae185ae4c0e4e5853741de6879b64c9e70970b5863b80c0c6a7abc18421316fcc2a605cef2ec340eefddb67685b65aa69e4210fd9fecbe1abedbd9810570bfe872187ab4f83e72772068d8ccbd07ee785d0ab5d3af275d40bb419616f3a951afa9fb5e319cf9067077fdb4a57691a1ee73fa6cc6be6166e65f11982229dacf2cd60159ae079761924e8676d56edd1a340921244660dc60916fa1e0ded58bb32899372637f821018e18798f0c71dd2dd542df5dca2dee9dfbc9790985d1aeebd08b6d20df14253ef8c8a28516dec2e119fe42794c71333bbef701f3697be67da95fdb1995117bc7a8cc597e05a951d1d7356dcf1d85af51fb5814122d34b9201887ab8427d1564a86f7a9703f70ec2fb3f58edf0cecbd9ff874d1875a92fa1ed93eac6430765c62c828c025f2f9776bb766692e6bf03eb25c00c94770c254c45779d1c04ca145f6883466d1d61c06f0536319c3e8e629b0f37a7d9efab9bf5c8f77e212f0a7219f20d40308fec5aee035b382a40c3d71795ef535032c218855e20f0db47dfc850b9bf95ee6a209f8b9ebc558dffb7d32e27aee711fc1e218df8d5c304fa9c9c2290859c273c38c19392cc94a4555aa3c0a34dc408e5c1c7ce63442d57a176e451f4d4c499a46210c3700179bb8de65a5bb0ef53f7da98a52331f07df0769f9e0aec5d394b20c06faaa7e3c6fd875a90a774ed77232d4779dfb5291fe6a8e051ed60fa4e30e1bfd4ed9596bdbaa4356933fddcea5f92c5d92f32754056a588bed4abf84a53cb55499fdb7a15879da09e9318d7943c69fcd0c84189543bf8294ff766bb519153b25dc96580ab6e74245b265d4792c40b6dc9e0a43ca8d46cb331b1248c0a9e45f85e967e6bb01630ab2c31fab0550bca13f91b89b13dc513ae7161fc5049af0fa754ca8c2b5c80b2782f25b0fc7eb1e46aa063f33ae185ae4c0e4e5853741de6879b64c9e70970b5863b80c0c6a7abc18421316fcc2a605cef2ec340eefddb67685b65aa69e4210fd9fecbe1abedbd9810570bfe872187ab4f83e76f3a951afa9fb5e319cf90ab5d3af275d40bb419612772068d8ccbd07ee785d067077fdb4a57691a1ee73fa6cc6be6166e65f11982229dacf2cd60159ae079761924e8676d56edd1a340921244660dc60916fa1e0ded58bb32899372637f821018e18798f0c71dd2dd542df5dca2dee9dfbc9790985d1aeebd08b6d20df14253ef8c8a28516dec2e119fe42794c71333bbef701f3697be67da95fdb1995117bc7a8cc597e05a951d1d7356dcf1d85af51fb5814122d34b9201887ab8427d1564a86f7a9703f70ec2fb3f58edf0cecbd9ff874d1875a92fa1ed93eac6430765c62c828c025f2f9776bb766692e6bf03eb25c")
if Verify(h, sol) {
t.Errorf("Must be incorrect solution")
}
}
func TestIncorrectlySorted(t *testing.T) {
h, _ := hex.DecodeString("0400000085efd9eee39b2efe73b7b8d44a8c17059ac951086175172f6d1d7fba00000000b00f66741e25e8c48d54d18d49c4802376e968e7c18550240a28d3aef4419f34000000000000000000000000000000000000000000000000000000000000000079bc29588f8a011d")
n, _ := hex.DecodeString("6df64c159311c3e05ea8bcfcfca71efa2529e73e000000000000000000000000")
h = append(h, n...)
sol, _ := hex.DecodeString("5b9c0cc8ff912fd516a2d65256bc2eb1523b911f7e021b0438a0c24891b1b2b3ccc3c684d50b7ecbcfb3b39677cf14882cd9f41a88b3a654ec5d6febf73c0703c465cafb629b035b35c250954b28c0bb59ee2ebcbc0adf343d194681743dc685a82d4f6212d577f12022d001e92f0fb2ec8f078029bb33a96d4ad83f032427478ee5c2a2e979426a787a1f4fbdbda9e53f960d26899b0591931ab9fb910ae199cad5302cebeac60d7470447219c5ac01a90679d825e861a24c01fb8c22434137f199499597f33ef713ba3dbbe5aa905c77498fe4053da710937f127e7834e4e892c4884e5eb7d6678f3479b58b3462b083e77cf6e9333a0d7d51949a624d1af8350ed8b31702eb13b7ef8ac079a8b9c1492cfc9a4292eb0151d1c8a3bb54796fa51fc9ffbb50c8a527e06a9da0dd1a4ec0c515f44fc72e203917e4de3b8f4fa242c7e24cf115e407e7fedcce42f87a1ddabaa77c088124dd6182f9ec5554e8fb4e1cdf8c0ba90f4e8be55c770fb5e8c49985313d580960234193b7ccdf0fbfd503274578a6dfa5fd91003fdbf2aca95a73850791773327f765750c5f4151867874d5ec3f2ddb9e10f0dbfb25d9bf23ea966f9a228f43dd2fe55c43027e6629cd976526f28a1d9e53a92b4cbf492310f675e7d74896d3a560a352a7c0e45867b6b5e0d906d69435fb21dd6725806ddba170d371763cf8dfde32a823f9874c83d93f869bb5a9f8b2d168f05286ada97b4f6b4948fa310e3cc87d9f6e8bb74b371dff52697e1383b99a23632a9a338f4fd137d26950bfec652fadb68b65564f3f45416e5d71f4e6791294144eab04719c6058afbd71cbb6a63bbf59efc1c7a575842149885ec49369c63df62c1209e3c82028bb84f4c13063a47d0efe8c4e2ef87f5460695d0e3c0e09b960a12d521dd50c10115cce5ca21a27f7031acd695e188184d69f87f357363b064745a43dea18689a090ea082baff9e427d87374b12fcf0d7fce3db10aa9a87a6fc31f54ab515c0c46fa246d24fddfe54e1ea40d0f6a3667505709878beedec3913985fd9cd440d17d50ce217a421b2588c846f62a09290a1bd23d18bf0117e264585fb1601436be310a58314ecce791c2ae41fad6d206c646a5d9e2fd15c340158a894d50524fc777901ba27af9b8e4f6660b75b45fa317d82f08efdbead3135b0ba42aa155e6ef1bcca25e0d21c1edd641d5c2689865f7b6803de967721425898cbee28f6ace5c0f74cca243b90486cb1d9a2e19be037c908a17a249098322b47e4c903844097db806feed88044afa126f69c2e181aafc0af13ed9414b65f137109a42eb4bef89b58915cedc1cae84cbd18385557fd636c03624c16c587581c050a51780d02d9a1220f521ca4d2c14fde92486962d80f132f61c888b328bb3e5f3c4a24879b54515244844581fbabf99fa3840f3bf7bce746969841a704fedbb4dd2453d53ef88123579244e34292a457718d76235d4a62866d0aa4672b2f6bc650601f073c66a16d3672e6a0c3a95566742a316bfd49cb7ea3b11ea12ffe1562fa997d89335d734443811124db77f30511459e9947b34c4b5297a2227a81a07dd2265bc9412675e5528a8a2a9761e0c71384a7b16496b13c18503aea6ea391f5b5328ee0cd82b840d2486bf61cab1dffec33358f1b30f73330c2593166f1278b5405a43f4d239b93c784ea9953f1be81d19b1988bbb51b191331d37d47c570555978433a6c696fa2e7af39aeee8f9c248bed9115acb1558418eab0e59d3bcd53880fa512b590fa5c2501335753ea8870f9b9f0fa1b6d2a86acc4e2e90537e85e524221fb20a8e109799489792b8eaa5a3272d747f97fe57dbcc8c9e06e50ad6d4cb005ee6e0ad2f7558f3b87f0106428ad11ee148817")
if Verify(h, sol) {
t.Errorf("Must be incorrect solution")
}
}
func BenchmarkVerify(b *testing.B) {
h, _ := hex.DecodeString("0400000008e9694cc2120ec1b5733cc12687b609058eec4f7046a521ad1d1e3049b400003e7420ed6f40659de0305ef9b7ec037f4380ed9848bc1c015691c90aa16ff3930000000000000000000000000000000000000000000000000000000000000000c9310d5874e0001f")
n, _ := hex.DecodeString("000000000000000000000000000000010b000000000000000000000000000040")
h = append(h, n...)
sol, _ := hex.DecodeString("00b43863a213bfe79f00337f5a729f09710abcc07035ef8ac34372abddecf2f82715f7223f075af96f0604fc124d6151fc8fb516d24a137faec123a89aa9a433f8a25a6bcfc554c28be556f6c878f96539186fab191505f278df48bf1ad2240e5bb39f372a143de1dd1b672312e00d52a3dd83f471b0239a7e8b30d4b9153027df87c8cd0b64de76749539fea376b4f39d08cf3d5e821495e52fdfa6f8085e59fc670656121c9d7c01388c8b4b4585aa7b9ac3f7ae796f9eb1fadba1730a1860eed797feabb18832b5e8f003c0adaf0788d1016e7a8969144018ecc86140aa4553962aa739a4850b509b505e158c5f9e2d5376374652e9e6d81b19fa0351be229af136efbce681463cc53d7880c1eeca3411154474ff8a7b2bac034a2026646776a517bf63921c31fbbd6be7c3ff42aab28230bfe81d33800b892b262f3579b7a41925a59f5cc1d4f523577c19ff9f92023146fa26486595bd89a1ba459eb0b5cec0578c3a071dbec73eca054c723ab30ce8e69de32e779cd2f1030e39878ac6ea3cdca743b43aedefe1a9b4f2da861038e2759defef0b8cad11d4179f2f08881b53ccc203e558c0571e049d998a257b3279016aad0d7999b609f6331a0d0f88e286a70432ca7f50a5bb8fafbbe9230b4ccb1fa57361c163d6b9f84579d61f41585a022d07dc8e55a8de4d8f87641dae777819458a2bf1bb02c438480ff11621ca8442ec2946875cce247c8877051359e9c822670d37bb00fa806e60e8e890ce62540fda2d5b1c790ca1e005030ac6d8e63db577bb98be111ee146828f9c48ee6257d7627b93ea3dd11aac3412e63dfc7ca132a73c4f51e7650f3f8ecf57bfc18716990b492d50e0a3e5fbf6136e771b91f7283ec3326209265b9531d157f8a07a4117fc8fb29ba1363afc6f9f0608251ea595256727a5bbe28f42a42edfbfa9017680e32980d4ad381612612b2bc7ad91e82eca693ea4fc27049a99636b50a576f1e55c72202d582b150ef194c1419f53177ecf315ea6b0e2f1aa8cd8f59b165aa0d89561c537fb6141f5813b7a4968fe16afc703326113f68508d88ff8d0aee1e88a84c0ae56c72f27511290ced48e93e8c95419d14aed1a5b2e9b2c9c1070c593e5eb50bb9a80e14e9f9fe501f56b1b3140159e8213b75d48d14af472a604484cd8e7e7abb6820245ed3ab29f9947463a033c586194be45eadec8392c8614d83a1e9ca0fe5655fa14f7a9c1d1f8f2185a06193ff4a3c3e9a96b02310033ceaa25894e7c56a6147e691597098054e285d39656d3d459ec5d13243c062b6eb44e19a13bdfc0b3c96bd3d1aeb75bb6b080322aea23555993cb529243958bb1a0e5d5027e6c78155437242d1d13c1d6e442a0e3783147a08bbfc0c2529fb705ad27713df40486fd58f001977f25dfd3c202451c07010a3880bca63959ca61f10ed3871f1152166fce2b52135718a8ceb239a0664a31c62defaad70be4b920dce70549c10d9138fbbad7f291c5b73fa21c3889929b143bc1576b72f70667ac11052b686891085290d871db528b5cfdc10a6d563925227609f10d1768a0e02dc7471ad424f94f737d4e7eb0fb167f1434fc4ae2d49e152f06f0845b6db0a44f0d6f5e7410420e6bd1f430b1af956005bf72b51405a04d9a5d9906ceca52c22c855785c3c3ac4c3e9bf532d31bab321e1db66f6a9f7dc9c017f2b7d8dfeb933cf5bbae71311ae318f6d187ebc5c843be342b08a9a0ff7c4b9c4b0f4fa74b13296afe84b6481440d58332e07b3d051ed55219d28e77af6612134da4431b797c63ef55bc53831e2f421db620fee51ba0967e4ed7009ef90af2204259bbfbb54537fd35c2132fa8e7f9c84bf9938d248862c6ca1cca9f48b0b33aa1589185c4eabc1c32")
for i := 0; i < b.N; i++ {
Verify(h, sol)
}
}