-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Go] [Rust] update language bindings to return value API #417
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, lgtm, some nits
constantine-rust/constantine-ethereum-evm-precompiles/tests/t_ethereum_evm_precompiles.rs
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
fn t_generate<T: CompareReturn, F>(test_name: String, func: F) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn t_generate<T: CompareReturn, F>(test_name: String, func: F) | |
fn t_generate<T: impl Iterator<Item = u8>, F>(test_name: String, func: F) |
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While your proposal is not quite correct (impl Iterator
is not valid syntax must be without the impl
), it led me down the right path. Iterator
would require the test functions to actually return an iterator. But there's also a predefined IntoIterator
trait, which works (via x.into_iter().collect::<Vec<u8>>()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, the impl Iterator is for arguments, not generics. And yes Vec use into_iter
indeed.
@@ -60,6 +60,31 @@ func eth_evm_sha256*(r: var openArray[byte], inputs: openArray[byte]): CttEVMSta | |||
sha256.hash(cast[ptr array[32, byte]](r[0].addr)[], inputs) | |||
return cttEVM_Success | |||
|
|||
func modexp_result_size*(size: var uint64, inputs: openArray[byte]): CttEVMStatus {.noInline, tags:[Alloca, Vartime], libPrefix: prefix_ffi, meter.} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func modexp_result_size*(size: var uint64, inputs: openArray[byte]): CttEVMStatus {.noInline, tags:[Alloca, Vartime], libPrefix: prefix_ffi, meter.} = | |
func eth_evm_modexp_result_size*(size: var uint64, inputs: openArray[byte]): CttEVMStatus {.noInline, tags:[Alloca, Vartime], libPrefix: prefix_ffi, meter.} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure whether to reuse the naming convention. I didn't so that there is a clearer distinction between what is a real EVM precompiles and what is a helper function. Will change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's namespacing in case several protocols have differing modexp, say a modexp for the EVM, a modexp to simulate GMP, etc ...
* The associated modulus length in bytes is the size required by the | ||
* result to `eth_evm_modexp`. | ||
*/ | ||
ctt_evm_status ctt_modexp_result_size( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctt_evm_status ctt_modexp_result_size( | |
ctt_evm_status ctt_eth_evm_modexp_result_size( |
NOTE: currently not all tests pass, due to the unmarshaling bug. We will rebase once a final decision for the solution has been made.
Adds a couple of overlooked API functions, - validation (sec, pub, sig) - serialization of seckeys - deserialize unchecked
Both Go and Rust should now pass the tests. We'll see. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks a lot
Previously the API for Go and Rust simply followed the C API (and by extension the Nim API from which the C API is generated) almost literally. That meant return types were reserved for error codes (or enums) and all 'interesting' data was passed via mutable arguments.
This changes the API to return values instead. This has the nice advantage on the Rust side that it sidesteps the
MaybeUninit
issue mentioned in #387.Note: currently the CI does not pass, because of the bug fixed in #409. There might be other minor issues present, but due to "expected" test failures, I haven't dug into every current failure for Go/Rust.