Skip to content

Commit

Permalink
encode input (#788)
Browse files Browse the repository at this point in the history
* encode input
  • Loading branch information
Liuhaai authored Dec 20, 2024
1 parent 4e9d5f8 commit 1fd30d4
Showing 1 changed file with 65 additions and 1 deletion.
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
}

0 comments on commit 1fd30d4

Please sign in to comment.