Skip to content

Commit

Permalink
feat: niporep
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed May 29, 2024
1 parent 201c990 commit 0035005
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 34 deletions.
35 changes: 20 additions & 15 deletions cgo/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ const (
)

const (
RegisteredSealProofStackedDrg2KiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG2_KI_B_V1
RegisteredSealProofStackedDrg8MiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG8_MI_B_V1
RegisteredSealProofStackedDrg512MiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG512_MI_B_V1
RegisteredSealProofStackedDrg32GiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG32_GI_B_V1
RegisteredSealProofStackedDrg64GiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG64_GI_B_V1
RegisteredSealProofStackedDrg2KiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG2_KI_B_V1_1
RegisteredSealProofStackedDrg8MiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG8_MI_B_V1_1
RegisteredSealProofStackedDrg512MiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG512_MI_B_V1_1
RegisteredSealProofStackedDrg32GiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG32_GI_B_V1_1
RegisteredSealProofStackedDrg64GiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG64_GI_B_V1_1
RegisteredSealProofStackedDrg2KiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG2_KI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg8MiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG8_MI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg512MiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG512_MI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg32GiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG32_GI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg64GiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG64_GI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg2KiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG2_KI_B_V1
RegisteredSealProofStackedDrg8MiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG8_MI_B_V1
RegisteredSealProofStackedDrg512MiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG512_MI_B_V1
RegisteredSealProofStackedDrg32GiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG32_GI_B_V1
RegisteredSealProofStackedDrg64GiBV1 = C.REGISTERED_SEAL_PROOF_STACKED_DRG64_GI_B_V1
RegisteredSealProofStackedDrg2KiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG2_KI_B_V1_1
RegisteredSealProofStackedDrg8MiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG8_MI_B_V1_1
RegisteredSealProofStackedDrg512MiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG512_MI_B_V1_1
RegisteredSealProofStackedDrg32GiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG32_GI_B_V1_1
RegisteredSealProofStackedDrg64GiBV11 = C.REGISTERED_SEAL_PROOF_STACKED_DRG64_GI_B_V1_1
RegisteredSealProofStackedDrg2KiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG2_KI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg8MiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG8_MI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg512MiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG512_MI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg32GiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG32_GI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg64GiBV11_Feat_SyntheticPoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG64_GI_B_V1_1__FEAT__SYNTHETIC_PO_REP
RegisteredSealProofStackedDrg2KiBV1_2_Feat_NonInteractivePoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG2_KI_B_V1_2__FEAT__NON_INTERACTIVE_PO_REP
RegisteredSealProofStackedDrg8MiBV1_2_Feat_NonInteractivePoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG8_MI_B_V1_2__FEAT__NON_INTERACTIVE_PO_REP
RegisteredSealProofStackedDrg512MiBV1_2_Feat_NonInteractivePoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG512_MI_B_V1_2__FEAT__NON_INTERACTIVE_PO_REP
RegisteredSealProofStackedDrg32GiBV1_2_Feat_NonInteractivePoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG32_GI_B_V1_2__FEAT__NON_INTERACTIVE_PO_REP
RegisteredSealProofStackedDrg64GiBV1_2_Feat_NonInteractivePoRep = C.REGISTERED_SEAL_PROOF_STACKED_DRG64_GI_B_V1_2__FEAT__NON_INTERACTIVE_PO_REP
)

