Skip to content

Commit

Permalink
Increase strictness of base types (ethereum#305)
Browse files Browse the repository at this point in the history
* increase strictness of base types

* rename speccheck steps

* add bytesMax32 type

* add test for invalid storage key

* add test for storage key too large
  • Loading branch information
lightclient authored Jan 3, 2023
1 parent 7474e63 commit 9500d37
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
go-version: ^1.18
id: go
- name: Install staticcheck
- name: Install speccheck
run: go install github.com/lightclient/rpctestgen/cmd/speccheck@latest
- name: Install staticcheck
- name: Run speccheck
run: speccheck -v
2 changes: 1 addition & 1 deletion src/eth/state.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
title: Storage keys
type: array
items:
$ref: '#/components/schemas/hash32'
$ref: '#/components/schemas/bytesMax32'
- name: Block
required: true
schema:
Expand Down
18 changes: 11 additions & 7 deletions src/schemas/base-types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,39 @@ bytes:
title: hex encoded bytes
type: string
pattern: ^0x[0-9a-f]*$
bytesMax32:
title: 32 hex encoded bytes
type: string
pattern: ^0x[0-9a-f]{0,64}$
bytes8:
title: 8 hex encoded bytes
type: string
pattern: ^0x[0-9a-f]{16}$
bytes32:
title: 32 hex encoded bytes
type: string
pattern: ^0x([0-9a-f][0-9a-f]){0,32}$
pattern: ^0x[0-9a-f]{64}$
bytes256:
title: 256 hex encoded bytes
type: string
pattern: ^0x[0-9a-f]{512}$
bytes65:
title: 65 hex encoded bytes
type: string
pattern: ^0x[0-9a-f]{512}$
pattern: ^0x[0-9a-f]{65}$
uint:
title: hex encoded unsigned integer
type: string
pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
uint64:
title: hex encoded unsigned integer
title: hex encoded 64 bit unsigned integer
type: string
pattern: ^0x([1-9a-f][0-9a-f]{0,15})|0$
pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
uint256:
title: hex encoded unsigned integer
title: hex encoded 256 bit unsigned integer
type: string
pattern: ^0x[0-9a-f]{0,64}$
pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
hash32:
title: 32 byte hex value
type: string
pattern: ^0x([0-9a-f][0-9a-f]){0,32}$
pattern: ^0x[0-9a-f]{64}$
2 changes: 1 addition & 1 deletion src/schemas/receipt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ReceiptInfo:
root:
title: state root
description: The post-transaction state root. Only specified for transactions included before the Byzantium upgrade.
$ref: '#/components/schemas/bytes32'
$ref: '#/components/schemas/hash32'
status:
title: status
description: Either 1 (success) or 0 (failure). Only specified for transactions included after the Byzantium upgrade.
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/state.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ StorageProof:
properties:
key:
title: key
$ref: '#/components/schemas/hash32'
$ref: '#/components/schemas/bytesMax32'
value:
title: value
$ref: '#/components/schemas/uint256'
Expand Down
2 changes: 2 additions & 0 deletions tests/eth_getStorage/get-storage-invalid-key-too-large.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>> {"jsonrpc":"2.0","id":12,"method":"eth_getStorageAt","params":["0xaa00000000000000000000000000000000000000","0x00000000000000000000000000000000000000000000000000000000000000000","latest"]}
<< {"jsonrpc":"2.0","id":12,"error":{"code":-32000,"message":"hex string of odd length"}}
2 changes: 2 additions & 0 deletions tests/eth_getStorage/get-storage-invalid-key.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>> {"jsonrpc":"2.0","id":11,"method":"eth_getStorageAt","params":["0xaa00000000000000000000000000000000000000","0xasdf","latest"]}
<< {"jsonrpc":"2.0","id":11,"error":{"code":-32000,"message":"invalid hex string"}}

0 comments on commit 9500d37

Please sign in to comment.