You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.6 KiB

  1. // Copyright 2017-2018 DERO Project. All rights reserved.
  2. // Use of this source code in any form is governed by RESEARCH license.
  3. // license can be found in the LICENSE file.
  4. // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
  5. //
  6. //
  7. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  8. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  10. // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  13. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  14. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  15. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. package ringct
  17. import "fmt"
  18. /* this files handles the generation and verification in ringct full */
  19. // NOTE the transaction must have been expanded earlier and must have a key image, mixring etc
  20. // this is implementation of verRctMG from rctSigs.cpp file
  21. func (r *RctSig) VerifyRCTFull_Core() (result bool) {
  22. result = false
  23. if r.sigType != RCTTypeFull {
  24. if DEBUGGING_MODE {
  25. fmt.Printf("Signature NOT RingCT MG type, verification failed\n")
  26. }
  27. result = false
  28. return
  29. }
  30. // some sanity checking
  31. /* if len(r.MixRing) != 1 { // this is hard code 1 for rct mg
  32. if DEBUGGING_MODE {
  33. fmt.Printf("RingCT MG must have mixring rows 1\n")
  34. }
  35. result= false
  36. return
  37. }
  38. if len(r.MixRing[0]) <= 1 { // mixing should be more than 1
  39. if DEBUGGING_MODE {
  40. fmt.Printf("RingCT MG mixring cannot be 1 or less\n")
  41. }
  42. result= false
  43. return
  44. }*/
  45. pre_mlsag_hash := Key(Get_pre_mlsag_hash(r))
  46. txfeekey := Commitment_From_Amount(r.txFee)
  47. cols := len(r.MixRing)
  48. rows := len(r.MixRing[0])
  49. // fmt.Printf("cols %d rows %d \n", cols, rows)
  50. // if cols = 1 , if mixin = 5 , rows = 5
  51. // create a matrix of the form
  52. // 0 0
  53. // 1 1
  54. // 2 2
  55. // 3 3
  56. // 4 4
  57. // 5 5 // yes there is an extra row
  58. M := make([][]Key, cols)
  59. for i := 0; i < (cols); i++ {
  60. M[i] = make([]Key, rows+1, rows+1)
  61. for j := 0; j < (rows + 1); j++ { // yes there is an extra column
  62. M[i][j] = Identity // fill it with identity
  63. // fmt.Printf("M[%d][%d] %s\n",i,j, M[i][j])
  64. }
  65. }
  66. for j := 0; j < rows; j++ {
  67. for i := 0; i < cols; i++ {
  68. //fmt.Printf("j %d i %d \n", j,i)
  69. // fmt.Printf("f j %d i %d %s\n", j,i, M[i][j])
  70. //fmt.Printf("i %d rows %d \n", i, rows)
  71. M[i][j] = r.MixRing[i][j].Destination
  72. // fmt.Printf("f M[i][rows] == %s\n",M[i][rows]);
  73. AddKeys(&M[i][rows], &M[i][rows], &r.MixRing[i][j].Mask) //add Ci in last row
  74. // fmt.Printf("f M[i][rows] = %s\n",M[i][rows]);
  75. }
  76. }
  77. for i := 0; i < cols; i++ {
  78. for j := 0; j < len(r.OutPk); j++ {
  79. SubKeys(&M[i][rows], &M[i][rows], &r.OutPk[j].Mask) //subtract output Ci's in last row
  80. // fmt.Printf("s i %d j %d %s \n",i,j,M[i][rows]);
  81. }
  82. //subtract txn fee output in last row
  83. SubKeys(&M[i][rows], &M[i][rows], &txfeekey)
  84. // fmt.Printf("s M[i][rows] = %s\n",M[i][rows])
  85. }
  86. // do the mlsag verification
  87. result = MLSAG_Ver(pre_mlsag_hash, M, &r.MlsagSigs[0], rows, r)
  88. if DEBUGGING_MODE {
  89. if result {
  90. fmt.Printf("Signature Full successfully verified\n")
  91. } else {
  92. fmt.Printf("RCT MG signarure verification failed\n")
  93. }
  94. }
  95. return
  96. }