Skip to content

Commit

Permalink
Merge branch 'main' into q9f/abi/packed
Browse files Browse the repository at this point in the history
  • Loading branch information
q9f committed Jul 2, 2024
2 parents 6b712bb + fd5b6b5 commit 1d4c456
Show file tree
Hide file tree
Showing 38 changed files with 814 additions and 186 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ jobs:
- ruby
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: "Initialize CodeQL"
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: "${{ matrix.language }}"
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3
- name: "Perform CodeQL Analysis"
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
ruby-version: '3.3'
bundler-cache: true
- name: "Run rufo code formatting checks"
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
ruby-version: '3.3'
bundler-cache: true
- name: Run Yard Doc
run: |
gem install yard
yard doc
- name: Deploy GH Pages
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.6.1
with:
branch: gh-pages
folder: doc/
12 changes: 8 additions & 4 deletions .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-12]
ruby: ['3.0', '3.1', '3.2']
os: [ubuntu-latest, macos-latest]
ruby: ['3.1', '3.2', '3.3']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand Down Expand Up @@ -49,5 +49,9 @@ jobs:
run: |
bundle exec rspec
env:
COVERAGE: true
INFURA_TOKEN: ${{ secrets.INFURA_TOKEN }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.5.12]
### Added
* Allow to call JSON RPC with custom block number [#268](https://github.com/q9f/eth.rb/pull/268)
* Support tuple params in EventLog [#276](https://github.com/q9f/eth.rb/pull/276)

### Changed
* Eth: update version [#280](https://github.com/q9f/eth.rb/pull/280)
* Eth/abi: fix negative integer coding [#279](https://github.com/q9f/eth.rb/pull/279)
* Support negative number from JSON RPC [#267](https://github.com/q9f/eth.rb/pull/267)
* Abi/event: confirm decoding tuples works [#278](https://github.com/q9f/eth.rb/pull/278)
* Allow to call JSON RPC with custom block number [#268](https://github.com/q9f/eth.rb/pull/268)
* Gem: run rufo [#277](https://github.com/q9f/eth.rb/pull/277)
* Fix event signature [#250](https://github.com/q9f/eth.rb/pull/250)
* Support tuple params in EventLog [#276](https://github.com/q9f/eth.rb/pull/276)
* Ci: update ruby version [#271](https://github.com/q9f/eth.rb/pull/271)
* Eth/api: remove coinbase as default account [#269](https://github.com/q9f/eth.rb/pull/269)
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.5.0 to 4.6.1 [#275](https://github.com/q9f/eth.rb/pull/275)
* Build(deps): bump github/codeql-action from 2 to 3 [#257](https://github.com/q9f/eth.rb/pull/257)
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.4.3 to 4.5.0 [#256](https://github.com/q9f/eth.rb/pull/256)
* Fix typo in contract_spec.rb [#253](https://github.com/q9f/eth.rb/pull/253)
* Eth/eip721: fix data type bug for bytes, fix #251 [#252](https://github.com/q9f/eth.rb/pull/252)
* Ci: unpatch geth [#248](https://github.com/q9f/eth.rb/pull/248)
* Build(deps): bump actions/checkout from 3 to 4 [#246](https://github.com/q9f/eth.rb/pull/246)

## [0.5.11]
### Added
* Eth/abi: allow encoding address types [#242](https://github.com/q9f/eth.rb/pull/242)
* Eth/solidity: enable --via-ir [#232](https://github.com/q9f/eth.rb/pull/232)
* Checking userinfo with the uri method [#233](https://github.com/q9f/eth.rb/pull/233)
* Eth/abi: add abicoder gem tests collection [#218](https://github.com/q9f/eth.rb/pull/218)
* Manual default_account [#215](https://github.com/q9f/eth.rb/pull/215)
* Add moonbeam networks in [#209](https://github.com/q9f/eth.rb/pull/209)

### Changed
* Spec: run rufo [#245](https://github.com/q9f/eth.rb/pull/245)
* Fix the decoding of unsigned transactions [#243](https://github.com/q9f/eth.rb/pull/243)
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.4.2 to 4.4.3 [#244](https://github.com/q9f/eth.rb/pull/244)
* Build(deps): bump JamesIves/github-pages-deploy-action from 4.4.1 to 4.4.2 [#240](https://github.com/q9f/eth.rb/pull/240)
* Eth/tx: update tx initcode cost for shanghai [#237](https://github.com/q9f/eth.rb/pull/237)
* Eth/client: remove default gas limit attribute [#235](https://github.com/q9f/eth.rb/pull/235)
* Docs: minor fixups [#229](https://github.com/q9f/eth.rb/pull/229)
* Eth/contract: ensure contract name is title case [#228](https://github.com/q9f/eth.rb/pull/228)
* Deps: require forwardable for contracts [#227](https://github.com/q9f/eth.rb/pull/227)
* Ens/resolver: remove pending for etc coin type [#219](https://github.com/q9f/eth.rb/pull/219)
* Deps: update secp256k1 to 6 [#214](https://github.com/q9f/eth.rb/pull/214)
* Eth/solidity: add docs for solc path override [#213](https://github.com/q9f/eth.rb/pull/213)
* Manually overwrite solc path [#212](https://github.com/q9f/eth.rb/pull/212)
* Abi.decoder handles arrays of string and bytes [#207](https://github.com/q9f/eth.rb/pull/207)
* Eth/util: fix compressed public key to address in [#206](https://github.com/q9f/eth.rb/pull/206)
* Eth/api: update execution apis to latest spec [#204](https://github.com/q9f/eth.rb/pull/204)
* Eth/abi: split abi class into encoder and decoder [#203](https://github.com/q9f/eth.rb/pull/203)
* Eth/client: deduplicate code [#202](https://github.com/q9f/eth.rb/pull/202)
* Eth/client: rewrite send to send_request [#201](https://github.com/q9f/eth.rb/pull/201)
* Docs: update changelog for 0.5.10 [#200](https://github.com/q9f/eth.rb/pull/200)
* Tested with Ruby 3.2 [#199](https://github.com/q9f/eth.rb/pull/199)

## [0.5.10]
### Added
* Eth/client: add transfer_erc20 function [#197](https://github.com/q9f/eth.rb/pull/197)
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Supported Versions

Ruby Ethereum 0.5.0 is a complete rewrite of the old `eth` 0.4.x gem.
Ruby Ethereum 0.5.x is a complete rewrite of the old `eth` 0.4.x gem.
It also contains modules from `abi`, `rlp` and the `ethereum` gem.

None of these gems are maintained anymore except for `eth` 0.5.0 and
Expand Down
7 changes: 5 additions & 2 deletions eth.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep %r{^(test|spec|features)/}

spec.platform = Gem::Platform::RUBY
spec.required_ruby_version = ">= 2.7", "< 4.0"
spec.required_ruby_version = ">= 3.0", "< 4.0"

# forwardable for contracts meta programming
spec.add_dependency "forwardable", "~> 1.3"

# keccak for hashing everything in ethereum
spec.add_dependency "keccak", "~> 1.3"
Expand All @@ -41,7 +44,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "konstructor", "~> 1.0"

# rbsecp256k1 for key-pairs and signatures
spec.add_dependency "rbsecp256k1", "~> 5.1"
spec.add_dependency "rbsecp256k1", "~> 6.0"

# openssl for encrypted key derivation
spec.add_dependency "openssl", ">= 2.2", "< 4.0"
Expand Down
20 changes: 19 additions & 1 deletion lib/eth/abi/decoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ def type(type, arg, packed = false)
type(Type.parse(type.base_type), arg[pointer + 32, Util.ceil32(data_l) + 32])
end
end
elsif type.base_type == "tuple"
offset = 0
data = {}
raise DecodingError, "Cannot decode tuples without known components" if type.components.nil?
type.components.each do |c|
if c.dynamic?
pointer = Util.deserialize_big_endian_to_int arg[offset, 32] # Pointer to the size of the array's element
data_len = Util.deserialize_big_endian_to_int arg[pointer, 32] # length of the element

data[c.name] = type(c, arg[pointer, Util.ceil32(data_len) + 32])
offset += 32
else
size = c.size
data[c.name] = type(c, arg[offset, size])
offset += size
end
end
data
elsif type.dynamic?
l = Util.deserialize_big_endian_to_int arg[0, 32]
nested_sub = type.nested_sub
Expand Down Expand Up @@ -108,7 +126,7 @@ def primitive_type(type, data, packed = false)
Util.deserialize_big_endian_to_int data
when "int"
u = Util.deserialize_big_endian_to_int data
i = u >= 2 ** (type.sub_type.to_i - 1) ? (u - 2 ** type.sub_type.to_i) : u
i = u >= 2 ** (type.sub_type.to_i - 1) ? (u - 2 ** 256) : u

# decoded integer
i
Expand Down
17 changes: 6 additions & 11 deletions lib/eth/abi/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ module Encoder
# @return [String] the encoded type.
# @raise [EncodingError] if value does not match type.
def type(type, arg, packed = false)


if %w(string bytes).include? type.base_type and type.sub_type.empty? and type.dimensions.empty?
raise EncodingError, "Argument must be a String" unless arg.instance_of? String

Expand Down Expand Up @@ -75,7 +73,6 @@ def type(type, arg, packed = false)
arg.size.times do |i|
head += type(nested_sub, arg[i], packed)
end

"#{head}#{tail}"
else
if type.dimensions.empty?
Expand Down Expand Up @@ -150,9 +147,9 @@ def int(arg, type, packed)
raise ValueOutOfBounds, arg unless i >= -2 ** (real_size - 1) and i < 2 ** (real_size - 1)
if packed
len = real_size / 8
return Util.zpad_int(i % 2 ** type.sub_type.to_i, len)
return Util.zpad_int(i % 2 ** 256, len)
else
return Util.zpad_int(i % 2 ** type.sub_type.to_i)
return Util.zpad_int(i % 2 ** 256)
end
end

Expand Down Expand Up @@ -187,15 +184,13 @@ def bytes(arg, type, packed)
if type.sub_type.empty?
size = Util.zpad_int arg.size
padding = Constant::BYTE_ZERO * (Util.ceil32(arg.size) - arg.size)

pp size, arg, padding if packed

# variable length string/bytes
"#{size}#{arg}#{padding}"
else
raise ValueOutOfBounds, arg unless arg.size <= type.sub_type.to_i
padding = Constant::BYTE_ZERO * (32 - arg.size)

pp arg, padding if packed

# fixed length string/bytes
Expand Down Expand Up @@ -278,8 +273,8 @@ def hash(arg, type)
def address(arg)
if arg.is_a? Address

# address from eth::address
Util.zpad_hex arg.to_s
# from checksummed address with 0x prefix
Util.zpad_hex arg.to_s[2..-1]
elsif arg.is_a? Integer

# address from integer
Expand All @@ -290,11 +285,11 @@ def address(arg)
Util.zpad arg, 32
elsif arg.size == 40

# address from hexadecimal address with 0x prefix
# address from hexadecimal address
Util.zpad_hex arg
elsif arg.size == 42 and arg[0, 2] == "0x"

# address from hexadecimal address
# address from hexadecimal address with 0x prefix
Util.zpad_hex arg[2..-1]
else
raise EncodingError, "Could not parse address: #{arg}"
Expand Down
29 changes: 25 additions & 4 deletions lib/eth/abi/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,20 @@ def compute_topic(interface)
def signature(interface)
name = interface.fetch("name")
inputs = interface.fetch("inputs", [])
types = inputs.map { |i| i.fetch("type") }
types = inputs.map { |i| type(i) }
"#{name}(#{types.join(",")})"
end

def type(input)
if input["type"] == "tuple"
"(#{input["components"].map { |c| type(c) }.join(",")})"
elsif input["type"] == "enum"
"uint8"
else
input["type"]
end
end

# A decoded event log.
class LogDescription
# The event ABI interface used to decode the log.
Expand Down Expand Up @@ -116,9 +126,20 @@ def decode_logs(interfaces, logs)
def decode_log(inputs, data, topics, anonymous = false)
topic_inputs, data_inputs = inputs.partition { |i| i["indexed"] }

topic_types = topic_inputs.map { |i| i["type"] }
data_types = data_inputs.map { |i| i["type"] }

topic_types = topic_inputs.map do |i|
if i["type"] == "tuple"
Type.parse(i["type"], i["components"], i["name"])
else
i["type"]
end
end
data_types = data_inputs.map do |i|
if i["type"] == "tuple"
Type.parse(i["type"], i["components"], i["name"])
else
i["type"]
end
end
# If event is anonymous, all topics are arguments. Otherwise, the first
# topic will be the event signature.
if anonymous == false
Expand Down
10 changes: 9 additions & 1 deletion lib/eth/abi/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ def initialize(base_type, sub_type, dimensions, components = nil, component_name
# @return [Eth::Abi::Type] a parsed Type object.
# @raise [ParseError] if it fails to parse the type.
def parse(type, components = nil, component_name = nil)
return type if type.is_a?(Type)
if type.is_a?(Type)
@base_type = type.base_type
@sub_type = type.sub_type
@dimensions = type.dimensions
@components = type.components
@name = type.name
return
end

_, base_type, sub_type, dimension = /([a-z]*)([0-9]*x?[0-9]*)((\[[0-9]*\])*)/.match(type).to_a

# type dimension can only be numeric
Expand Down
1 change: 0 additions & 1 deletion lib/eth/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ module Api
"eth_blockNumber",
"eth_call",
"eth_chainId",
"eth_coinbase",
"eth_compileLLL",
"eth_compileSerpent",
"eth_compileSolidity",
Expand Down
Loading

0 comments on commit 1d4c456

Please sign in to comment.