Skip to content

Commit

Permalink
refactor: remove all batch and compress logic (#392)
Browse files Browse the repository at this point in the history
* refactor: remove  and

* chore: CHANGELOG

* lint

* chore: changelog

* refactor: remove CombineProofs

* refactor: VerifyMembership and VerifyNonMembership api

* refactor: remove batch and compress logic

* refactor: remove unused test data

* refactor: reset api

* Update go/ics23.go

* refactor: remove unnecessary code

* lint

* chore: changelog
  • Loading branch information
colin-axner authored Oct 23, 2024
1 parent 90b4eef commit 642bc3e
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 763 deletions.
1 change: 1 addition & 0 deletions go/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- fix: guarantee that `spec.InnerSpec.MaxPrefixLength` < `spec.InnerSpec.MinPrefixLength` + `spec.InnerSpec.ChildSize` ([#369](https://github.com/cosmos/ics23/pull/369))
- refactor: support for `BatchProof` and `CompressedBatchProof` is being dropped.
* The API's `BatchVerifyMembership`, `BatchVerifyNonMembership`, and `CombineProofs` have been removed. ([#390](https://github.com/cosmos/ics23/pull/390))
* The API's `IsCompressed`, `Compress`, and `Decompress` have been removed. ([#392](https://github.com/cosmos/ics23/pull/392))

# v0.11.0

Expand Down
159 changes: 0 additions & 159 deletions go/compress.go

This file was deleted.

14 changes: 0 additions & 14 deletions go/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,9 @@ func (p *CommitmentProof) Calculate() (CommitmentRoot, error) {
return v.Exist.Calculate()
case *CommitmentProof_Nonexist:
return v.Nonexist.Calculate()
case *CommitmentProof_Batch:
if len(v.Batch.GetEntries()) == 0 || v.Batch.GetEntries()[0] == nil {
return nil, errors.New("batch proof has empty entry")
}
if e := v.Batch.GetEntries()[0].GetExist(); e != nil {
return e.Calculate()
}
if n := v.Batch.GetEntries()[0].GetNonexist(); n != nil {
return n.Calculate()
}
case *CommitmentProof_Compressed:
proof := Decompress(p)
return proof.Calculate()
default:
return nil, errors.New("unrecognized proof type")
}
return nil, errors.New("unrecognized proof type")
}

// Verify does all checks to ensure this proof proves this key, value -> root
Expand Down
38 changes: 0 additions & 38 deletions go/vectors_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,6 @@ type BatchVectorData struct {
Invalid bool // default is valid
}

func DecompressBatchVectorsTestData(t *testing.T) map[string]*CommitmentProof {
t.Helper()
iavl := filepath.Join("..", "testdata", "iavl")
tendermint := filepath.Join("..", "testdata", "tendermint")
smt := filepath.Join("..", "testdata", "smt")
// note that these batches are already compressed
batchIAVL := loadBatch(t, iavl, "batch_exist.json")
batchTM := loadBatch(t, tendermint, "batch_nonexist.json")
batchSMT := loadBatch(t, smt, "batch_nonexist.json")
return map[string]*CommitmentProof{
"iavl": batchIAVL,
"tendermint": batchTM,
"smt": batchSMT,
}
}

func LoadFile(tb testing.TB, dir string, filename string) (*CommitmentProof, *RefData) {
tb.Helper()
// load the file into a json struct
Expand Down Expand Up @@ -128,25 +112,3 @@ func mustHex(tb testing.TB, data string) []byte {
}
return res
}

func loadBatch(t *testing.T, dir string, filename string) *CommitmentProof {
t.Helper()
// load the file into a json struct
name := filepath.Join(dir, filename)
bz, err := os.ReadFile(name)
if err != nil {
t.Fatalf("Read file: %+v", err)
}
var data BatchVector
err = json.Unmarshal(bz, &data)
if err != nil {
t.Fatalf("Unmarshal json: %+v", err)
}
// parse the protobuf object
var proof CommitmentProof
err = proof.Unmarshal(mustHex(t, data.Proof))
if err != nil {
t.Fatalf("Unmarshal protobuf: %+v", err)
}
return &proof
}
36 changes: 0 additions & 36 deletions go/vectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,3 @@ func TestVectors(t *testing.T) {
})
}
}

func TestDecompressBatchVectors(t *testing.T) {
cases := DecompressBatchVectorsTestData(t)
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
small, err := tc.Marshal()
if err != nil {
t.Fatalf("Marshal batch %v", err)
}

decomp := Decompress(tc)
if decomp == tc {
t.Fatalf("Decompression is a no-op")
}
big, err := decomp.Marshal()
if err != nil {
t.Fatalf("Marshal batch %v", err)
}
if len(small) >= len(big) {
t.Fatalf("Compression doesn't reduce size")
}

restore := Compress(tc)
resmall, err := restore.Marshal()
if err != nil {
t.Fatalf("Marshal batch %v", err)
}
if len(resmall) != len(small) {
t.Fatalf("Decompressed len %d, original len %d", len(resmall), len(small))
}
if !bytes.Equal(resmall, small) {
t.Fatal("Decompressed batch proof differs from original")
}
})
}
}
86 changes: 0 additions & 86 deletions testdata/iavl/batch_exist.json

This file was deleted.

86 changes: 0 additions & 86 deletions testdata/iavl/batch_nonexist.json

This file was deleted.

86 changes: 0 additions & 86 deletions testdata/smt/batch_exist.json

This file was deleted.

86 changes: 0 additions & 86 deletions testdata/smt/batch_nonexist.json

This file was deleted.

86 changes: 0 additions & 86 deletions testdata/tendermint/batch_exist.json

This file was deleted.

86 changes: 0 additions & 86 deletions testdata/tendermint/batch_nonexist.json

This file was deleted.

0 comments on commit 642bc3e

Please sign in to comment.