const (
Expand Down
9 changes: 9 additions & 0 deletions cgo/proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ func SealCommitPhase2(sealCommitPhase1Output SliceRefUint8, sectorId uint64, pro
return resp.value.copy(), nil
}

func SealCommitPhase2CircuitProofs(sealCommitPhase1Output SliceRefUint8, sectorId uint64) ([]byte, error) {
resp := C.seal_commit_phase2_circuit_proofs(sealCommitPhase1Output, C.uint64_t(sectorId))
defer resp.destroy()
if err := CheckErr(resp); err != nil {
return nil, err
}
return resp.value.copy(), nil
}

func AggregateSealProofs(registeredProof RegisteredSealProof, registeredAggregation RegisteredAggregationProof, commRs SliceRefByteArray32, seeds SliceRefByteArray32, sealCommitResponses SliceRefSliceBoxedUint8) ([]byte, error) {
resp := C.aggregate_seal_proofs(registeredProof, registeredAggregation, commRs, seeds, sealCommitResponses)
defer resp.destroy()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/filecoin-project/go-address v1.1.0
github.com/filecoin-project/go-fil-commcid v0.1.0
github.com/filecoin-project/go-state-types v0.13.1
github.com/filecoin-project/go-state-types v0.14.0-dev.0.20240529001730-3bfff718e9cc
github.com/ipfs/go-block-format v0.0.3
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-ipfs-blockstore v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/filecoin-project/go-crypto v0.0.1 h1:AcvpSGGCgjaY8y1az6AMfKQWreF/pWO2
github.com/filecoin-project/go-crypto v0.0.1/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
github.com/filecoin-project/go-fil-commcid v0.1.0 h1:3R4ds1A9r6cr8mvZBfMYxTS88OqLYEo6roi+GiIeOh8=
github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-state-types v0.13.1 h1:4CivvlcHAIoAtFFVVlZtokynaMQu5XLXGoTKhQkfG1I=
github.com/filecoin-project/go-state-types v0.13.1/go.mod h1:cHpOPup9H1g2T29dKHAjC2sc7/Ef5ypjuW9A3I+e9yY=
github.com/filecoin-project/go-state-types v0.14.0-dev.0.20240529001730-3bfff718e9cc h1:waUN6BYKWlun/O5fT1Fo5/7xtKv98tTG1UWdzZN8Lxk=
github.com/filecoin-project/go-state-types v0.14.0-dev.0.20240529001730-3bfff718e9cc/go.mod h1:cHpOPup9H1g2T29dKHAjC2sc7/Ef5ypjuW9A3I+e9yY=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand Down
18 changes: 18 additions & 0 deletions proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ func SealCommitPhase2(
return cgo.SealCommitPhase2(cgo.AsSliceRefUint8(phase1Output), uint64(sectorNum), &proverID)
}

// SealCommitPhase2CircuitProofs runs a non-interactive proof and returns the circuit proof bytes
// rather than the aggregated proof bytes. This is used to aggregate multiple non-interactive
// proofs as the aggregated single proof outputs can't further be aggregated.
func SealCommitPhase2CircuitProofs(phase1Output []byte, sectorNum abi.SectorNumber) ([]byte, error) {
return cgo.SealCommitPhase2CircuitProofs(cgo.AsSliceRefUint8(phase1Output), uint64(sectorNum))
}

// TODO AggregateSealProofs it only needs InteractiveRandomness out of the aggregateInfo.Infos
func AggregateSealProofs(aggregateInfo proof.AggregateSealVerifyProofAndInfos, proofs [][]byte) (out []byte, err error) {
sp, err := toFilRegisteredSealProof(aggregateInfo.SealProof)
Expand Down Expand Up @@ -1030,6 +1037,17 @@ func toFilRegisteredSealProof(p abi.RegisteredSealProof) (cgo.RegisteredSealProo
case abi.RegisteredSealProof_StackedDrg64GiBV1_1_Feat_SyntheticPoRep:
return cgo.RegisteredSealProofStackedDrg64GiBV11_Feat_SyntheticPoRep, nil

case abi.RegisteredSealProof_StackedDrg2KiBV1_2_Feat_NiPoRep:
return cgo.RegisteredSealProofStackedDrg2KiBV1_2_Feat_NonInteractivePoRep, nil
case abi.RegisteredSealProof_StackedDrg8MiBV1_2_Feat_NiPoRep:
return cgo.RegisteredSealProofStackedDrg8MiBV1_2_Feat_NonInteractivePoRep, nil
case abi.RegisteredSealProof_StackedDrg512MiBV1_2_Feat_NiPoRep:
return cgo.RegisteredSealProofStackedDrg512MiBV1_2_Feat_NonInteractivePoRep, nil
case abi.RegisteredSealProof_StackedDrg32GiBV1_2_Feat_NiPoRep:
return cgo.RegisteredSealProofStackedDrg32GiBV1_2_Feat_NonInteractivePoRep, nil
case abi.RegisteredSealProof_StackedDrg64GiBV1_2_Feat_NiPoRep:
return cgo.RegisteredSealProofStackedDrg64GiBV1_2_Feat_NonInteractivePoRep, nil

default:
return 0, errors.Errorf("no mapping to C.FFIRegisteredSealProof value available for: %v", p)
}
Expand Down
48 changes: 36 additions & 12 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ rayon = "1.2.1"
anyhow = "1.0.23"
serde_json = "1.0.46"
rust-gpu-tools = { version = "0.7", optional = true, default-features = false }
fvm4 = { package = "fvm", version = "~4.2.0", default-features = false, features = ["nv23-dev"] }
fvm4_shared = { package = "fvm_shared", version = "~4.2.0" }
fvm4 = { package = "fvm", version = "4", default-features = false, features = ["nv23-dev", "verify-signature"], path = "/home/rvagg/git/pl/filecoin-project/ref-fvm/fvm/" }
fvm4_shared = { package = "fvm_shared", version = "4", path = "/home/rvagg/git/pl/filecoin-project/ref-fvm/shared/" }
fvm3 = { package = "fvm", version = "~3.9.0", default-features = false }
fvm3_shared = { package = "fvm_shared", version = "~3.6.0" }
fvm2 = { package = "fvm", version = "~2.7", default-features = false }
fvm2_shared = { package = "fvm_shared", version = "~2.6" }
fvm_ipld_encoding = "0.4.0"
fvm_ipld_blockstore = "0.2.0"
fvm_ipld_blockstore = { version = "0.2.1" }
num-traits = "0.2.14"
cid = { version = "0.10.1", features = ["serde-codec"] }
lazy_static = "1.4.0"
serde = "1.0.117"
serde_tuple = "0.5"
safer-ffi = { version = "0.0.7", features = ["proc_macros"] }
filecoin-proofs-api = { version = "18.0", default-features = false }
filecoin-proofs-api = { version = "18.0", default-features = false, path = "/home/rvagg/git/pl/filecoin-project/rust-filecoin-proofs-api/" }
yastl = "0.1.2"

[dev-dependencies]
Expand Down
30 changes: 30 additions & 0 deletions rust/src/proofs/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,36 @@ fn seal_commit_phase2(
})
}

/// This function generates a variant of the circuit proof for the second phase of the sealing
/// process. It takes as input the output from the first phase of the sealing process
/// [`seal_commit_phase1`] and a sector ID.
///
/// This variant of `seal_commit_phase2` is intended specifically for returning the circuit proofs
/// of a NonInteractivePoRep proof, such that it can later be aggregated with other
/// NonInteractivePoRep proofs.
///
/// # Arguments
///
/// * `seal_commit_phase1_output` - A reference to a slice of bytes representing the output from the
/// first phase of the sealing process.
/// * `sector_id` - A 64-bit integer representing the sector ID.
///
/// # Returns
/// This function returns a `SealCommitPhase2Response` wrapped in a `repr_c::Box`. This response
/// includes the proof generated in this phase of the sealing process.
#[ffi_export]
fn seal_commit_phase2_circuit_proofs(
seal_commit_phase1_output: c_slice::Ref<u8>,
sector_id: u64,
) -> repr_c::Box<SealCommitPhase2Response> {
catch_panic_response("seal_commit_phase2_circuit_proofs", || {
let scp1o = serde_json::from_slice(&seal_commit_phase1_output)?;
let result = seal::seal_commit_phase2_circuit_proofs(scp1o, SectorId::from(sector_id))?;

Ok(result.proof.into_boxed_slice().into())
})
}

/// TODO: document
#[ffi_export]
fn generate_synth_proofs(
Expand Down

0 comments on commit 0035005

Please sign in to comment.