Commit Graph

118 Commits

Author SHA1 Message Date
03263c850a Force program address off the curve (#11323) 2020-08-05 16:35:54 -07:00
2dbed80e48 Disable cross-program invocations for OperatingMode::Stable (#11272) 2020-07-29 15:29:52 -07:00
05445c718e Fix hygiene issues in declare_program! and declare_loader!
The `declare_program!` and `declare_loader!` macros both expand to
new macro definitions (based on the `$name` argument). These 'inner'
macros make use of the special `$crate` metavariable to access items in
the crate where the 'inner' macros is defined.

However, this only works due to a bug in rustc. When a macro is
expanded, all `$crate` tokens in its output are 'marked' as being
resolved in the defining crate of that macro. An inner macro (including
the body of its arms) is 'just' another set of tokens that appears in
the body of the outer macro, so any `$crate` identifiers used there are
resolved relative to the 'outer' macro.

For example, consider the following code:

```rust
macro_rules! outer {
    () => {
        macro_rules! inner {
            () => {
                $crate::Foo
            }
        }
    }
}
```

The path `$crate::Foo` will be resolved relative to the crate that defines `outer`,
**not** the crate which defines `inner`.

However, rustc currently loses this extra resolution information
(referred to as 'hygiene' information) when a crate is serialized.
In the above example, this means that the macro `inner` (which gets
defined in whatever crate invokes `outer!`) will behave differently
depending on which crate it is invoked from:

When `inner` is invoked from the same crate in which it is defined,
the hygiene information will still be available,
which will cause `$crate::Foo` to be resolved in the crate which defines 'outer'.

When `inner` is invoked from a different crate, it will be loaded from
the metadata of the crate which defines 'inner'. Since the hygiene
information is currently lost, rust will 'forget' that `$crate::Foo` is
supposed to be resolved in the context of 'outer'. Instead, it will be
resolved relative to the crate which defines 'inner', which can cause
incorrect code to compile.

This bug will soon be fixed in rust (see https://github.com/rust-lang/rust/pull/72121),
which will break `declare_program!` and `declare_loader!`. Fortunately,
it's possible to obtain the desired behavior (`$crate` resolving in the
context of the 'inner' macro) by use of a procedural macro.

This commit adds a `respan!` proc-macro to the `sdk/macro` crate.
Using the newly-stabilized (on Nightly) `Span::resolved_at` method,
the `$crate` identifier can be made to be resolved in the context of the
proper crate.

Since `Span::resolved_at` is only stable on the latest nightly,
referencing it on an earlier version of Rust will cause a compilation error.
This requires the `rustversion` crate to be used, which allows conditionally
compiling code epending on the Rust compiler version in use. Since this method is already
stabilized in the latest nightly, there will never be a situation where
the hygiene bug is fixed (e.g. https://github.com/rust-lang/rust/pull/72121)
is merged but we are unable to call `Span::resolved_at`.
2020-07-14 14:40:02 -07:00
57576b07ef Fix warnings (#10992)
* Fix warnings

* disable warning
2020-07-10 20:02:55 +00:00
1c498369b5 Remove fee-payer guesswork from Message and Transaction (#10776)
* Make Message::new_with_payer the default constructor

* Remove Transaction::new_[un]signed_instructions

These guess the fee-payer instead of stating it explicitly
2020-06-24 14:52:38 -06:00
73586c1aad Use &[u8] for program address seeds rather then &str (#10744) 2020-06-22 16:51:43 -07:00
dac7dc2f10 Move types to more appropriate files (#10638) 2020-06-17 10:39:14 -07:00
b6a9573748 Route all loader messages to log collector (#10528) 2020-06-13 13:20:08 -07:00
7e2651ca51 RPC simulateTransaction endpoint now returns program log output (#10432) 2020-06-06 10:18:28 -07:00
a4cd96609c Add built-in programs to InvokeContext (#10383)
automerge
2020-06-03 12:48:19 -07:00
03abd3ddd7 Prevent privilege escalation (#10232)
automerge
2020-05-26 01:02:31 -07:00
4a72c2b054 Support cross-program invocation to native programs (#10136) 2020-05-20 09:24:57 -07:00
5e89bd8868 Panic if no fee-payer found via Message::new() (#10050)
automerge
2020-05-15 12:23:09 -07:00
58ef02f02b 9951 clippy errors in the test suite (#10030)
automerge
2020-05-15 09:35:43 -07:00
5cc252d471 Remove hash field from account (#9915) 2020-05-12 23:39:46 +08:00
af84dff9ef nudge 2020-05-11 09:06:05 -07:00
97e17f9b32 Programs can only sign their accounts 2020-05-11 09:06:05 -07:00
84885d79d5 Pull in hardened BPF virtual machine (#9931) 2020-05-08 12:37:04 -07:00
7678af6300 Cleanup BPF helper symbols (#9804) 2020-04-30 11:29:11 -07:00
de9d8cd849 Rename BPF helper to syscall (#9819)
automerge
2020-04-30 01:43:11 -07:00
068f12fd6f Add Cross-program invocations (#9582) 2020-04-28 14:33:56 -07:00
d3e3f51330 Ignore log tests due to concurrency conflicts (#9719) 2020-04-25 22:38:59 -07:00
17e7667da4 Serialize test (#9655) 2020-04-22 14:53:06 -07:00
89b30b4853 Ignore test_helper_sol_log due to solana_logger concurency issue (#9654) 2020-04-22 10:03:41 -07:00
58887c591b Add and update tests (#9566) 2020-04-18 17:04:13 -07:00
241a05fc52 Add native loader entry points (#9486) 2020-04-15 09:41:29 -07:00
ad0482be73 Revert "Add native loader entry points (#9275)" Breaks genesis_config abi (#9377)
This reverts commit ed86d8d1fc.
2020-04-08 14:36:18 -07:00
ed86d8d1fc Add native loader entry points (#9275) 2020-04-03 17:40:59 -07:00
1e6b789bfa Improve BPF Loader reporting (#9202)
automerge
2020-03-31 18:18:44 -07:00
130c0b484d Enforce an executable's rent exemption in the runtime (#9134) 2020-03-31 10:07:38 -07:00
dae28b9cfe Bump rBPF to v0.1.24, update rBPF/BPF Loader error handling (#9089) 2020-03-26 14:00:26 -07:00
de6ef68571 Add BPF virtual address translate helpers (#8919) 2020-03-18 08:39:55 -07:00
61514e3b0e Allow program accounts to be passed as program and parameter (#8907) 2020-03-17 12:06:15 -07:00
8df4d8b905 Update to rbpf v0.1.23 - Use trait objects to convey helper context (#8648) 2020-03-05 14:14:21 -08:00
5e3ce30d02 Pass the correct program_id to programs (#8630) 2020-03-05 10:57:35 -08:00
25df95be6f Expose executable and rent_epoch in AccountInfo (#8619) 2020-03-04 10:52:09 -08:00
4593d333c7 Remove BPF Loader's use of GenericError (#8284) 2020-02-14 13:59:03 -08:00
517fe73734 Non-conflicting account duplicate marker value (#8206) 2020-02-11 10:03:28 -08:00
df782b93ae Add is_writable to AccountInfo (#8196) 2020-02-10 21:33:29 -08:00
8436457e75 Rename program_utils.rs (#8127) 2020-02-05 12:48:30 -08:00
0fd795a676 Remove program error footgun and cleaner developer experience (#8042) 2020-01-31 10:58:07 -08:00
dd276138c2 Add support for idiomatic error handling to BPF instruction processors (#7968) 2020-01-30 09:47:22 -08:00
669502ede7 Don't depend on user modifiable data to parse paramter buffer (#8022) 2020-01-29 21:49:42 -08:00
34ed93d57c Optimize account copies and use RefCell to handle duplicate accounts in BPF programs (#7958) 2020-01-24 10:54:26 -08:00
c95e5346a4 Boot the mut (#7926) 2020-01-22 17:54:06 -08:00
023074650f Allow the same account to be passed multiple times to a single instruction (#7795) 2020-01-22 09:11:56 -08:00
bb950ec93e Naming nits (#7896)
automerge
2020-01-21 10:38:46 -08:00
08ba27627d Direct entrypoint for execution (#7746) 2020-01-10 13:20:15 -08:00
2d08dddfc8 nit, cleanup uses (#7747)
automerge
2020-01-09 23:58:13 -08:00
07855e3125 Allow override of RUST_LOG (#7705) 2020-01-08 09:19:12 -08:00