Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-sectorbuilder
Commits
06775780
Unverified
Commit
06775780
authored
Oct 31, 2019
by
Erin Swenson-Healey
Committed by
GitHub
Oct 31, 2019
Browse files
feat(comm_d): verify_seal no longer needs pieces, just comm_d (#41)
- also expose a function to compute comm_d from pieces
parent
e8231db9
Changes
3
Hide whitespace changes
Inline
Side-by-side
bindings.go
View file @
06775780
...
...
@@ -166,7 +166,6 @@ func VerifySeal(
seed
[
32
]
byte
,
sectorID
uint64
,
proof
[]
byte
,
pieces
[]
PublicPieceInfo
,
)
(
bool
,
error
)
{
defer
elapsed
(
"VerifySeal"
)()
...
...
@@ -188,9 +187,6 @@ func VerifySeal(
seedCBytes
:=
C
.
CBytes
(
seed
[
:
])
defer
C
.
free
(
seedCBytes
)
cPiecesPtr
,
cPiecesLen
:=
cPublicPieceInfo
(
pieces
)
defer
C
.
free
(
unsafe
.
Pointer
(
cPiecesPtr
))
// a mutable pointer to a VerifySealResponse C-struct
resPtr
:=
C
.
sector_builder_ffi_verify_seal
(
C
.
uint64_t
(
sectorSize
),
...
...
@@ -202,8 +198,6 @@ func VerifySeal(
(
*
[
32
]
C
.
uint8_t
)(
seedCBytes
),
(
*
C
.
uint8_t
)(
proofCBytes
),
C
.
size_t
(
len
(
proof
)),
(
*
C
.
sector_builder_ffi_FFIPublicPieceInfo
)(
cPiecesPtr
),
cPiecesLen
,
)
defer
C
.
sector_builder_ffi_destroy_verify_seal_response
(
resPtr
)
...
...
@@ -694,6 +688,26 @@ func GeneratePieceCommitment(piecePath string, pieceSize uint64) ([CommitmentByt
return
GeneratePieceCommitmentFromFile
(
pieceFile
,
pieceSize
)
}
// GenerateDataCommitment produces a commitment for the sector containing the
// provided pieces.
func
GenerateDataCommitment
(
sectorSize
uint64
,
pieces
[]
PublicPieceInfo
)
([
CommitmentBytesLen
]
byte
,
error
)
{
cPiecesPtr
,
cPiecesLen
:=
cPublicPieceInfo
(
pieces
)
defer
C
.
free
(
unsafe
.
Pointer
(
cPiecesPtr
))
resPtr
:=
C
.
sector_builder_ffi_generate_data_commitment
(
C
.
uint64_t
(
sectorSize
),
(
*
C
.
sector_builder_ffi_FFIPublicPieceInfo
)(
cPiecesPtr
),
cPiecesLen
)
defer
C
.
sector_builder_ffi_destroy_generate_data_commitment_response
(
resPtr
)
if
resPtr
.
status_code
!=
0
{
return
[
CommitmentBytesLen
]
byte
{},
errors
.
New
(
C
.
GoString
(
resPtr
.
error_msg
))
}
commDSlice
:=
goBytes
(
&
resPtr
.
comm_d
[
0
],
CommitmentBytesLen
)
var
commitment
[
CommitmentBytesLen
]
byte
copy
(
commitment
[
:
],
commDSlice
)
return
commitment
,
nil
}
// GeneratePieceCommitmentFromFile produces a piece commitment for the provided data
// stored in a given file.
func
GeneratePieceCommitmentFromFile
(
pieceFile
*
os
.
File
,
pieceSize
uint64
)
(
commP
[
CommitmentBytesLen
]
byte
,
err
error
)
{
...
...
bindings_test.go
View file @
06775780
...
...
@@ -89,6 +89,9 @@ func TestSectorBuilderLifecycle(t *testing.T) {
CommP
:
commP
,
}}
preComputedCommD
,
err
:=
sb
.
GenerateDataCommitment
(
1024
,
publicPieceInfoA
)
require
.
NoError
(
t
,
err
)
// seek to the beginning
_
,
err
=
pieceFileA
.
Seek
(
0
,
0
)
require
.
NoError
(
t
,
err
)
...
...
@@ -113,6 +116,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
sectorIDA
,
out
.
SectorID
)
require
.
Equal
(
t
,
ticketA
.
TicketBytes
,
out
.
Ticket
.
TicketBytes
)
require
.
True
(
t
,
bytes
.
Equal
(
preComputedCommD
[
:
],
out
.
CommD
[
:
]))
}()
// write a second piece to a staged sector, reducing remaining space to 0
...
...
@@ -161,7 +165,7 @@ func TestSectorBuilderLifecycle(t *testing.T) {
require
.
Equal
(
t
,
seedB
.
TicketBytes
,
statusB
.
Seed
.
TicketBytes
)
// verify the seal proof
isValid
,
err
:=
sb
.
VerifySeal
(
1024
,
statusA
.
CommR
,
statusA
.
CommD
,
proverID
,
ticketA
.
TicketBytes
,
seedA
.
TicketBytes
,
sectorIDA
,
statusA
.
Proof
,
publicPieceInfoA
)
isValid
,
err
:=
sb
.
VerifySeal
(
1024
,
statusA
.
CommR
,
statusA
.
CommD
,
proverID
,
ticketA
.
TicketBytes
,
seedA
.
TicketBytes
,
sectorIDA
,
statusA
.
Proof
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
isValid
)
...
...
rust-fil-sector-builder
@
0bb1e071
Compare
8ed121f6
...
0bb1e071
Subproject commit
8ed121f63c40e692860644c93c5cd76ea16c58a0
Subproject commit
0bb1e071fffff861d388109e119a24f5a202bd36
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment