Skip to content

Commit

Permalink
[Go] [Rust] update language bindings to return value API (#417)
Browse files Browse the repository at this point in the history
* refactor(Rust): start refactoring to idiomatic Rust API)

* refactor(Go): start refactoring to idiomatic Go API

* refactor(C): ptrdiff_t -> size_t

* [Go] make Go API more statically typed, out param -> return value API

* add helper function returning required size for EVM modexp, C API

* [Go] update all BLS sig tests for new API

* [Go] fix copy paste typo in EVM FP2 to G2

* [Go] update Go EVM precompiles test for new API

NOTE: currently not all tests pass, due to the unmarshaling bug. We
will rebase once a final decision for the solution has been made.

* [rust] change Rust BLS signature API to return values, add missing

Adds a couple of overlooked API functions,
- validation (sec, pub, sig)
- serialization of seckeys
- deserialize unchecked

* [rust] update tests for BLS signatures with new API

* [Go] add overlooked valid return value for unchecked deserialization

* [rust] update EVM precompiles API to return values

* [rust] regenerate Rust bindings w/ modexp result alloc helper

* [rust] fix up tests for EVM precompiles

* [rust] add missing inline, add must_use, fix sha256 API isize -> usize

* [go] explicitly return `nil` in EvmSha256 for non error case

* [go] remove TODO comment

* [rust] fix naming of EVM precompiles test cases

* [rust] simplify EVM precompiles tests using IntoIterator trait

* add `eth_evm` prefix to EVM modexp result size helper

* [rust] update BLS sig API for ptrdiff_t -> csize_t change

* [rust] remove some warnings from BLS sig rust test

* [rust] fix wrong size for FP2 to G2

* [rust] remove unused imports in EVM precompiles (and test)

* [rust] fix name of EVM precompiles test fn

* [rust] minor clean up, also assert expected error given if fail

---------

Co-authored-by: Mamy Ratsimbazafy <mamy_github@numforge.co>
  • Loading branch information
Vindaar and mratsim authored Jul 5, 2024
1 parent ad325cf commit 0fe6bbc
Show file tree
Hide file tree
Showing 21 changed files with 1,271 additions and 1,002 deletions.
17 changes: 17 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ subroutines.
- https://github.com/rust-lang/rust/pull/76986
- https://github.com/rust-lang/rfcs/pull/2884

### Error codes, and Result

In low-level C, everything is return through status codes.

In Rust, status is communicated through `Result<Output, Error>`
In particular for verification, Errors are used if the protocol is not followed:
- wrong input length
- point not on curve
- point not in subgroup
- zero point

However if all those exceptional rules are followed, but verification still fails,
the failure is communicated through a boolean.

Similarly in Go, errors are used to communicate breaking protocol rules
and the result of verification is communicated through a bool.

## Code organization

TBD
8 changes: 4 additions & 4 deletions bindings/c_typedefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ proc toCparam*(name: string, typ: NimNode): string =
typ.treeRepr()
let sTyp = $typ[2]
if sTyp in TypeMap:
"const " & TypeMap[sTyp] & " " & name & "[], ptrdiff_t " & name & "_len"
"const " & TypeMap[sTyp] & " " & name & "[], size_t " & name & "_len"
else:
"const " & sTyp & " " & name & "[], ptrdiff_t " & name & "_len"
"const " & sTyp & " " & name & "[], size_t " & name & "_len"
elif typ.kind == nnkVarTy and typ[0].kind == nnkCall:
typ[0][0].expectKind(nnkOpenSymChoice)
doAssert typ[0][0][0].eqIdent"[]"
doAssert typ[0][1].eqIdent"openArray"
let sTyp = $typ[0][2]
if sTyp in TypeMap:
TypeMap[sTyp] & " " & name & "[], ptrdiff_t " & name & "_len"
TypeMap[sTyp] & " " & name & "[], size_t " & name & "_len"
else:
sTyp & " " & name & "[], ptrdiff_t " & name & "_len"
sTyp & " " & name & "[], size_t " & name & "_len"
elif typ.kind == nnkPtrTy and typ[0].kind == nnkCall:
typ[0][0].expectKind(nnkOpenSymChoice)
doAssert typ[0][0][0].eqIdent"[]"
Expand Down
Loading

0 comments on commit 0fe6bbc

Please sign in to comment.