Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

EIP-213 (bn128 curve operations) #4999

Merged
merged 11 commits into from
Mar 31, 2017
Merged

EIP-213 (bn128 curve operations) #4999

merged 11 commits into from
Mar 31, 2017

Conversation

NikVolf
Copy link
Contributor

@NikVolf NikVolf commented Mar 22, 2017

  • utilizes modified version of bn lib
  • there maybe some minor alteration and correctness tests added later once EIP gets more specified
  • also introduces fail-ability for built-ins (since this operations are first ones of the kind)

@NikVolf NikVolf added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Mar 22, 2017
@arkpar arkpar mentioned this pull request Mar 22, 2017
12 tasks
pub fn execute(&self, input: &[u8], output: &mut BytesRef) { self.native.execute(input, output) }
pub fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> {
self.native.execute(input, output)?;
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body can be unchanged: self.native.execute()

}

impl Impl for Bn128AddImpl {
fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that these are fallible, it makes sense to document the failure conditions.

@@ -45,6 +45,7 @@ ethcore-bloom-journal = { path = "../util/bloom" }
hardware-wallet = { path = "../hw" }
stats = { path = "../util/stats" }
num = "0.1"
bn = { git = "https:/paritytech/bn" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any plans to upstream these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep after i'm done with pairing

@arkpar
Copy link
Collaborator

arkpar commented Mar 24, 2017

We should not really use "alt_" prefix anywhere. As far as I can tell this is only used in libsnark to distinguish two implementations of the same curve apart.

@NikVolf
Copy link
Contributor Author

NikVolf commented Mar 24, 2017

@arkpar done

@NikVolf NikVolf changed the title EIP-213 (bn_128 curve operations) EIP-213 (bn128 curve operations) Mar 24, 2017
@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Mar 24, 2017
@@ -70,6 +73,12 @@ impl From<Box<trie::TrieError>> for Error {
}
}

impl From<builtin::Error> for Error {
fn from(err: builtin::Error) -> Self {
Error::BuiltIn(err.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have builtins return a String as error rather than go through the trouble of making a builtin::Error type which is just destructured here? Not sure it's worth allocating the string at all, actually, since

  • it's easy to make builtins fail
  • builtins are on a hot path
  • errors are silently swallowed anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense

@gavofyork gavofyork added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Mar 25, 2017
@gavofyork
Copy link
Contributor

@NikVolf worth addressing @rphmeier 's suggestion now? or another PR?

@NikVolf NikVolf added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Mar 25, 2017
Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A grumble regarding state snapshot not being discarded/reverter.

@@ -276,7 +276,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {

let cost = builtin.cost(data);
if cost <= params.gas {
builtin.execute(data, &mut output);
builtin.execute(data, &mut output)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can fail without discarding or reverting_to_checkpoint.

Currently we don't have any state-altering builtins, but might be good to have that in mind. Also I'm not entirely sure if one leaking state snapshot would ever be a problem, but IMHO would be good to address that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i follow
why shouldn't it fail the same way as not enough gas fails, but with different reason?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think every other exit from this function is either doing: state.discard_snapshot(), state.revert_to_snapshot() or enact_result (which does this stuff internally afair).

This could exit the function after creating state.checkpoint() but without reseting it. Also seems that tracing for top-level failed builtin call might be missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I misjudged the program flow here
the errors and rollback/discard logic should be decoupled from each other though

if let Err(e) = builtin.execute(data, &mut output) {
self.state.revert_to_checkpoint();
let evm_err: evm::evm::Error = e.into();
tracer.trace_failed_call(trace_info, vec![], evm_err.clone().into());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last tiny grumble: We're tracing only calls on `self.depth == 0 to avoid DoS attacks for tracing nodes, probably worth doing the same check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But out-of-gas is tracing error on any self.depth below?
Which seems right, because you never know what caused contract to fail otherwise

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, probably the problematic part is trace_output anyway.

@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Mar 30, 2017
@rphmeier rphmeier merged commit d146ae7 into master Mar 31, 2017
@rphmeier rphmeier deleted the eip-213 branch March 31, 2017 12:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants