Skip to content

Commit

Permalink
runtime-sdk/modules/evm: Add subcall precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jul 28, 2023
1 parent de10c45 commit 170ba4e
Show file tree
Hide file tree
Showing 30 changed files with 1,693 additions and 376 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions client-sdk/go/types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,8 @@ func NewAddressFromConsensus(addr staking.Address) Address {
func NewAddressFromConsensusPublicKey(pk signature.PublicKey) Address {
return NewAddress(NewSignatureAddressSpecEd25519(ed25519.PublicKey(pk)))
}

// NewAddressFromEth creates a new address from an Eth-compatible address.
func NewAddressFromEth(ethAddress []byte) Address {
return NewAddressRaw(AddressV0Secp256k1EthContext, ethAddress)
}
14 changes: 14 additions & 0 deletions client-sdk/go/types/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ func TestAddressRaw(t *testing.T) {
addr := NewAddressRaw(AddressV0Secp256k1EthContext, ethAddress)
require.EqualValues("oasis1qrk58a6j2qn065m6p06jgjyt032f7qucy5wqeqpt", addr.String())
}

func TestNewAddressFromEth(t *testing.T) {
// Dave from test keys.
ethAddr, err := hex.DecodeString("Dce075E1C39b1ae0b75D554558b6451A226ffe00")
require.NoError(t, err, "hex.DecodeString")
addr := NewAddressFromEth(ethAddr)
require.Equal(t, addr.String(), "oasis1qrk58a6j2qn065m6p06jgjyt032f7qucy5wqeqpt")

// Erin from test keys.
ethAddr, err = hex.DecodeString("709EEbd979328A2B3605A160915DEB26E186abF8")
require.NoError(t, err, "hex.DecodeString")
addr = NewAddressFromEth(ethAddr)
require.Equal(t, addr.String(), "oasis1qqcd0qyda6gtwdrfcqawv3s8cr2kupzw9v967au6")
}
9 changes: 9 additions & 0 deletions runtime-sdk/modules/contracts/src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ fn process_subcalls<Cfg: Config, C: TxContext>(
// preconfigured the amount of available gas.
<C::Runtime as Runtime>::Core::use_tx_gas(ctx, result.gas_used)?;

// Forward any emitted event tags.
ctx.emit_etags(result.state.events);

// Forward any emitted runtime messages.
for (msg, hook) in result.state.messages {
// This should never fail as child context has the right limits configured.
ctx.emit_message(msg, hook)?;

Check warning on line 157 in runtime-sdk/modules/contracts/src/results.rs

View check run for this annotation

Codecov / codecov/patch

runtime-sdk/modules/contracts/src/results.rs#L157

Added line #L157 was not covered by tests
}

// Process replies based on filtering criteria.
let result = result.call_result;
match (reply, result.is_success()) {
Expand Down
9 changes: 6 additions & 3 deletions runtime-sdk/modules/contracts/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,13 @@ fn test_hello_contract_call() {
"there should only be one denomination"
);

let (etags, messages) = tx_ctx.commit();
let tags = etags.into_tags();
let state = tx_ctx.commit();
let tags = state.events.into_tags();
// Make sure no runtime messages got emitted.
assert!(messages.is_empty(), "no runtime messages should be emitted");
assert!(
state.messages.is_empty(),
"no runtime messages should be emitted"
);
// Make sure a contract event was emitted and is properly formatted.
assert_eq!(tags.len(), 2, "two events should have been emitted");
assert_eq!(tags[0].key, b"accounts\x00\x00\x00\x01"); // accounts.Transfer (code = 1) event
Expand Down
1 change: 1 addition & 0 deletions runtime-sdk/modules/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ oasis-runtime-sdk = { path = "../..", features = ["test"] }
rand = "0.7.3"
serde = { version = "1.0.144", features = ["derive"] }
serde_json = { version = "1.0.87", features = ["raw_value"] }
ethabi = { version = "18.0.0", default-features = false, features = ["std", "full-serde"]}

[[bench]]
name = "criterion_benchmark"
Expand Down
Loading

0 comments on commit 170ba4e

Please sign in to comment.