The encoding of a unsealed data into the replica data with a sector key is simple field additions. The Rust source is at https://github.com/filecoin-project/rust-fil-proofs/blob/fcb22da26b2ac6ea6acafd1da41cc4f098ae332b/storage-proofs-porep/src/encode.rs.
The following is a translation into a Python-like pseudo code, where I add the Go functions to call as comments.
def encode(key_bytes, value_bytes):
'''`key_bytes` and `value_bytes` are each 32 bytes long.
'''
# https://pkg.go.dev/github.com/consensys/gnark-crypto@v0.10.0/ecc/bls12-381/fr#Element.SetBytes
key = key_bytes.to_field_element()
value = value.bytes.to_field_element()
# https://pkg.go.dev/github.com/consensys/gnark-crypto@v0.10.0/ecc/bls12-381/fr#Element.Add
key += value
decode
is the same, except that the value is subtracted from the key.
Some background information. We operate on an elliptic curve called BLS12-381
. We are using the Scalar field, in this context often referred as Fr
.