A very experimental PLC implementation which uses BFT consensus for decentralization
19
fork

Configure Feed

Select the types of activity you want to include in your feed.

Ensure block proof effort is not reusable across validators. Decrease proof production difficulty

gbl08ma ff46fdf4 cee59cdd

+21 -33
+7 -9
abciapp/block_challenge.go
··· 99 99 return zeroValue, stacktrace.Propagate(err) 100 100 } 101 101 102 - sharedPart := buildBlockChallengeCircuitAssignmentShared(lastCommitHash, [1550]byte(operationData)) 102 + sharedPart := buildBlockChallengeCircuitAssignmentShared(lastCommitHash, [proof.OperationDataLength]byte(operationData)) 103 103 104 104 return theine.Loaded[proof.BlockChallengeCircuit]{ 105 105 Value: sharedPart, ··· 295 295 return v, stacktrace.Propagate(err) 296 296 } 297 297 298 - func buildBlockChallengeCircuitAssignmentShared(lastCommitHash []byte, data [1550]byte) proof.BlockChallengeCircuit { 298 + func buildBlockChallengeCircuitAssignmentShared(lastCommitHash []byte, data [proof.OperationDataLength]byte) proof.BlockChallengeCircuit { 299 299 var assignment proof.BlockChallengeCircuit 300 - 301 - h := mimc.NewMiMC() 302 300 303 301 if len(lastCommitHash) > 31 { 304 302 lastCommitHash = lastCommitHash[len(lastCommitHash)-31:] 305 303 } 306 - h.Write(lastCommitHash) 307 304 assignment.LastCommitHash = lastCommitHash 308 305 309 306 for i := 0; i < len(assignment.OperationData); i++ { 310 307 d := data[31*i : 31*(i+1)] 311 308 assignment.OperationData[i] = d 312 - h.Write(d) 313 309 } 314 310 315 - sharedHash := h.Sum(nil) 316 - assignment.SharedHash = sharedHash 317 311 return assignment 318 312 } 319 313 ··· 321 315 h := mimc.NewMiMC() 322 316 323 317 h.Write(validatorAddress) 324 - h.Write(shared.SharedHash.([]byte)) 318 + h.Write(shared.LastCommitHash.([]byte)) 319 + 320 + for i := 0; i < len(shared.OperationData); i++ { 321 + h.Write(shared.OperationData[i].([]byte)) 322 + } 325 323 326 324 shared.ValidatorAddress = validatorAddress 327 325 shared.SpecificHash = h.Sum(nil)
abciapp/proofcircuit/BlockChallengeCircuit_ConstraintSystem

This is a binary file and will not be displayed.

abciapp/proofcircuit/BlockChallengeCircuit_ProvingKey

This is a binary file and will not be displayed.

abciapp/proofcircuit/BlockChallengeCircuit_VerifyingKey

This is a binary file and will not be displayed.

abciapp/proofcircuit/BlockChallenge_ConstraintSystem

This is a binary file and will not be displayed.

abciapp/proofcircuit/BlockChallenge_ProvingKey

This is a binary file and will not be displayed.

abciapp/proofcircuit/BlockChallenge_VerifyingKey

This is a binary file and will not be displayed.

+3 -11
proof/block_challenge.go
··· 5 5 "github.com/consensys/gnark/std/hash/mimc" 6 6 ) 7 7 8 - const OperationDataVariables = 50 8 + const OperationDataVariables = 25 9 9 const OperationDataLength = OperationDataVariables * 31 10 10 11 11 type BlockChallengeCircuit struct { 12 12 OperationData [OperationDataVariables]frontend.Variable 13 13 LastCommitHash frontend.Variable `gnark:",public"` // A unique challenge ID, the same for all validators 14 - SharedHash frontend.Variable `gnark:",public"` // Hash(LastCommitHash, OperationData) 15 14 16 15 // Validator-specific: 17 16 ValidatorAddress frontend.Variable `gnark:",public"` 18 - SpecificHash frontend.Variable `gnark:",public"` // Hash(ValidatorID, SharedHash) 17 + SpecificHash frontend.Variable `gnark:",public"` // Hash(ValidatorID, LastCommitHash, OperationData) 19 18 } 20 19 21 20 func (circuit *BlockChallengeCircuit) Define(api frontend.API) error { 22 21 mimc, _ := mimc.NewMiMC(api) 23 22 23 + mimc.Write(circuit.ValidatorAddress) 24 24 mimc.Write(circuit.LastCommitHash) 25 25 26 26 for i := 0; i < len(circuit.OperationData); i++ { 27 27 mimc.Write(circuit.OperationData[i]) 28 28 } 29 - 30 - computedSharedHash := mimc.Sum() 31 - api.AssertIsEqual(circuit.SharedHash, computedSharedHash) 32 - 33 - mimc.Reset() 34 - 35 - mimc.Write(circuit.ValidatorAddress) 36 - mimc.Write(computedSharedHash) 37 29 38 30 api.AssertIsEqual(circuit.SpecificHash, mimc.Sum()) 39 31
+11 -13
proof/block_challenge_test.go
··· 36 36 origLastCommitHash := lo.Must(hex.DecodeString("deadf00ddeadf00ddeadf00ddeadbeef")) 37 37 38 38 opDataSlice := slices.Repeat(lo.Must(hex.DecodeString("ffee")), 775) 39 - opData := [1550]byte{} 39 + opData := [OperationDataLength]byte{} 40 40 copy(opData[:], opDataSlice) 41 - assignmentShared, sharedHash := buildBlockChallengeCircuitAssignmentShared(origLastCommitHash, opData) 42 - assignment := buildBlockChallengeCircuitAssignmentFull(assignmentShared, sharedHash, origValidatorID) 41 + assignmentShared := buildBlockChallengeCircuitAssignmentShared(origLastCommitHash, opData) 42 + assignment := buildBlockChallengeCircuitAssignmentFull(assignmentShared, origValidatorID) 43 43 t.Log("Out of circuit took", time.Since(st)) 44 44 45 45 st = time.Now() ··· 61 61 t.Log("Verify took", time.Since(st)) 62 62 } 63 63 64 - func buildBlockChallengeCircuitAssignmentShared(lastCommitHash []byte, data [1550]byte) (BlockChallengeCircuit, []byte) { 64 + func buildBlockChallengeCircuitAssignmentShared(lastCommitHash []byte, data [OperationDataLength]byte) BlockChallengeCircuit { 65 65 var assignment BlockChallengeCircuit 66 66 67 - h := mimc.NewMiMC() 68 - 69 67 if len(lastCommitHash) > 31 { 70 68 lastCommitHash = lastCommitHash[len(lastCommitHash)-31:] 71 69 } 72 - h.Write(lastCommitHash) 73 70 assignment.LastCommitHash = lastCommitHash 74 71 75 72 for i := 0; i < len(assignment.OperationData); i++ { 76 73 d := data[31*i : 31*(i+1)] 77 74 assignment.OperationData[i] = d 78 - h.Write(d) 79 75 } 80 76 81 - sharedHash := h.Sum(nil) 82 - assignment.SharedHash = sharedHash 83 - return assignment, sharedHash 77 + return assignment 84 78 } 85 79 86 - func buildBlockChallengeCircuitAssignmentFull(shared BlockChallengeCircuit, sharedHash, validatorAddress []byte) *BlockChallengeCircuit { 80 + func buildBlockChallengeCircuitAssignmentFull(shared BlockChallengeCircuit, validatorAddress []byte) *BlockChallengeCircuit { 87 81 h := mimc.NewMiMC() 88 82 89 83 h.Write(validatorAddress) 90 - h.Write(sharedHash) 84 + h.Write(shared.LastCommitHash.([]byte)) 85 + 86 + for i := 0; i < len(shared.OperationData); i++ { 87 + h.Write(shared.OperationData[i].([]byte)) 88 + } 91 89 92 90 shared.ValidatorAddress = validatorAddress 93 91 shared.SpecificHash = h.Sum(nil)