Daohub-io / cap9

Capability-based security protocol for smart contracts
Apache License 2.0
22 stars 10 forks source link

Implement additional Ethereum operations in pwasm #153

Closed JakeOShannessy closed 5 years ago

JakeOShannessy commented 5 years ago

Cap9 relies on several properties of a system in order to be implementable, one of those is the system needs to be able to reflect or introspect itself. In real terms it needs to be able to read the code that will be executed. On Ethereum we use EXTCODECOPY which reads the code of another contract. This is specified in eWASM (see the eWASM spec) but it is not implemented in pwasm (nor is there a spec to suggest that it should be.

These Ethereum primitives are provided via wasm imports from an env modules. For example, to be able to use SSTORE a wasm contract (in pwasm) can import storage_write via:

(import "env" "storage_write" (func $env.storage_write (type $t0)))

In order for the validation code to work we would need to implement EXTCODECOPY ourselves, so that we can do something like:

(import "env" "extcodecopy" (func $env.extcodecopy (type $t1)))

I have already implemented EXTCODESIZE, which shows it is possible, although EXTCODECOPY is likely much more complex.

JakeOShannessy commented 5 years ago

This is now addressed in master of https://github.com/Daohub-io/parity-ethereum, and relied upon in #151. Both EXTCODESIZE and EXTCODECOPY are implemented.