Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode input #788

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion vm/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func LoadPayload(task *task.Task, projectConfig *project.Config) ([]byte, error)
case _pebbleProjectID.String():
return encodePebblePayload(task, projectConfig)
case _geoProjectID.String():
panic("not implemented")
return encodeGeodnetPayload(task, projectConfig)
default:
return task.Payload, nil
}
Expand Down Expand Up @@ -66,3 +66,67 @@ func encodePebblePayload(task *task.Task, projectConfig *project.Config) ([]byte
}
return witness.MarshalBinary()
}

type ProofofMovenessCircuit struct {
LastPayloadHash []uints.U8
LastTimestamp frontend.Variable
LastLatitude frontend.Variable
LastLongitude frontend.Variable
LastSigBytes []uints.U8

CurPayloadHash []uints.U8
CurTimestamp frontend.Variable `gnark:",public"`
CurLatitude frontend.Variable
CurLongitude frontend.Variable
CurSigBytes []uints.U8

IsMoved frontend.Variable `gnark:",public"`

PubBytes []uints.U8 `gnark:",public"`
}

func (circuit *ProofofMovenessCircuit) Define(api frontend.API) error { return nil }

func encodeGeodnetPayload(task *task.Task, projectConfig *project.Config) ([]byte, error) {
// TODO: loaded from task
lastPayloadHash := []byte{}
lastTimestamp := 0
lastLatitude := uint64(3)
lastLongitude := uint64(51)
lastSig := []byte{}
curPayloadHash := []byte{}
curTimestamp := 0
curLatitude := uint64(12523)
curLongitude := uint64(10)
curSig := []byte{}
isMove := (abs(lastLatitude, curLatitude) > 10^3) || (abs(lastLongitude, curLongitude) > 10^3)

assignment := ProofofMovenessCircuit{
LastPayloadHash: uints.NewU8Array(lastPayloadHash[:]),
LastTimestamp: lastTimestamp,
LastLatitude: lastLatitude,
LastLongitude: lastLongitude,
LastSigBytes: uints.NewU8Array(lastSig[:]),

CurPayloadHash: uints.NewU8Array(curPayloadHash[:]),
CurTimestamp: curTimestamp,
CurLatitude: curLatitude,
CurLongitude: curLongitude,
CurSigBytes: uints.NewU8Array(curSig[:]),

IsMoved: isMove,
PubBytes: uints.NewU8Array(task.DevicePubKey),
}
witness, err := frontend.NewWitness(&assignment, ecc.BN254.ScalarField())
if err != nil {
return nil, err
}
return witness.MarshalBinary()
}

func abs(a, b uint64) uint64 {
if a > b {
return a - b
}
return b - a
}
Loading